Modification de map_count_marches (plus efficace, utilise le dép de l'acheteur)

This commit is contained in:
Colin Maudry
2026-03-13 23:59:54 +01:00
parent c7d1a5ec73
commit d9f97cf8b3
+10 -10
View File
@@ -11,20 +11,20 @@ from dash import dash_table, dcc, html
from src.utils import data_schema, df, format_number from src.utils import data_schema, df, format_number
def get_map_count_marches(): def get_map_count_marches(dff: pl.DataFrame) -> go.Figure:
lf = df.lazy() lff: pl.LazyFrame = dff.lazy()
lf = lf.with_columns( lff = lff.rename({"acheteur_departement_code": "Département"})
pl.col("lieuExecution_code").str.head(2).str.zfill(2).alias("Département")
) lff = (
lf = ( lff.select(["uid", "Département"])
lf.select(["uid", "Département"])
.drop_nulls() .drop_nulls()
.unique(subset="uid") .group_by("uid")
.agg(pl.col("Département").first())
.group_by("Département") .group_by("Département")
.len("uid") .len("uid")
) )
# Suppression des infos pour les DOM/TOM pour l'instant # Suppression des infos pour les DOM/TOM pour l'instant
lf = lf.remove(pl.col("Département").is_in(["97", "98"])) lff = lff.filter(~pl.col("Département").str.head(2).is_in(["97", "98"]))
with open("./data/departements-1000m.geojson") as f: with open("./data/departements-1000m.geojson") as f:
departements = json.load(f) departements = json.load(f)
@@ -33,7 +33,7 @@ def get_map_count_marches():
for f in departements["features"]: for f in departements["features"]:
f["id"] = f["properties"]["code"] f["id"] = f["properties"]["code"]
df_map = lf.collect(engine="streaming") df_map = lff.collect(engine="streaming")
fig = px.choropleth( fig = px.choropleth(
df_map, df_map,