X-Git-Url: http://nitlanguage.org diff --git a/src/metrics/metrics_base.nit b/src/metrics/metrics_base.nit index 64770df..080ceec 100644 --- a/src/metrics/metrics_base.nit +++ b/src/metrics/metrics_base.nit @@ -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 @@ -196,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 @@ -210,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 @@ -226,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 @@ -251,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 @@ -266,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 @@ -319,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 @@ -347,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") @@ -370,7 +400,7 @@ class MetricSet line.add("n/a") end end - csv.lines.add(line) + csv.records.add(line) end return csv end