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

feat(forum_stats): collecte des expressions de recherche #685

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,8 @@
"sync-xhr": [],
"usb": [],
}

# forum_stats
# ---------------------------------------

SEARCH_COLLECTION_PERIOD_DAYS = 30
12 changes: 11 additions & 1 deletion lacommunaute/forum_stats/admin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
from django.contrib import admin

from lacommunaute.forum_stats.models import Stat
from lacommunaute.forum_stats.models import SearchCollectionPeriod, SearchQuery, Stat


class StatAdmin(admin.ModelAdmin):
list_display = ("name", "date", "value", "period")
list_filter = ("name", "date", "period")


class SearchCollectionPeriodAdmin(admin.ModelAdmin):
list_display = ("name", "start_date", "end_date")


class SearchQueryAdmin(admin.ModelAdmin):
list_display = ("period", "nb_visits")


admin.site.register(Stat, StatAdmin)
admin.site.register(SearchCollectionPeriod, SearchCollectionPeriodAdmin)
admin.site.register(SearchQuery, SearchQueryAdmin)
27 changes: 26 additions & 1 deletion lacommunaute/forum_stats/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import factory
import factory.django
from django.conf import settings

from lacommunaute.forum_stats.enums import Period
from lacommunaute.forum_stats.models import Stat
from lacommunaute.forum_stats.models import SearchCollectionPeriod, SearchQuery, Stat


class StatFactory(factory.django.DjangoModelFactory):
Expand All @@ -23,3 +24,27 @@ class Params:
value=46,
period="day",
)


class SearchCollectionPeriodFactory(factory.django.DjangoModelFactory):
class Meta:
model = SearchCollectionPeriod

name = factory.Faker("word")
start_date = factory.Faker("date")

@factory.lazy_attribute
def end_date(self):
return (
datetime.datetime.strptime(self.start_date, "%Y-%m-%d")
+ datetime.timedelta(days=settings.SEARCH_COLLECTION_PERIOD_DAYS)
).date()


class SearchQueryFactory(factory.django.DjangoModelFactory):
class Meta:
model = SearchQuery

label = factory.Faker("word")
period = factory.SubFactory(SearchCollectionPeriodFactory)
nb_visits = factory.Faker("random_int", min=1, max=10)
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Generated by Django 5.0.6 on 2024-06-17 16:54

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("forum_stats", "0001_initial"),
]

operations = [
migrations.CreateModel(
name="SearchCollectionPeriod",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("name", models.CharField(max_length=256, verbose_name="Name")),
("start_date", models.DateField(help_text="The start of the period", verbose_name="Start date")),
("end_date", models.DateField(help_text="The end of the period", verbose_name="End date")),
],
options={
"verbose_name": "Search Collection Period",
"verbose_name_plural": "Search Collection Periods",
"ordering": ["-end_date", "-start_date"],
"unique_together": {("start_date", "end_date")},
},
),
migrations.CreateModel(
name="SearchQuery",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("label", models.TextField(help_text="The search query made by the user")),
("nb_visits", models.PositiveIntegerField(verbose_name="Number visits")),
(
"period",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="searches",
to="forum_stats.searchcollectionperiod",
),
),
],
options={
"verbose_name": "Search Query",
"verbose_name_plural": "Search Queries",
"ordering": ["-period", "label"],
},
),
]
37 changes: 37 additions & 0 deletions lacommunaute/forum_stats/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db import models
from django.utils.translation import gettext_lazy as _

from lacommunaute.forum_stats.enums import Period

Expand Down Expand Up @@ -31,3 +32,39 @@ def __str__(self):
return f"{self.name} - {self.date} - {self.period}"

objects = StatQuerySet().as_manager()


class SearchCollectionPeriod(models.Model):
name = models.CharField(max_length=256, verbose_name=_("Name"))
start_date = models.DateField(verbose_name=_("Start date"), help_text=_("The start of the period"))
end_date = models.DateField(verbose_name=_("End date"), help_text=_("The end of the period"))

class Meta:
verbose_name = _("Search Collection Period")
verbose_name_plural = _("Search Collection Periods")
ordering = ["-end_date", "-start_date"]
unique_together = ("start_date", "end_date")

def __str__(self):
return f"Period {str(self.name)} ({str(self.start_date)} - {str(self.end_date)})"


class SearchQuery(models.Model):
"""
Matomo logs for us the searches made by users visiting the site.
We collect searches made during a period and store them for interpretation
"""

label = models.TextField(help_text=_("The search query made by the user"))
period = models.ForeignKey(
SearchCollectionPeriod, related_name="searches", on_delete=models.CASCADE, db_index=True
)
nb_visits = models.PositiveIntegerField(verbose_name=_("Number visits"))

class Meta:
verbose_name = _("Search Query")
verbose_name_plural = _("Search Queries")
ordering = ["-period", "label"]

def __str__(self):
return f"Search from {str(self.period)}"
Empty file.
Binary file modified locale/fr/LC_MESSAGES/django.mo
Binary file not shown.
41 changes: 41 additions & 0 deletions locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,46 @@ msgstr "Motif du blocage"
msgid "Poster"
msgstr "Auteur"

#: lacommunaute/forum_stats/models.py
msgid "Start date"
msgstr "Date de début"

#: lacommunaute/forum_stats/models.py
msgid "The start of the period"
msgstr "Le début de la période"

#: lacommunaute/forum_stats/models.py
msgid "End date"
msgstr "Date de fin"

#: lacommunaute/forum_stats/models.py
msgid "The end of the period"
msgstr "La fin de la période"

#: lacommunaute/forum_stats/models.py
msgid "Search Collection Period"
msgstr "Recherche Période de collecte"

#: lacommunaute/forum_stats/models.py
msgid "Search Collection Periods"
msgstr "Recherche de Périodes de collecte"

#: lacommunaute/forum_stats/models.py
msgid "The search query made by the user"
msgstr "La requête de recherche effectuée par l'utilisateur"

#: lacommunaute/forum_stats/models.py
msgid "Number visits"
msgstr "Nombre de visites"

#: lacommunaute/forum_stats/models.py
msgid "Search Query"
msgstr "Recherche"

#: lacommunaute/forum_stats/models.py
msgid "Search Queries"
msgstr "Recherches"

#: lacommunaute/search/forms.py:24
msgid "Keywords or phrase"
msgstr "Mots clés ou phrase"
Expand Down Expand Up @@ -77,6 +117,7 @@ msgid "Global forum permissions"
msgstr "Autorisations globales des communautés"

#: lacommunaute/templates/admin/forum/forum/change_list_table.html:9
#: lacommunaute/forum_stats/models.py
msgid "Name"
msgstr "Nom"

Expand Down
Loading