Removes div-by-zero error if the first vote is an abstention
This commit is contained in:
parent
47a6f212f2
commit
6e133970d9
1 changed files with 7 additions and 1 deletions
|
@ -5,6 +5,7 @@ from decimal import Decimal
|
|||
|
||||
from django.db import models
|
||||
from django.db.models import Q, F
|
||||
from django.db.models import Case, When, Value
|
||||
from django.db.models.signals import post_save
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
|
@ -16,13 +17,18 @@ from symposion.schedule.models import Presentation
|
|||
|
||||
|
||||
def score_expression():
|
||||
return (
|
||||
score = (
|
||||
(2 * F("plus_two") + F("plus_one")) -
|
||||
(F("minus_one") + 2 * F("minus_two"))
|
||||
) / (
|
||||
F("vote_count") - F("abstain") * 1.0
|
||||
)
|
||||
|
||||
return Case(
|
||||
When(vote_count=F("abstain"), then=Value("0")), # no divide by zero
|
||||
default=score,
|
||||
)
|
||||
|
||||
|
||||
class Votes(object):
|
||||
ABSTAIN = "0"
|
||||
|
|
Loading…
Reference in a new issue