Skip to content

Commit

Permalink
Track and store plausible stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashesh3 committed Sep 6, 2023
1 parent 6390735 commit 85b0268
Show file tree
Hide file tree
Showing 7 changed files with 397 additions and 1 deletion.
12 changes: 12 additions & 0 deletions aws/backend.json
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,18 @@
{
"valueFrom": "/care/backend/ABDM_CLIENT_SECRET",
"name": "ABDM_CLIENT_SECRET"
},
{
"valueFrom": "/care/backend/PLAUSIBLE_HOST",
"name": "PLAUSIBLE_HOST"
},
{
"valueFrom": "/care/backend/PLAUSIBLE_SITE_ID",
"name": "PLAUSIBLE_SITE_ID"
},
{
"valueFrom": "/care/backend/PLAUSIBLE_AUTH_TOKEN",
"name": "PLAUSIBLE_AUTH_TOKEN"
}
],
"name": "care-backend"
Expand Down
24 changes: 24 additions & 0 deletions aws/celery.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@
{
"valueFrom": "/care/backend/HCX_IG_URL",
"name": "HCX_IG_URL"
},
{
"valueFrom": "/care/backend/PLAUSIBLE_HOST",
"name": "PLAUSIBLE_HOST"
},
{
"valueFrom": "/care/backend/PLAUSIBLE_SITE_ID",
"name": "PLAUSIBLE_SITE_ID"
},
{
"valueFrom": "/care/backend/PLAUSIBLE_AUTH_TOKEN",
"name": "PLAUSIBLE_AUTH_TOKEN"
}
],
"name": "care-celery-beat"
Expand Down Expand Up @@ -432,6 +444,18 @@
{
"valueFrom": "/care/backend/HCX_IG_URL",
"name": "HCX_IG_URL"
},
{
"valueFrom": "/care/backend/PLAUSIBLE_HOST",
"name": "PLAUSIBLE_HOST"
},
{
"valueFrom": "/care/backend/PLAUSIBLE_SITE_ID",
"name": "PLAUSIBLE_SITE_ID"
},
{
"valueFrom": "/care/backend/PLAUSIBLE_AUTH_TOKEN",
"name": "PLAUSIBLE_AUTH_TOKEN"
}
],
"name": "care-celery-worker"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Generated by Django 4.2.2 on 2023-09-06 08:36

import uuid

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


class Migration(migrations.Migration):
dependencies = [
("facility", "0382_assetservice_remove_asset_last_serviced_on_and_more"),
]

operations = [
migrations.CreateModel(
name="Goal",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"external_id",
models.UUIDField(db_index=True, default=uuid.uuid4, unique=True),
),
(
"created_date",
models.DateTimeField(auto_now_add=True, db_index=True, null=True),
),
(
"modified_date",
models.DateTimeField(auto_now=True, db_index=True, null=True),
),
("deleted", models.BooleanField(db_index=True, default=False)),
("name", models.CharField(max_length=200)),
],
options={
"abstract": False,
},
),
migrations.CreateModel(
name="GoalEntry",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"external_id",
models.UUIDField(db_index=True, default=uuid.uuid4, unique=True),
),
(
"created_date",
models.DateTimeField(auto_now_add=True, db_index=True, null=True),
),
(
"modified_date",
models.DateTimeField(auto_now=True, db_index=True, null=True),
),
("deleted", models.BooleanField(db_index=True, default=False)),
("date", models.DateField()),
("visitors", models.IntegerField(null=True)),
("events", models.IntegerField(null=True)),
(
"goal",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="entries",
to="facility.goal",
),
),
],
options={
"abstract": False,
},
),
migrations.CreateModel(
name="GoalProperty",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"external_id",
models.UUIDField(db_index=True, default=uuid.uuid4, unique=True),
),
(
"created_date",
models.DateTimeField(auto_now_add=True, db_index=True, null=True),
),
(
"modified_date",
models.DateTimeField(auto_now=True, db_index=True, null=True),
),
("deleted", models.BooleanField(db_index=True, default=False)),
("name", models.CharField(max_length=200)),
(
"goal",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="properties",
to="facility.goal",
),
),
],
options={
"abstract": False,
},
),
migrations.CreateModel(
name="GoalPropertyEntry",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"external_id",
models.UUIDField(db_index=True, default=uuid.uuid4, unique=True),
),
(
"created_date",
models.DateTimeField(auto_now_add=True, db_index=True, null=True),
),
(
"modified_date",
models.DateTimeField(auto_now=True, db_index=True, null=True),
),
("deleted", models.BooleanField(db_index=True, default=False)),
("value", models.CharField(max_length=200)),
("visitors", models.IntegerField(null=True)),
("events", models.IntegerField(null=True)),
(
"goal_entry",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="properties",
to="facility.goalentry",
),
),
(
"goal_property",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="entries",
to="facility.goalproperty",
),
),
],
options={
"abstract": False,
},
),
]
43 changes: 43 additions & 0 deletions care/facility/models/stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from django.db import models

from care.utils.models.base import BaseModel


class Goal(BaseModel):
name = models.CharField(max_length=200)


class GoalEntry(BaseModel):
goal = models.ForeignKey(
Goal,
on_delete=models.PROTECT,
related_name="entries",
)
date = models.DateField()
visitors = models.IntegerField(null=True)
events = models.IntegerField(null=True)


class GoalProperty(BaseModel):
name = models.CharField(max_length=200)
goal = models.ForeignKey(
Goal,
on_delete=models.CASCADE,
related_name="properties",
)


class GoalPropertyEntry(BaseModel):
goal_entry = models.ForeignKey(
GoalEntry,
on_delete=models.PROTECT,
related_name="properties",
)
goal_property = models.ForeignKey(
GoalProperty,
on_delete=models.PROTECT,
related_name="entries",
)
value = models.CharField(max_length=200)
visitors = models.IntegerField(null=True)
events = models.IntegerField(null=True)
9 changes: 8 additions & 1 deletion care/facility/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from care.facility.tasks.asset_monitor import check_asset_status
from care.facility.tasks.cleanup import delete_old_notifications
from care.facility.tasks.plausible_stats import capture_goals
from care.facility.tasks.summarisation import (
summarise_district_patient,
summarise_facility_capacity,
Expand All @@ -14,8 +15,9 @@

@current_app.on_after_finalize.connect
def setup_periodic_tasks(sender, **kwargs):
capture_goals.apply_async()
sender.add_periodic_task(
crontab(minute="0", hour="0"),
crontab(hour="0", minute="0"),
delete_old_notifications.s(),
name="delete_old_notifications",
)
Expand Down Expand Up @@ -49,3 +51,8 @@ def setup_periodic_tasks(sender, **kwargs):
check_asset_status.s(),
name="check_asset_status",
)
sender.add_periodic_task(
crontab(hour="0", minute="0"),
capture_goals.s(),
name="capture_goals",
)
Loading

0 comments on commit 85b0268

Please sign in to comment.