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:
parent
33bf61712e
commit
03b90fe50a
|
@ -52,6 +52,21 @@ class KarmaKey(models.Model):
|
||||||
return rank+1
|
return rank+1
|
||||||
return None
|
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):
|
class KarmaLogEntryManager(models.Manager):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue