Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add aggregators that ignore 0 values

  • Loading branch information...
commit 8f5698fe5ee592d1590ed00a77eff6a86f134a7b 1 parent 59212cd
@schmichael authored
Showing with 7 additions and 0 deletions.
  1. +7 −0 mmstats/mmash.py
View
7 mmstats/mmash.py
@@ -62,12 +62,19 @@ def graph():
numeric_stats=sorted(numeric_stats, key=lambda x: x['label']))
+def _nonzero_avg(values):
+ """Return the average of ``values`` ignoring 0 values"""
+ nonzero_values = [v for v in values if v]
+ return float(sum(nonzero_values)) / len(nonzero_values)
+
aggregators = {
'avg': lambda v: float(sum(v)) / len(v),
'one': operator.itemgetter(0),
'max': max,
'min': min,
'sum': sum,
+ 'nonzero-min': lambda vals: min([v for v in vals if v]),
+ 'nonzero-avg': _nonzero_avg,
}
Please sign in to comment.
Something went wrong with that request. Please try again.