Sean Cassidy avatar Sean Cassidy committed 6ba0af3

Add docstrings

Comments (0)

Files changed (1)

 class Percentile:
     LEN = 5
     def __init__(self, p):
+        """ Constructs a single Percentile object """
         self.dn = [0, p/2, p, (1 + p)/2, 1]
         self.npos = [1, 1 + 2*p, 1 + 4*p, 3 + 2*p, 5]
         self.pos = range(1, self.LEN + 1)
         self.initialized = False
 
     def add(self, item):
+        """ Adds another datum """
         if len(self.heights) != 5:
             self.heights.append(item)
         else:
 
 class LiveStats:
     def __init__(self, p = [0.5]):
+        """ Constructs a LiveStream object
+
+        Keyword arguments:
+
+        p -- A list of percentiles to track, by default, [0.5]
+
+        """
         self.var_m2 = 0.0
         self.kurt_m4 = 0.0
         self.skew_m3 = 0.0
             self.tiles[i] = Percentile(i)
 
     def add(self, item):
+        """ Adds another datum """
         delta = item - self.average
 
         # Average
 
 
     def percentiles(self):
-        # We have enough data to generate the tiles
-        return [x.percentile() for x in self.tiles.values()]
+        """ Returns a list of tuples of the percentile and its location """
+        return [(key, val.percentile()) for key, val in self.tiles.iteritems()]
 
     def mean(self):
+        """ Returns the cumulative moving average of the data """
         return self.average
 
     def num(self):
+        """ Returns the number of items added so far"""
         return self.count
 
     def variance(self):
+        """ Returns the sample variance of the data given so far"""
         return self.var_m2 / (self.count - 1)
 
     def kurtosis(self):
+        """ Returns the sample kurtosis of the data given so far"""
         return self.kurt_m4 / (self.count * self.variance()**2.0) - 3.0
 
     def skewness(self):
+        """ Returns the sample skewness of the data given so far"""
         return self.skew_m3 / (self.count * self.variance()**1.5)
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.