Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PNI] Handle 100 average creepiness #11538

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
jhonatan-lopes marked this conversation as resolved.
Show resolved Hide resolved
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