From 71ae728c9742c196ce8e4dd15318ac739024c010 Mon Sep 17 00:00:00 2001 From: "Storm B. Heg" Date: Sun, 5 Nov 2023 17:38:50 +0100 Subject: [PATCH] Show conversions rounded to the nearest tenth decimal place Fixes https://github.com/wagtail-nest/wagtail-ab-testing/issues/38 --- wagtail_ab_testing/views.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/wagtail_ab_testing/views.py b/wagtail_ab_testing/views.py index d45f771..833a97e 100644 --- a/wagtail_ab_testing/views.py +++ b/wagtail_ab_testing/views.py @@ -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 @@ -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, @@ -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