Skip to content

Commit

Permalink
suppression type_action inutiles
Browse files Browse the repository at this point in the history
  • Loading branch information
kolok committed Jan 16, 2025
1 parent 7427dc5 commit b4cbe5f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 47 deletions.
2 changes: 0 additions & 2 deletions dags/sources/config/shared_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@

# SuggestionCohorte actions
SUGGESTION_CLUSTERING = "CLUSTERING"
SUGGESTION_SOURCE = "SOURCE"
SUGGESTION_SOURCE_AJOUT = "SOURCE_AJOUT"
SUGGESTION_SOURCE_MISESAJOUR = "SOURCE_MISESAJOUR"
SUGGESTION_SOURCE_SUPRESSION = "SOURCE_SUPRESSION"
SUGGESTION_ENRICHISSEMENT = "ENRICHISSEMENT"

# Public accueilli
PUBLIC_PAR = "Particuliers"
Expand Down
26 changes: 12 additions & 14 deletions dags/suggestions/tasks/business_logic/db_normalize_suggestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,26 @@ def db_normalize_suggestion():
df_sql["type_action"] == constants.SUGGESTION_SOURCE_AJOUT
]
df_acteur_to_update = df_sql[
df_sql["type_action"] == constants.SUGGESTION_SOURCE_AJOUT
df_sql["type_action"] == constants.SUGGESTION_SOURCE_MISESAJOUR
]
df_acteur_to_delete = df_sql[
df_sql["type_action"] == constants.SUGGESTION_SOURCE_SUPRESSION
]
if not df_acteur_to_create.empty:
normalized_dfs = df_acteur_to_create["suggestion"].apply(pd.json_normalize)
df_acteur = pd.concat(normalized_dfs.tolist(), ignore_index=True)
return normalize_acteur_update_for_db(df_acteur, suggestion_cohorte_id, engine)
return normalize_acteur_update_for_db(
df_acteur, suggestion_cohorte_id, engine, constants.SUGGESTION_SOURCE_AJOUT
)
if not df_acteur_to_update.empty:
normalized_dfs = df_acteur_to_update["suggestion"].apply(pd.json_normalize)
df_acteur = pd.concat(normalized_dfs.tolist(), ignore_index=True)
return normalize_acteur_update_for_db(df_acteur, suggestion_cohorte_id, engine)
return normalize_acteur_update_for_db(
df_acteur,
suggestion_cohorte_id,
engine,
constants.SUGGESTION_SOURCE_MISESAJOUR,
)
if not df_acteur_to_delete.empty:
normalized_dfs = df_acteur_to_delete["suggestion"].apply(pd.json_normalize)
df_acteur = pd.concat(normalized_dfs.tolist(), ignore_index=True)
Expand All @@ -51,7 +58,7 @@ def db_normalize_suggestion():
raise ValueError("No suggestion found")


def normalize_acteur_update_for_db(df_actors, dag_run_id, engine):
def normalize_acteur_update_for_db(df_actors, dag_run_id, engine, type_action):
df_labels = process_many2many_df(df_actors, "labels")
df_acteur_services = process_many2many_df(
df_actors, "acteur_services", df_columns=["acteur_id", "acteurservice_id"]
Expand Down Expand Up @@ -85,7 +92,7 @@ def normalize_acteur_update_for_db(df_actors, dag_run_id, engine):
"dag_run_id": dag_run_id,
"labels": df_labels[["acteur_id", "labelqualite_id"]],
"acteur_services": df_acteur_services[["acteur_id", "acteurservice_id"]],
"change_type": constants.SUGGESTION_SOURCE,
"change_type": type_action,
}


Expand All @@ -102,12 +109,3 @@ def process_many2many_df(df, column_name, df_columns=["acteur_id", "labelqualite
except KeyError:
# Handle the case where the specified column does not exist
return pd.DataFrame(columns=df_columns)


def normalize_acteur_delete_for_db(df_actors, dag_run_id):

return {
"actors": df_actors,
"dag_run_id": dag_run_id,
"change_type": constants.SUGGESTION_SOURCE_SUPRESSION,
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def db_write_validsuggestions(data_from_db: dict):

with engine.begin() as connection:
if change_type in [
constants.SUGGESTION_SOURCE,
constants.SUGGESTION_SOURCE_AJOUT,
constants.SUGGESTION_SOURCE_MISESAJOUR,
]:
Expand Down
23 changes: 0 additions & 23 deletions data/migrations/0002_tables_suggestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class Migration(migrations.Migration):
blank=True,
choices=[
("CLUSTERING", "regroupement/déduplication des acteurs"),
("SOURCE", "ingestion de source de données"),
(
"SOURCE_AJOUT",
"ingestion de source de données - nouveau acteur",
Expand All @@ -50,7 +49,6 @@ class Migration(migrations.Migration):
"ingestion de source de données - modification d'acteur existant",
),
("SOURCE_SUPRESSION", "ingestion de source de données"),
("ENRICHISSEMENT", "suggestion d'enrichissement"),
],
max_length=250,
),
Expand Down Expand Up @@ -99,27 +97,6 @@ class Migration(migrations.Migration):
name="SuggestionUnitaire",
fields=[
("id", models.AutoField(primary_key=True, serialize=False)),
(
"type_action",
models.CharField(
blank=True,
choices=[
("CLUSTERING", "regroupement/déduplication des acteurs"),
("SOURCE", "ingestion de source de données"),
(
"SOURCE_AJOUT",
"ingestion de source de données - nouveau acteur",
),
(
"SOURCE_MISESAJOUR",
"ingestion de source de données - modification d'acteur existant",
),
("SOURCE_SUPRESSION", "ingestion de source de données"),
("ENRICHISSEMENT", "suggestion d'enrichissement"),
],
max_length=250,
),
),
(
"statut",
models.CharField(
Expand Down
7 changes: 0 additions & 7 deletions data/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
SUGGESTION_AVALIDER,
SUGGESTION_CLUSTERING,
SUGGESTION_ENCOURS,
SUGGESTION_ENRICHISSEMENT,
SUGGESTION_ERREUR,
SUGGESTION_PARTIEL,
SUGGESTION_REJETER,
SUGGESTION_SOURCE,
SUGGESTION_SOURCE_AJOUT,
SUGGESTION_SOURCE_MISESAJOUR,
SUGGESTION_SOURCE_SUPRESSION,
Expand All @@ -31,10 +29,6 @@ class SuggestionStatut(models.TextChoices):

class SuggestionAction(models.TextChoices):
CLUSTERING = SUGGESTION_CLUSTERING, "regroupement/déduplication des acteurs"
SOURCE = (
SUGGESTION_SOURCE,
"ingestion de source de données",
)
SOURCE_AJOUT = (
SUGGESTION_SOURCE_AJOUT,
"ingestion de source de données - nouveau acteur",
Expand All @@ -44,7 +38,6 @@ class SuggestionAction(models.TextChoices):
"ingestion de source de données - modification d'acteur existant",
)
SOURCE_SUPPRESSION = SUGGESTION_SOURCE_SUPRESSION, "ingestion de source de données"
SOURCE_ENRICHISSEMENT = SUGGESTION_ENRICHISSEMENT, "suggestion d'enrichissement"


class SuggestionCohorte(models.Model):
Expand Down

0 comments on commit b4cbe5f

Please sign in to comment.