add KarmaKey.history()

calculates the value of the score at every point in the score's history.
might be slow, unsure yet
This commit is contained in:
Brian S. Stephan 2016-03-30 17:06:12 -05:00
parent 33bf61712e
commit 03b90fe50a
1 changed files with 15 additions and 0 deletions

View File

@ -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):