add a method to compute the differences between two measures.

This commit is contained in:
Fred Pauchet 2017-02-28 21:22:35 +01:00
parent 7b58db2c90
commit 513077aa25
1 changed files with 11 additions and 0 deletions

View File

@ -21,10 +21,21 @@ class Gauge(models.Model):
class DiffMeasure(object): class DiffMeasure(object):
"""Takes two measures and compute the differences between them.
Attribues:
increase (decimal): the increase between the lowest value and the highest.
timedelta (timespan): the elapsed time between the two values.
"""
def __init__(self, measure_1, measure_2): def __init__(self, measure_1, measure_2):
self.increase = abs(measure_1.diff(measure_2)) self.increase = abs(measure_1.diff(measure_2))
self.timedelta = abs(measure_1.moment - measure_2.moment) self.timedelta = abs(measure_1.moment - measure_2.moment)
def daily_average_increase(self):
"""Returns the daily average increase, based on the two initial measures.
"""
return self.increase / self.timedelta.days
def diff_from_measures(measure1, measure2): def diff_from_measures(measure1, measure2):
"""Generate the diff between the two measures. """Generate the diff between the two measures.