src: Updated uses of CSV library
[nit.git] / src / metrics / metrics_base.nit
index d49f96b..a2fb201 100644 (file)
@@ -51,7 +51,7 @@ redef class ToolContext
        # --rta
        var opt_rta = new OptionBool("Compute RTA metrics", "--rta")
        # --generate-csv
-       var opt_csv = new OptionBool("Export metrics in CSV format", "--csv")
+       var opt_csv = new OptionBool("Also export metrics in CSV format", "--csv")
        # --generate_hyperdoc
        var opt_generate_hyperdoc = new OptionBool("Generate Hyperdoc", "--generate_hyperdoc")
        # --poset
@@ -139,20 +139,6 @@ redef class ToolContext
 
 end
 
-redef class MClass
-       # is the class imported from standard lib?
-       fun is_standard: Bool do
-               return self.intro_mmodule.mgroup.mproject.name == "standard"
-       end
-end
-
-redef class MModule
-       # is the module imported from standard lib?
-       fun is_standard: Bool do
-               return self.mgroup.mproject.name == "standard"
-       end
-end
-
 # A Metric is used to collect data about things
 #
 # The concept is reified here for a better organization and documentation
@@ -180,7 +166,7 @@ interface Metric
        fun values: RES is abstract
 
        # Collect metric values on elements
-       fun collect(elements: Set[ELM]) is abstract
+       fun collect(elements: Collection[ELM]) is abstract
 
        # The value calculated for the element
        fun [](element: ELM): VAL do return values[element]
@@ -313,7 +299,10 @@ class FloatMetric
 
        redef fun sum do
                var sum = 0.0
-               for v in values.values do sum += v
+               for v in values.values do
+                       if v.is_nan then continue
+                       sum += v
+               end
                return sum
        end
 
@@ -351,6 +340,7 @@ class FloatMetric
        redef fun std_dev do
                var sum = 0.0
                for value in values.values do
+                       if value.is_nan then continue
                        sum += (value - avg).pow(2.to_f)
                end
                return (sum / values.length.to_f).sqrt
@@ -405,8 +395,7 @@ class MetricSet
        # Export the metric set in CSV format
        fun to_csv: CsvDocument do
                var csv = new CsvDocument
-
-               csv.format = new CsvFormat('"', ';', "\n")
+               csv.separator = ';'
 
                # set csv headers
                csv.header.add("entry")