metrics: remove useless return types in redefs
[nit.git] / src / metrics / metrics_base.nit
index 056aba4..ba4856e 100644 (file)
@@ -19,6 +19,7 @@
 module metrics_base
 
 import model_utils
+import modelbuilder
 import csv
 import counter
 import console
@@ -86,7 +87,7 @@ redef class ToolContext
                self.option_context.add_option(opt_nocolors)
        end
 
-       redef fun process_options
+       redef fun process_options(args)
        do
                super
                var val = self.opt_dir.value
@@ -170,6 +171,15 @@ interface Metric
 
        # Pretty print the metric results in console
        fun to_console(indent: Int, colors: Bool) do
+               if values.is_empty then
+                       if colors then
+                               print "{"\t" * indent}{name}: {desc} -- nothing".green
+                       else
+                               print "{"\t" * indent}{name}: {desc} -- nothing"
+                       end
+                       return
+               end
+
                var max = self.max
                var min = self.min
                if colors then
@@ -187,6 +197,9 @@ interface Metric
                end
        end
 
+       # The sum of all the values.
+       fun sum: VAL is abstract
+
        # The values standard derivation
        fun std_dev: Float is abstract
 
@@ -201,6 +214,11 @@ interface Metric
 
        # The set of element above the threshold
        fun above_threshold: Set[ELM] is abstract
+
+       # Sort the metric keys by values
+       fun sort: Array[ELM] do
+               return values.keys_sorted_by_values(default_reverse_comparator)
+       end
 end
 
 # A Metric that collects integer data
@@ -217,7 +235,7 @@ class IntMetric
 
        redef fun clear do values_cache.clear
 
-       fun sum: Int do return values_cache.sum
+       redef fun sum do return values_cache.sum
 
        redef fun max do
                assert not values_cache.is_empty
@@ -230,9 +248,9 @@ class IntMetric
        end
 
        # Values average
-       redef fun avg: Float do return values_cache.avg
+       redef fun avg do return values_cache.avg
 
-       redef fun std_dev: Float do return values_cache.std_dev
+       redef fun std_dev do return values_cache.std_dev
 
        redef fun above_threshold do
                var above = new HashSet[ELM]
@@ -242,6 +260,15 @@ class IntMetric
                end
                return above
        end
+
+       redef fun to_console(indent, colors) do
+               super
+               if colors then
+                       print "{"\t" * indent}  sum: {sum}".light_gray
+               else
+                       print "{"\t" * indent}  sum: {sum}"
+               end
+       end
 end
 
 # A Metric that collects float datas
@@ -257,7 +284,8 @@ class FloatMetric
 
        redef fun clear do values_cache.clear
 
-       fun sum: Float do
+
+       redef fun sum do
                var sum = 0.0
                for v in values.values do sum += v
                return sum
@@ -294,7 +322,7 @@ class FloatMetric
                return sum / values.length.to_f
        end
 
-       redef fun std_dev: Float do
+       redef fun std_dev do
                var sum = 0.0
                for value in values.values do
                        sum += (value - avg).pow(2.to_f)
@@ -310,6 +338,15 @@ class FloatMetric
                end
                return above
        end
+
+       redef fun to_console(indent, colors) do
+               super
+               if colors then
+                       print "{"\t" * indent}  sum: {sum}".light_gray
+               else
+                       print "{"\t" * indent}  sum: {sum}"
+               end
+       end
 end
 
 # A MetricSet is a metric holder
@@ -338,8 +375,10 @@ class MetricSet
        end
 
        # Export the metric set in CSV format
-       fun to_csv: CSVDocument do
-               var csv = new CSVDocument
+       fun to_csv: CsvDocument do
+               var csv = new CsvDocument
+
+               csv.format = new CsvFormat('"', ';', "\n")
 
                # set csv headers
                csv.header.add("entry")
@@ -361,7 +400,7 @@ class MetricSet
                                        line.add("n/a")
                                end
                        end
-                       csv.lines.add(line)
+                       csv.records.add(line)
                end
                return csv
        end