From 513077aa25c049eaee0b614fb3cca70888d6a140 Mon Sep 17 00:00:00 2001 From: Fred Pauchet Date: Tue, 28 Feb 2017 21:22:35 +0100 Subject: [PATCH] add a method to compute the differences between two measures. --- heima/sherlock/models.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/heima/sherlock/models.py b/heima/sherlock/models.py index 0d31e3d..e19c06d 100644 --- a/heima/sherlock/models.py +++ b/heima/sherlock/models.py @@ -21,10 +21,21 @@ class Gauge(models.Model): 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): self.increase = abs(measure_1.diff(measure_2)) 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): """Generate the diff between the two measures.