From 993a298794ffa06e01e90872aeae409c8b2b9765 Mon Sep 17 00:00:00 2001 From: Sean Cassidy Date: Sat, 4 May 2013 23:50:10 -0700 Subject: [PATCH] Minimum and maximum data points --- README.md | 2 ++ livestats.py | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index 514b4aa..7721cd0 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,8 @@ When constructing a LiveStats object, pass in an array of the quantiles you wish Easy. +There are plenty of other methods too, such as minimum, maximum, [kurtosis](http://en.wikipedia.org/wiki/Kurtosis), and [skewness](http://en.wikipedia.org/wiki/Skewness). + # FAQ ## How does this work? diff --git a/livestats.py b/livestats.py index 25bf59d..e751e67 100644 --- a/livestats.py +++ b/livestats.py @@ -94,6 +94,8 @@ class LiveStats: p -- A list of quantiles to track, by default, [0.5] """ + self.min_val = float('inf') + self.max_val = float('-inf') self.var_m2 = 0.0 self.kurt_m4 = 0.0 self.skew_m3 = 0.0 @@ -108,6 +110,9 @@ class LiveStats: """ Adds another datum """ delta = item - self.average + self.min_val = min(self.min_val, item) + self.max_val = max(self.max_val, item) + # Average self.average = (self.count * self.average + item) / (self.count + 1) self.count = self.count + 1 @@ -130,10 +135,18 @@ class LiveStats: """ Returns a list of tuples of the quantile and its location """ return [(key, val.quantile()) for key, val in self.tiles.items()] + def maximum(self): + """ Returns the maximum value given """ + return self.max_val + def mean(self): """ Returns the cumulative moving average of the data """ return self.average + def minimum(self): + """ Returns the minimum value given """ + return self.min_val + def num(self): """ Returns the number of items added so far""" return self.count -- 2.1.1