Merge: doc: fixed some typos and other misc. corrections
[nit.git] / src / metrics / metrics_base.nit
index a7ded94..959041b 100644 (file)
@@ -18,7 +18,6 @@
 # Helpers for various statistics tools.
 module metrics_base
 
-import model_utils
 import modelbuilder
 import csv
 import counter
@@ -51,8 +50,10 @@ redef class ToolContext
        var opt_tables = new OptionBool("Compute tables metrics", "--tables")
        # --rta
        var opt_rta = new OptionBool("Compute RTA metrics", "--rta")
+       # --readme
+       var opt_readme = new OptionBool("Compute ReadMe metrics", "--readme")
        # --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
@@ -80,6 +81,7 @@ redef class ToolContext
                self.option_context.add_option(opt_static_types)
                self.option_context.add_option(opt_tables)
                self.option_context.add_option(opt_rta)
+               self.option_context.add_option(opt_readme)
                self.option_context.add_option(opt_csv)
                self.option_context.add_option(opt_generate_hyperdoc)
                self.option_context.add_option(opt_poset)
@@ -140,20 +142,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
@@ -181,7 +169,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]
@@ -250,7 +238,7 @@ end
 class IntMetric
        super Metric
 
-       redef type VAL: Int
+       redef type VAL: Int is fixed
        redef type RES: Counter[ELM]
 
        # `IntMetric` uses a Counter to store values in intern.
@@ -314,7 +302,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
 
@@ -352,6 +343,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
@@ -406,8 +398,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")