metrics: add Counter#print_summary
authorJean Privat <jean@pryen.org>
Tue, 23 Jul 2013 15:33:30 +0000 (11:33 -0400)
committerJean Privat <jean@pryen.org>
Tue, 23 Jul 2013 15:58:43 +0000 (11:58 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/counter.nit
src/metrics/static_types_metrics.nit
tests/sav/nitmetrics_args1.res
tests/sav/nitmetrics_args1.sav

index 14b418d..a9621fe 100644 (file)
@@ -60,6 +60,36 @@ class Counter[E: Object]
                #res.sort !cmp a, b = map[a] <=> map[b]
                return res
        end
+
+       # Display statistical information
+       fun print_summary
+       do
+               var list = self.sort
+               print " population: {list.length}"
+               if list.is_empty then return
+               print " minimum value: {self[list.first]}"
+               print " maximum value: {self[list.last]}"
+               print " total value: {self.total}"
+               print " average value: {div(self.total,list.length)}"
+               print " distribution:"
+               var count = 0
+               var sum = 0
+               var limit = self[list.first]
+               for t in list do
+                       if self[t] > limit then
+                               print "  <={limit}: sub-population={count} ({div(count*100,list.length)}%); cumulated value={sum} ({div(sum*100,self.total)}%)"
+                               count = 0
+                               sum = 0
+                               while self[t] > limit do
+                                       limit = limit * 2
+                                       if limit == 0 then limit = 1
+                               end
+                       end
+                       count += 1
+                       sum += self[t]
+               end
+               print "  <={limit}: sub-population={count} ({div(count*100,list.length)}%); cumulated value={sum} ({div(sum*100,self.total)}%)"
+       end
 end
 
 private class CounterSorter[E: Object]
index 3f28cee..5c77c0e 100644 (file)
@@ -94,20 +94,7 @@ do
                print "  {t}: {typecount[t]}"
        end
 
-       # Compute the distribution of type usage
-       print "Distribution of type usage:"
-       var count = 0
-       var sum = 0
-       var limit = 1
-       for t in types do
-               if typecount[t] > limit then
-                       print "  <={limit}: {count} ({div(count*100,types.length)}% of types; {div(sum*100,typecount.total)}% of usage)"
-                       count = 0
-                       sum = 0
-                       while typecount[t] > limit do limit = limit * 2
-               end
-               count += 1
-               sum += typecount[t]
-       end
-       print "  <={limit}: {count} ({div(count*100,types.length)}% of types; {div(sum*100,typecount.total)}% of usage)"
+       # Some statistics
+       print "Statistics of type usage:"
+       typecount.print_summary
 end
index 9dc3dd0..5102893 100644 (file)
@@ -107,9 +107,15 @@ Most used types:
   C: 1
   B: 1
   A: 1
-Distribution of type usage:
-  <=1: 3 (75.00% of types; 33.33% of usage)
-  <=8: 1 (25.00% of types; 66.66% of usage)
+Statistics of type usage:
+ population: 4
+ minimum value: 1
+ maximum value: 6
+ total value: 9
+ average value: 2.25
+ distribution:
+  <=1: sub-population=3 (75.00%); cumulated value=3 (33.33%)
+  <=8: sub-population=1 (25.00%); cumulated value=6 (66.66%)
 --- Sends on Nullable Reciever ---
 Total number of sends: 19
 Number of sends on a nullable receiver: 0 (0.0%)
index 41a794a..9956c30 100644 (file)
@@ -26,9 +26,15 @@ Most used types:
   C: 1
   B: 1
   A: 1
-Distribution of type usage:
-  <=1: 3 (75.00% of types; 33.33% of usage)
-  <=8: 1 (25.00% of types; 66.66% of usage)
+Statistics of type usage:
+ population: 4
+ minimum value: 1
+ maximum value: 6
+ total value: 9
+ average value: 2.25
+ distribution:
+  <=1: sub-population=3 (75.00%); cumulated value=3 (33.33%)
+  <=8: sub-population=1 (25.00%); cumulated value=6 (66.66%)
 --- Metrics of refinement usage ---
 Number of modules: 1