From 03b90fe50af30f8e7493af975dd05b28df980815 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Wed, 30 Mar 2016 17:06:12 -0500 Subject: [PATCH] add KarmaKey.history() calculates the value of the score at every point in the score's history. might be slow, unsure yet --- dr_botzo/karma/models.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/dr_botzo/karma/models.py b/dr_botzo/karma/models.py index 5349e53..12b1d67 100644 --- a/dr_botzo/karma/models.py +++ b/dr_botzo/karma/models.py @@ -52,6 +52,21 @@ class KarmaKey(models.Model): return rank+1 return None + def history(self): + """Determine the score for this karma entry at every delta.""" + + history = [] + + entries = KarmaLogEntry.objects.filter(key=self).order_by('created') + for entry in entries: + timestamp = entry.created + delta = entry.delta + score = KarmaLogEntry.objects.filter(key=self).filter(created__lte=entry.created).aggregate(models.Sum('delta'))['delta__sum'] + + history.append((timestamp, delta, score)) + + return history + class KarmaLogEntryManager(models.Manager):