Skip to content

Commit

Permalink
make score computation at the python level
Browse files Browse the repository at this point in the history
  • Loading branch information
pdebuyl committed Mar 23, 2015
1 parent 0956e85 commit 112123b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions symposion/reviews/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,24 +231,24 @@ def full_calculate(cls):
result, created = cls._default_manager.get_or_create(proposal=proposal)
result.comment_count = Review.objects.filter(proposal=proposal).count()
result.vote_count = LatestVote.objects.filter(proposal=proposal).count()
result.plus_one = LatestVote.objects.filter(
plus_one = result.plus_one = LatestVote.objects.filter(
proposal=proposal,
vote=VOTES.PLUS_ONE
).count()
result.plus_zero = LatestVote.objects.filter(
plus_zero = result.plus_zero = LatestVote.objects.filter(
proposal=proposal,
vote=VOTES.PLUS_ZERO
).count()
result.minus_zero = LatestVote.objects.filter(
minus_zero = result.minus_zero = LatestVote.objects.filter(
proposal=proposal,
vote=VOTES.MINUS_ZERO
).count()
result.minus_one = LatestVote.objects.filter(
minus_one = result.minus_one = LatestVote.objects.filter(
proposal=proposal,
vote=VOTES.MINUS_ONE
).count()
result.save()
cls._default_manager.filter(pk=result.pk).update(score=ProposalScoreExpression())
cls._default_manager.filter(pk=result.pk).update(score=((3 * plus_one + plus_zero) - (minus_zero + 3 * minus_one)))

def update_vote(self, vote, previous=None, removal=False):
mapping = {
Expand Down Expand Up @@ -277,7 +277,7 @@ def update_vote(self, vote, previous=None, removal=False):
self.comment_count = models.F("comment_count") + 1
self.save()
model = self.__class__
model._default_manager.filter(pk=self.pk).update(score=ProposalScoreExpression())
model._default_manager.filter(pk=self.pk).update(score=((3 * self.plus_one + self.plus_zero) - (self.minus_zero + 3 * self.minus_one)))


class Comment(models.Model):
Expand Down

0 comments on commit 112123b

Please sign in to comment.