Skip to content

Commit

Permalink
corrections proposé lors de la relecture
Browse files Browse the repository at this point in the history
  • Loading branch information
kolok committed Jan 20, 2025
1 parent f815986 commit 39716f0
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 218 deletions.
8 changes: 8 additions & 0 deletions core/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.contrib.auth.mixins import LoginRequiredMixin


class IsStaffMixin(LoginRequiredMixin):
def dispatch(self, request, *args, **kwargs):
if not request.user.is_staff:
return self.handle_no_permission()
return super().dispatch(request, *args, **kwargs)
2 changes: 1 addition & 1 deletion dags/sources/tasks/airflow_logic/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from sources.tasks.airflow_logic.db_read_propositions_max_id_task import (
db_read_propositions_max_id_task,
)
from sources.tasks.airflow_logic.db_write_suggestion_task import (
from sources.tasks.airflow_logic.db_write_type_action_suggestions_task import (
db_write_type_action_suggestions_task,
)
from sources.tasks.airflow_logic.propose_acteur_changes_task import (
Expand Down
35 changes: 20 additions & 15 deletions dags/sources/tasks/business_logic/source_data_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _transform_columns(df: pd.DataFrame, dag_config: DAGConfig) -> pd.DataFrame:
for column_to_transform in columns_to_transform:
function_name = column_to_transform.transformation
normalisation_function = get_transformation_function(function_name, dag_config)
# logger.warning(f"Transformation {function_name}")
logger.warning(f"Transformation {function_name}")
df[column_to_transform.destination] = df[column_to_transform.origin].apply(
normalisation_function
)
Expand All @@ -70,7 +70,7 @@ def _transform_df(df: pd.DataFrame, dag_config: DAGConfig) -> pd.DataFrame:
for column_to_transform_df in columns_to_transform_df:
function_name = column_to_transform_df.transformation
normalisation_function = get_transformation_function(function_name, dag_config)
# logger.warning(f"Transformation {function_name}")
logger.warning(f"Transformation {function_name}")
df[column_to_transform_df.destination] = df[
column_to_transform_df.origin
].apply(normalisation_function, axis=1)
Expand Down Expand Up @@ -141,6 +141,22 @@ def _remove_undesired_lines(df: pd.DataFrame, dag_config: DAGConfig) -> pd.DataF
return df


def _display_warning_about_missing_location(df: pd.DataFrame) -> None:
# TODO: A voir ce qu'on doit faire de ces acteurs non digitaux mais sans
# localisation (proposition : les afficher en erreur directement ?)
if "location" in df.columns and "acteur_type_code" in df.columns:
df_acteur_sans_loc = df[
(df["location"].isnull()) & (df["acteur_type_code"] != "acteur_digital")
]
if not df_acteur_sans_loc.empty:
nb_acteurs = len(df)
logger.warning(
f"Nombre d'acteur sans localisation: {len(df_acteur_sans_loc)} / "
f"{nb_acteurs}"
)
log.preview("Acteurs sans localisation", df_acteur_sans_loc)


def source_data_normalize(
df_acteur_from_source: pd.DataFrame,
dag_config: DAGConfig,
Expand Down Expand Up @@ -191,19 +207,8 @@ def source_data_normalize(
# Merge et suppression des lignes indésirables
df = _remove_undesired_lines(df, dag_config)

# TODO: A voir ce qu'on doit faire de ces acteurs non digitaux mais sans
# localisation (proposition : les afficher en erreur directement ?)
if "location" in df.columns and "acteur_type_code" in df.columns:
df_acteur_sans_loc = df[
(df["location"].isnull()) & (df["acteur_type_code"] != "acteur_digital")
]
if not df_acteur_sans_loc.empty:
nb_acteurs = len(df)
logger.warning(
f"Nombre d'acteur sans localisation: {len(df_acteur_sans_loc)} / "
f"{nb_acteurs}"
)
log.preview("Acteurs sans localisation", df_acteur_sans_loc)
# Log si des localisations sont manquantes parmis les acteurs non digitaux
_display_warning_about_missing_location(df)

log.preview("df après normalisation", df)
if df.empty:
Expand Down
1 change: 0 additions & 1 deletion dags/sources/tasks/transform/transform_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ def compute_location(row: pd.Series, _):
lng_column = row.keys()[1]
row[lat_column] = parse_float(row[lat_column])
row[lng_column] = parse_float(row[lng_column])
print(row[lat_column], row[lng_column])
row["location"] = transform_location(row[lng_column], row[lat_column])
return row[["location"]]

Expand Down
1 change: 0 additions & 1 deletion dags/utils/base_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def extract_details(row, col="adresse_format_ban"):

def transform_location(longitude, latitude):
if not longitude or not latitude or math.isnan(longitude) or math.isnan(latitude):
print("Longitude or latitude is missing.")
return None
return wkb.dumps(Point(longitude, latitude)).hex()

Expand Down
6 changes: 3 additions & 3 deletions data/admin.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from django.contrib.gis import admin

from data.models import SuggestionCohorte, SuggestionUnitaire
from data.models import Suggestion, SuggestionCohorte


class SuggestionCohorteAdmin(admin.ModelAdmin):
pass


class SuggestionUnitaireAdmin(admin.ModelAdmin):
class SuggestionAdmin(admin.ModelAdmin):
pass


admin.site.register(SuggestionCohorte, SuggestionCohorteAdmin)
admin.site.register(SuggestionUnitaire, SuggestionUnitaireAdmin)
admin.site.register(Suggestion, SuggestionAdmin)
2 changes: 2 additions & 0 deletions data/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
class DataConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "data"
label = "data"
verbose_name = "Gestion des interactions avec la plateforme de données"
6 changes: 3 additions & 3 deletions data/migrations/0001_bancache.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class Migration(migrations.Migration):
verbose_name="ID",
),
),
("adresse", models.CharField(blank=True, max_length=255, null=True)),
("adresse", models.CharField(blank=True, null=True)),
(
"code_postal",
models.CharField(blank=True, max_length=255, null=True),
models.CharField(blank=True, null=True),
),
("ville", models.CharField(blank=True, max_length=255, null=True)),
("ville", models.CharField(blank=True, null=True)),
(
"location",
django.contrib.gis.db.models.fields.PointField(
Expand Down
16 changes: 8 additions & 8 deletions data/migrations/0002_tables_suggestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ class Migration(migrations.Migration):
(
"identifiant_action",
models.CharField(
help_text="Identifiant de l'action (ex : dag_id pour Airflow)",
max_length=250,
verbose_name="Identifiant de l'action",
help_text="(ex : dag_id pour Airflow)",
),
),
(
"identifiant_execution",
models.CharField(
help_text="Identifiant de l'execution (ex : run_id pour Airflow)",
max_length=250,
verbose_name="Identifiant de l'execution",
help_text="(ex : run_id pour Airflow)",
),
),
(
Expand All @@ -50,7 +50,7 @@ class Migration(migrations.Migration):
),
("SOURCE_SUPRESSION", "ingestion de source de données"),
],
max_length=250,
max_length=50,
),
),
(
Expand Down Expand Up @@ -94,7 +94,7 @@ class Migration(migrations.Migration):
],
),
migrations.CreateModel(
name="SuggestionUnitaire",
name="Suggestion",
fields=[
("id", models.AutoField(primary_key=True, serialize=False)),
(
Expand All @@ -117,14 +117,14 @@ class Migration(migrations.Migration):
"context",
models.JSONField(
blank=True,
help_text="Contexte de la suggestion : données initiales",
verbose_name="Contexte de la suggestion : données initiales",
null=True,
),
),
(
"suggestion",
models.JSONField(
blank=True, help_text="Suggestion de modification"
blank=True, verbose_name="Suggestion de modification"
),
),
(
Expand Down
28 changes: 16 additions & 12 deletions data/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ class SuggestionCohorte(models.Model):
# On utilise identifiant car le champ n'est pas utilisé pour résoudre une relation
# en base de données
identifiant_action = models.CharField(
max_length=250, help_text="Identifiant de l'action (ex : dag_id pour Airflow)"
verbose_name="Identifiant de l'action", help_text="(ex : dag_id pour Airflow)"
)
identifiant_execution = models.CharField(
max_length=250,
help_text="Identifiant de l'execution (ex : run_id pour Airflow)",
verbose_name="Identifiant de l'execution",
help_text="(ex : run_id pour Airflow)",
)
type_action = models.CharField(
choices=SuggestionAction.choices,
max_length=250,
max_length=50,
blank=True,
)
statut = models.CharField(
Expand All @@ -62,7 +62,9 @@ class SuggestionCohorte(models.Model):
default=SuggestionStatut.AVALIDER,
)
metadata = models.JSONField(
null=True, blank=True, help_text="Metadata de la cohorte, données statistiques"
null=True,
blank=True,
verbose_name="Metadata de la cohorte, données statistiques",
)
cree_le = models.DateTimeField(auto_now_add=True, db_default=Now())
modifie_le = models.DateTimeField(auto_now=True, db_default=Now())
Expand All @@ -86,7 +88,7 @@ def __str__(self) -> str:
return f"{self.identifiant_action} - {self.identifiant_execution}"


class SuggestionUnitaire(models.Model):
class Suggestion(models.Model):
id = models.AutoField(primary_key=True)
suggestion_cohorte = models.ForeignKey(
SuggestionCohorte, on_delete=models.CASCADE, related_name="suggestion_unitaires"
Expand All @@ -97,9 +99,11 @@ class SuggestionUnitaire(models.Model):
default=SuggestionStatut.AVALIDER,
)
context = models.JSONField(
null=True, blank=True, help_text="Contexte de la suggestion : données initiales"
null=True,
blank=True,
verbose_name="Contexte de la suggestion : données initiales",
)
suggestion = models.JSONField(blank=True, help_text="Suggestion de modification")
suggestion = models.JSONField(blank=True, verbose_name="Suggestion de modification")
cree_le = models.DateTimeField(auto_now_add=True, db_default=Now())
modifie_le = models.DateTimeField(auto_now=True, db_default=Now())

Expand Down Expand Up @@ -152,11 +156,11 @@ def display_proposition_service(self):
class BANCache(models.Model):
class Meta:
verbose_name = "Cache BAN"
verbose_name_plural = "Cache BAN"
verbose_name_plural = "Caches BAN"

adresse = models.CharField(max_length=255, blank=True, null=True)
code_postal = models.CharField(max_length=255, blank=True, null=True)
ville = models.CharField(max_length=255, blank=True, null=True)
adresse = models.CharField(blank=True, null=True)
code_postal = models.CharField(blank=True, null=True)
ville = models.CharField(blank=True, null=True)
location = models.PointField(blank=True, null=True)
ban_returned = models.JSONField(blank=True, null=True)
modifie_le = models.DateTimeField(auto_now=True, db_default=Now())
6 changes: 3 additions & 3 deletions data/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from django.urls import path

from data.views import SuggestionManagment
from data.views import SuggestionManagement

urlpatterns = [
path(
"suggestions",
SuggestionManagment.as_view(),
"suggestions/",
SuggestionManagement.as_view(),
name="suggestions",
),
]
Loading

0 comments on commit 39716f0

Please sign in to comment.