Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Sep 21, 2023
1 parent 106a056 commit 479b126
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
6 changes: 6 additions & 0 deletions lacommunaute/forum_stats/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ class Meta:

def __str__(self):
return f"{self.name} - {self.date} - {self.period}"

def get_month_stats(self):
qs = Stat.objects.filter(date__year=self.date.year, date__month=self.date.month, period=Period.MONTH).values(
"name", "value"
)
return {stat["name"]: stat["value"] for stat in qs}
17 changes: 17 additions & 0 deletions lacommunaute/pages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from lacommunaute.forum_conversation.models import Topic
from lacommunaute.forum_stats.models import Stat
from lacommunaute.utils.json import extract_values_in_list
from lacommunaute.utils.math import percent


logger = logging.getLogger(__name__)
Expand All @@ -25,6 +26,21 @@ def contact(request):
class StatistiquesPageView(TemplateView):
template_name = "pages/statistiques.html"

def get_funnel_data(self):
current_period = Stat.objects.filter(period="month").order_by("-date").first()
current_stats = Stat.get_month_stats(current_period)
current_stats["nb_uniq_visitors"] = current_stats.get("nb_uniq_visitors", 0)
current_stats["nb_uniq_active_visitors"] = current_stats.get("nb_uniq_active_visitors", 0)
current_stats["nb_uniq_engaged_visitors"] = current_stats.get("nb_uniq_engaged_visitors", 0)
current_stats["activation_percent"] = percent(
current_stats["nb_uniq_active_visitors"], current_stats["nb_uniq_visitors"]
)
current_stats["engagement_percent"] = percent(
current_stats["nb_uniq_engaged_visitors"], current_stats["nb_uniq_visitors"]
)
current_stats["period"] = current_period.date.strftime("%B %Y")
return current_stats

def get_context_data(self, **kwargs):
indicator_names = [
"nb_uniq_engaged_visitors",
Expand All @@ -40,6 +56,7 @@ def get_context_data(self, **kwargs):

context = super().get_context_data(**kwargs)
context["stats"] = extract_values_in_list(datas, indicator_names)
context = {**context, **self.get_funnel_data()}

return context

Expand Down
14 changes: 7 additions & 7 deletions lacommunaute/templates/pages/statistiques.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ <h2>Acquisition</h2>
<div class="row">
<div class="col funnel-container">
<img src="{% static 'images/funnel.png' %}" alt="Entonnoir d'aquisition des utilisateurs">
<span class="number-overlay number-overlay-top">3192</span>
<span class="number-overlay number-overlay-top target">-16%/mois précédent</span>
<span class="number-overlay number-overlay-middle">3067</span>
<span class="number-overlay number-overlay-middle target">96% des Utilisateurs<br>+1,4%/mois précédent</span>
<span class="number-overlay number-overlay-bottom">1539</span>
<span class="number-overlay number-overlay-bottom target text-center">50.2% des Util. Actifs<br>+3%/mois préc.</span>
<span class="number-overlay number-overlay-top">{{ nb_uniq_visitors }}</span>
<span class="number-overlay number-overlay-top target">-XXX%/mois précédent</span>
<span class="number-overlay number-overlay-middle">{{ nb_uniq_active_visitors }}</span>
<span class="number-overlay number-overlay-middle target">{{ activation_percent }}% des Utilisateurs<br>XXX%/mois précédent</span>
<span class="number-overlay number-overlay-bottom">{{nb_uniq_engaged_visitors }}</span>
<span class="number-overlay number-overlay-bottom target text-center">{{ engagement_percent }}% des Util. Actifs<br>+XXX%/mois préc.</span>
</div>
<div class="col ">
<span class="text-overlay text-overlay-top">
Expand All @@ -48,7 +48,7 @@ <h3 class="mb-1">Utilisateurs</h3>visiteurs uniques ayant au moins accédé à l
</div>
<div class="card-footer">
<small class="text-muted">
Période : Août 2023
Période : {{ period }}
</small>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions lacommunaute/utils/math.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def percent(a, b):
if b == 0:
return 0
return round((a / b) * 100, 2)

0 comments on commit 479b126

Please sign in to comment.