From: Alexandre Terrasa Date: Thu, 15 Oct 2015 21:41:50 +0000 (-0400) Subject: metrics: skip `not a number` values when computinh the sum and std_dev X-Git-Tag: v0.7.9~33^2~1 X-Git-Url: http://nitlanguage.org metrics: skip `not a number` values when computinh the sum and std_dev Signed-off-by: Alexandre Terrasa --- diff --git a/src/metrics/metrics_base.nit b/src/metrics/metrics_base.nit index 605f4d3..ebd05ae 100644 --- a/src/metrics/metrics_base.nit +++ b/src/metrics/metrics_base.nit @@ -299,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 @@ -337,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