Fix score calculation hack

I have no idea why we do this in the database as some magic after we
call save().  I also have no idea why MySQL is seeming to think we want
type BIGINT UNSIGNED at the end of the
((2 * '+2' + '+1') - ( '-1' + 2 * '-2')) but it does.

Setting it to 2.0 or float(2) doesn't get the ORM to get this right, but
we are going to Decimal and making the 2 multiplier be of type Decimal
manages to make the ORM pull it's shit together and use something that
seems like we're okay with.

+1, -2 = 1 / 2 = -0.5 Score == True
Looks like it works.

UPDATE `symposion_reviews_proposalresult` SET `score` = CASE WHEN `symposion_reviews_proposalresult`.`vote_count` = 0 THEN '0' ELSE ((((2 * `symposion_reviews_proposalresult`.`plus_two`) + `symposion_reviews_proposalresult`.`plus_one`) - (`symposion_reviews_proposalresult`.`minus_one` + (2 * `symposion_reviews_proposalresult`.`minus_two`))) / (`symposion_reviews_proposalresult`.`vote_count` * 1)) END WHERE `symposion_reviews_proposalresult`.`id` = 1
This commit is contained in:
Sachi King 2017-08-08 15:37:33 +10:00
parent e1ce26eb62
commit 084c78e2cd

View file

@ -21,10 +21,10 @@ from symposion.schedule.models import Presentation
def score_expression():
score = (
(2 * F("plus_two") + F("plus_one")) -
(F("minus_one") + 2 * F("minus_two"))
(Decimal(2) * F("plus_two") + F("plus_one")) -
(F("minus_one") + Decimal(2) * F("minus_two"))
) / (
F("vote_count") * 1.0
F("vote_count") * Decimal(1)
)
return Case(