Closed smcalilly closed 2 years ago
@fgregg here's the relevant code: https://github.com/fpdcc/ccfp-asset-dashboard/blob/master/asset_dashboard/models.py#L336-L355
it looks like it's calculating the total score as expected. here is a stripped down version of that code in a python shell, using the same values of the project where we saw this bug in the demo:
>>> scores = [2, 2, 3, 4, 2, 0]
>>> weights = [0.5, 0.5, 0.3, 0.2, 0.3, 0.3]
>>> total = 0
>>> for score, weight in zip(scores, weights):
... total += score * weight
...
>>> print(total)
4.3
that 4.3
equals what is on the staging site. it would equal > 5 if you tweak the values.
what do we need to change in the calculation so the total is <= 5?
it needs to be
for score, weight in zip(scores, weights):
total += score * weight
total /= sum(weights)
@fgregg that's closer but still > 5 when i tweak the scores
>>> scores = [4, 5, 5, 4, 3, 0]
>>> weights = [0.5, 0.5, 0.3, 0.2, 0.3, 0.3]
>>> for score, weight in zip(scores, weights):
... total += score * weight
...
>>> total /= sum(weights)
>>> total
6.708454810495628
did you reset total = 0
> sum(score * weight for score, weight in zip(scores, weights)) / sum(weights)
3.666666666666666
ahhh (hahaha) no, i didn't! duh. thank you @fgregg
weighted score average should be between 0 and 5.