Skip to content

Commit

Permalink
Handle 100 average creepiness (#11538)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonatan-lopes authored Jan 11, 2024
1 parent 220561e commit c59c02d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,11 @@ def average_bin(self):

average_vote = self.average_creepiness
mode_bin = int(average_vote // self.BIN_SIZE)
if mode_bin == 5:
# Handle case where average is 100 (which should be in bin 4)
# Votes should go until 99 to avoid this, but they are allowed to go up to 100
# due to legacy implementation :facepalm:
mode_bin = 4
label = self.BIN_LABELS[f"bin_{mode_bin}"]

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ def test_avg_bin_with_avg_vote_between_60_and_80(self):
self.assertEqual(evaluation.average_creepiness, vote_value)
self.assertDictEqual(evaluation.average_bin, {"label": "Very creepy", "localized": gettext("Very creepy")})

def test_avg_bin_with_avg_vote_between_80_and_100(self):
vote_value = self.fake.random_int(min=80, max=100)
def test_avg_bin_with_avg_vote_between_80_and_99(self):
vote_value = self.fake.random_int(min=80, max=99)
buyersguide_factories.ProductVoteFactory(evaluation=self.product_page.evaluation, value=vote_value)
evaluation = (
ProductPageEvaluation.objects.with_total_votes()
Expand All @@ -300,6 +300,18 @@ def test_avg_bin_with_avg_vote_between_80_and_100(self):
self.assertEqual(evaluation.average_creepiness, vote_value)
self.assertDictEqual(evaluation.average_bin, {"label": "Super creepy", "localized": gettext("Super creepy")})

def test_avg_bin_with_avg_vote_equal_100(self):
buyersguide_factories.ProductVoteFactory(evaluation=self.product_page.evaluation, value=100)
evaluation = (
ProductPageEvaluation.objects.with_total_votes()
.with_total_creepiness()
.with_average_creepiness()
.get(pk=self.product_page.evaluation.pk)
)

self.assertEqual(evaluation.average_creepiness, 100)
self.assertDictEqual(evaluation.average_bin, {"label": "Super creepy", "localized": gettext("Super creepy")})


class TestProductPageEvaluationPrefetching(BuyersGuideTestCase):
def setUp(self):
Expand Down

0 comments on commit c59c02d

Please sign in to comment.