Skip to content

Commit

Permalink
setup scheduled management command to collect weekly stats on documen…
Browse files Browse the repository at this point in the history
…tation forums
  • Loading branch information
vincentporte committed Jun 24, 2024
1 parent 34bd9e5 commit ab0a921
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
18 changes: 18 additions & 0 deletions clevercloud/collect_weekly_matomo_forum_stats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash -l

# Collect Daily Matomo Stats

#
# About clever cloud cronjobs:
# https://www.clever-cloud.com/doc/tools/crons/
#

if [[ "$INSTANCE_NUMBER" != "0" ]]; then
echo "Instance number is ${INSTANCE_NUMBER}. Stop here."
exit 0
fi

# $APP_HOME is set by default by clever cloud.
cd $APP_HOME

python manage.py collect_matomo_forum_stats
1 change: 1 addition & 0 deletions clevercloud/cron.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"0 5 * * * $ROOT/clevercloud/collect_daily_matomo_stats.sh",
"3 5 * * * $ROOT/clevercloud/collect_daily_dsp_stats.sh",
"5 5 1 * * $ROOT/clevercloud/collect_monthly_matomo_stats.sh",
"8 5 * * 1 $ROOT/clevercloud/collect_weekly_matomo_forum_stats.sh",
"5 7-21 * * * $ROOT/clevercloud/send_notifs_when_first_reply.sh",
"5 6 * * * $ROOT/clevercloud/send_notifs_when_following_replies.sh",
"10 6-22 * * * $ROOT/clevercloud/add_user_to_list_when_register.sh",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from datetime import date

from dateutil.relativedelta import relativedelta
from django.core.management.base import BaseCommand

from lacommunaute.stats.models import ForumStat
from lacommunaute.utils.date import get_last_sunday
from lacommunaute.utils.matomo import collect_forum_stats_from_matomo_api


class Command(BaseCommand):
help = "Collecter les stats des forum dans matomo, jusqu'au dimanche précédent l'execution"

def handle(self, *args, **options):
period = "week"

from_date = ForumStat.objects.filter(period=period).order_by("-date").first()

if from_date:
from_date = from_date.date + relativedelta(days=7)
else:
from_date = date(2023, 10, 2)

to_date = get_last_sunday(date.today())

collect_forum_stats_from_matomo_api(from_date=from_date, to_date=to_date, period=period)

self.stdout.write(self.style.SUCCESS("That's all, folks!"))

0 comments on commit ab0a921

Please sign in to comment.