Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tonial committed Jul 17, 2024
1 parent b775080 commit a773892
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clevercloud/crons/populate_metabase_emplois.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ if [[ "$1" == "--daily" ]]; then
django-admin populate_metabase_emplois --mode=users |& tee -a "$OUTPUT_LOG"
django-admin populate_metabase_emplois --mode=memberships |& tee -a "$OUTPUT_LOG"
django-admin populate_metabase_emplois --mode=dbt_daily |& tee -a "$OUTPUT_LOG"
django-admin populate_metabase_emplois --mode=gps_groups |& tee -a "$OUTPUT_LOG"
django-admin populate_metabase_emplois --mode=gps_membershios |& tee -a "$OUTPUT_LOG"
django-admin populate_metabase_emplois --mode=data_inconsistencies |& tee -a "$OUTPUT_LOG"
django-admin send_slack_message ":white_check_mark: succès mise à jour de données C1 -> Metabase"
elif [[ "$1" == "--monthly" ]]; then
Expand Down
17 changes: 17 additions & 0 deletions itou/metabase/management/commands/populate_metabase_emplois.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from itou.companies.models import Company, CompanyMembership, JobDescription
from itou.eligibility.enums import AdministrativeCriteriaLevel
from itou.eligibility.models import AdministrativeCriteria, EligibilityDiagnosis
from itou.gps.models import FollowUpGroup, FollowUpGroupMembership
from itou.institutions.models import Institution, InstitutionMembership
from itou.job_applications.enums import JobApplicationState, Origin, RefusalReason, SenderKind
from itou.job_applications.models import JobApplication
Expand All @@ -51,6 +52,7 @@
evaluated_job_applications,
evaluated_siaes,
evaluation_campaigns,
gps,
insee_codes,
institutions,
job_applications,
Expand Down Expand Up @@ -113,6 +115,8 @@ def __init__(self, *args, **kwargs):
"departments": self.populate_departments,
"enums": self.populate_enums,
"dbt_daily": self.build_dbt_daily,
"gps_groups": self.populate_gps_groups,
"gps_memberships": self.populate_gps_memberships,
"data_inconsistencies": self.report_data_inconsistencies,
}

Expand Down Expand Up @@ -495,6 +499,19 @@ def populate_enums(self):
df = get_df_from_rows(rows)
store_df(df=df, table_name=table_name)

def populate_gps_groups(self):
queryset = (
FollowUpGroup.objects.all()
.select_related("beneficiary")
.only("beneficiary__department", "id", "created_at", "created_in_bulk", "updated_at")
)
populate_table(gps.GroupsTable, batch_size=100_000, querysets=[queryset])

def populate_gps_memberships(self):
queryset = FollowUpGroupMembership.objects.all()

populate_table(gps.MembershipsTable, batch_size=100_000, querysets=[queryset])

@timeit
def report_data_inconsistencies(self):
"""
Expand Down
72 changes: 72 additions & 0 deletions itou/metabase/tables/gps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from itou.analytics.models import DatumCode
from itou.metabase.tables.utils import MetabaseTable


DATUM_CHOICES = dict(DatumCode.choices)


GroupsTable = MetabaseTable(name="gps_groups_v1")
GroupsTable.add_columns(
[
{
"name": "id",
"type": "integer",
"comment": "ID du group",
"fn": lambda o: o.pk,
},
{
"name": "created_at",
"type": "timestamp with time zone", # which is UTC
"comment": "Date de création",
"fn": lambda o: o.created_at,
},
{
"name": "updated_at",
"type": "timestamp with time zone", # which is UTC
"comment": "Date de modification",
"fn": lambda o: o.updated_at,
},
{
"name": "created_in_bulk",
"type": "boolean",
"comment": "Créé automatiquement",
"fn": lambda o: o.created_in_bulk,
},
{
"name": "department",
"type": "varchar",
"comment": "Département du bénéficiaire",
"fn": lambda o: o.beneficiary.department,
},
]
)

GroupsTable = MetabaseTable(name="gps_membres_v1")
GroupsTable.add_columns(
[
{
"name": "id",
"type": "integer",
"comment": "ID de la relation",
"fn": lambda o: o.pk,
},
{
"name": "created_at",
"type": "timestamp with time zone", # which is UTC
"comment": "Date de création",
"fn": lambda o: o.created_at,
},
{
"name": "updated_at",
"type": "timestamp with time zone", # which is UTC
"comment": "Date de modification",
"fn": lambda o: o.updated_at,
},
{
"name": "created_in_bulk",
"type": "boolean",
"comment": "Créé automatiquement",
"fn": lambda o: o.created_in_bulk,
},
]
)

0 comments on commit a773892

Please sign in to comment.