Skip to content

Commit

Permalink
Show conversions rounded to the nearest tenth decimal place
Browse files Browse the repository at this point in the history
Fixes #38
  • Loading branch information
Stormheg committed Nov 5, 2023
1 parent 5f4428e commit 71ae728
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions wagtail_ab_testing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.core.serializers.json import DjangoJSONEncoder
from django.shortcuts import get_object_or_404, redirect, render
from django.template.loader import render_to_string
from django.utils import timezone
from django.utils import formats, timezone
from django.utils.functional import cached_property
from django.utils.translation import gettext as _, gettext_lazy
from django.views.decorators.csrf import csrf_exempt
Expand Down Expand Up @@ -375,6 +375,14 @@ def get_progress_and_results_common_context(request, page, ab_test):
}
)

# Format stats for display
control_conversions_percent = formats.localize(
round(control_conversions / control_participants * 100, 1)
) if control_participants else 0
variant_conversions_percent = formats.localize(
round(variant_conversions / variant_participants * 100, 1)
) if variant_conversions else 0

return {
"page": page,
"ab_test": ab_test,
Expand All @@ -384,18 +392,10 @@ def get_progress_and_results_common_context(request, page, ab_test):
),
"control_conversions": control_conversions,
"control_participants": control_participants,
"control_conversions_percent": int(
control_conversions / control_participants * 100
)
if control_participants
else 0,
"control_conversions_percent": control_conversions_percent,
"variant_conversions": variant_conversions,
"variant_participants": variant_participants,
"variant_conversions_percent": int(
variant_conversions / variant_participants * 100
)
if variant_participants
else 0,
"variant_conversions_percent": variant_conversions_percent,
"control_is_winner": ab_test.winning_version == AbTest.VERSION_CONTROL,
"variant_is_winner": ab_test.winning_version == AbTest.VERSION_VARIANT,
"unclear_winner": ab_test.status
Expand Down

0 comments on commit 71ae728

Please sign in to comment.