Carte résumé => figures.py #65
This commit is contained in:
+38
-2
@@ -1,10 +1,10 @@
|
|||||||
from typing import Literal
|
from typing import Literal
|
||||||
from urllib.error import HTTPError, URLError
|
from urllib.error import HTTPError, URLError
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
import dash_bootstrap_components as dbc
|
import dash_bootstrap_components as dbc
|
||||||
import dash_leaflet as dl
|
import dash_leaflet as dl
|
||||||
import dash_leaflet.express as dlx
|
import dash_leaflet.express as dlx
|
||||||
|
import numpy as np
|
||||||
import plotly.express as px
|
import plotly.express as px
|
||||||
import plotly.graph_objects as go
|
import plotly.graph_objects as go
|
||||||
import polars as pl
|
import polars as pl
|
||||||
@@ -597,7 +597,7 @@ def get_distance_histogram(lff: pl.LazyFrame) -> dcc.Graph:
|
|||||||
counts, bin_edges = np.histogram(log_distances, bins=50)
|
counts, bin_edges = np.histogram(log_distances, bins=50)
|
||||||
bin_centers = (bin_edges[:-1] + bin_edges[1:]) / 2
|
bin_centers = (bin_edges[:-1] + bin_edges[1:]) / 2
|
||||||
bin_widths = bin_edges[1:] - bin_edges[:-1]
|
bin_widths = bin_edges[1:] - bin_edges[:-1]
|
||||||
bin_edges_km = 10.0 ** bin_edges
|
bin_edges_km = 10.0**bin_edges
|
||||||
|
|
||||||
def fmt_km(km):
|
def fmt_km(km):
|
||||||
if km < 10:
|
if km < 10:
|
||||||
@@ -636,6 +636,42 @@ def get_distance_histogram(lff: pl.LazyFrame) -> dcc.Graph:
|
|||||||
return dcc.Graph(figure=fig)
|
return dcc.Graph(figure=fig)
|
||||||
|
|
||||||
|
|
||||||
|
def get_dashboard_summary_table(dff, dff_per_uid, nb_marches):
|
||||||
|
nb_acheteurs = dff.select("acheteur_id").n_unique()
|
||||||
|
nb_titulaires = dff.select("titulaire_id", "titulaire_typeIdentifiant").n_unique()
|
||||||
|
total_montant = int(dff_per_uid.select(pl.col("montant").sum()).item())
|
||||||
|
|
||||||
|
summary_table = [
|
||||||
|
html.P(["Nombre de marchés : ", html.Strong(str(format_number(nb_marches)))]),
|
||||||
|
html.P(
|
||||||
|
[
|
||||||
|
"Nombre d'acheteurs uniques : ",
|
||||||
|
html.Strong(str(format_number(nb_acheteurs))),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
html.P(
|
||||||
|
[
|
||||||
|
"Nombre de titulaires uniques : ",
|
||||||
|
html.Strong(str(format_number(nb_titulaires))),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
html.P(
|
||||||
|
[
|
||||||
|
"Montant total (",
|
||||||
|
html.Span(
|
||||||
|
"?",
|
||||||
|
id={"type": "modal-trigger", "index": "montant"},
|
||||||
|
style={"cursor": "pointer", "textDecoration": "underline dotted"},
|
||||||
|
),
|
||||||
|
") : ",
|
||||||
|
html.Strong(format_number(total_montant) + " €"),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
return summary_table
|
||||||
|
|
||||||
|
|
||||||
def make_card(
|
def make_card(
|
||||||
title: str, subtitle=None, fig=None, paragraphs=None, lg=6, xl=4
|
title: str, subtitle=None, fig=None, paragraphs=None, lg=6, xl=4
|
||||||
) -> dbc.Col:
|
) -> dbc.Col:
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ from dash import (
|
|||||||
|
|
||||||
from src.figures import (
|
from src.figures import (
|
||||||
get_barchart_sources,
|
get_barchart_sources,
|
||||||
|
get_dashboard_summary_table,
|
||||||
get_distance_histogram,
|
get_distance_histogram,
|
||||||
get_duplicate_matrix,
|
get_duplicate_matrix,
|
||||||
get_geographic_maps,
|
get_geographic_maps,
|
||||||
@@ -30,7 +31,6 @@ from src.utils import (
|
|||||||
df,
|
df,
|
||||||
df_acheteurs,
|
df_acheteurs,
|
||||||
df_titulaires,
|
df_titulaires,
|
||||||
format_number,
|
|
||||||
get_enum_values_as_dict,
|
get_enum_values_as_dict,
|
||||||
meta_content,
|
meta_content,
|
||||||
prepare_dashboard_data,
|
prepare_dashboard_data,
|
||||||
@@ -532,16 +532,9 @@ def udpate_dashboard_cards(
|
|||||||
|
|
||||||
# Génération des métriques
|
# Génération des métriques
|
||||||
dff = lff.collect(engine="streaming")
|
dff = lff.collect(engine="streaming")
|
||||||
|
|
||||||
# À transformer en fonction
|
|
||||||
nb_acheteurs = dff.select("acheteur_id").n_unique()
|
|
||||||
nb_titulaires = dff.select("titulaire_id", "titulaire_typeIdentifiant").n_unique()
|
|
||||||
|
|
||||||
df_per_uid = (
|
df_per_uid = (
|
||||||
dff.select("uid", "montant").group_by("uid").agg(pl.col("montant").first())
|
dff.select("uid", "montant").group_by("uid").agg(pl.col("montant").first())
|
||||||
)
|
)
|
||||||
|
|
||||||
total_montant = int(df_per_uid.select(pl.col("montant").sum()).item())
|
|
||||||
nb_marches = df_per_uid.height
|
nb_marches = df_per_uid.height
|
||||||
|
|
||||||
if nb_marches == 0:
|
if nb_marches == 0:
|
||||||
@@ -553,29 +546,9 @@ def udpate_dashboard_cards(
|
|||||||
|
|
||||||
cards = []
|
cards = []
|
||||||
|
|
||||||
card_basic_counts = [
|
card_summary_table = get_dashboard_summary_table(dff, df_per_uid, nb_marches)
|
||||||
html.P(["Nombre de marchés : ", html.Strong(str(format_number(nb_marches)))]),
|
|
||||||
html.P(
|
|
||||||
["Nombre d'acheteurs : ", html.Strong(str(format_number(nb_acheteurs)))]
|
|
||||||
),
|
|
||||||
html.P(
|
|
||||||
["Nombre de titulaires : ", html.Strong(str(format_number(nb_titulaires)))]
|
|
||||||
),
|
|
||||||
html.P(
|
|
||||||
[
|
|
||||||
"Montant total (",
|
|
||||||
html.Span(
|
|
||||||
"?",
|
|
||||||
id={"type": "modal-trigger", "index": "montant"},
|
|
||||||
style={"cursor": "pointer", "textDecoration": "underline dotted"},
|
|
||||||
),
|
|
||||||
") : ",
|
|
||||||
html.Strong(format_number(total_montant) + " €"),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
||||||
cards.append(make_card(title="Résumé", paragraphs=card_basic_counts))
|
cards.append(make_card(title="Résumé", paragraphs=card_summary_table))
|
||||||
|
|
||||||
donut_acheteur_categorie, nb_acheteur_categories = make_donut(
|
donut_acheteur_categorie, nb_acheteur_categories = make_donut(
|
||||||
lff,
|
lff,
|
||||||
|
|||||||
Reference in New Issue
Block a user