Merge branch 'feature/55_top10' into dev
This commit is contained in:
@@ -38,8 +38,9 @@ Ne pas oublier de mettre à jour les fichier .env.
|
|||||||
|
|
||||||
## Notes de version
|
## Notes de version
|
||||||
|
|
||||||
### 2.2.0 ()
|
#### 2.2.0 ()
|
||||||
|
|
||||||
|
- Top acheteurs / titulaires par montant attribué/remporté (([#55](https://github.com/ColinMaudry/decp.info/issues/55)))
|
||||||
- Moins de colonnes affichées par défaut ([#54](https://github.com/ColinMaudry/decp.info/issues/54))
|
- Moins de colonnes affichées par défaut ([#54](https://github.com/ColinMaudry/decp.info/issues/54))
|
||||||
|
|
||||||
##### 2.1.6 (15 octobre 2025)
|
##### 2.1.6 (15 octobre 2025)
|
||||||
|
|||||||
@@ -53,9 +53,10 @@ div.logo > a {
|
|||||||
|
|
||||||
/* Réduire la taille du texte de la colonne Objet */
|
/* Réduire la taille du texte de la colonne Objet */
|
||||||
|
|
||||||
td[data-dash-column="objet"] {
|
/*
|
||||||
|
td[data-dash-column="objet"],td[data-dash-column="titulaire_nom"],td[data-dash-column="acheteur_nom"], {
|
||||||
font-size: 85%;
|
font-size: 85%;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/* Couleur des en-têtes */
|
/* Couleur des en-têtes */
|
||||||
.dash-table-container
|
.dash-table-container
|
||||||
@@ -211,6 +212,11 @@ summary > h3 {
|
|||||||
grid-row: 2;
|
grid-row: 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.org_top {
|
||||||
|
grid-column: 1/3;
|
||||||
|
grid-row: 3;
|
||||||
|
}
|
||||||
|
|
||||||
/* Vue marché */
|
/* Vue marché */
|
||||||
|
|
||||||
.marche_infos p {
|
.marche_infos p {
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
import polars as pl
|
||||||
|
from dash import dash_table, html
|
||||||
|
|
||||||
|
from utils import add_links_in_dict, format_montant, setup_table_columns
|
||||||
|
|
||||||
|
|
||||||
|
def get_top_org_table(data, org_type: str):
|
||||||
|
dff = pl.DataFrame(data)
|
||||||
|
if dff.height == 0:
|
||||||
|
return html.Div()
|
||||||
|
|
||||||
|
dff = dff.select(["uid", f"{org_type}_id", f"{org_type}_nom", "montant"])
|
||||||
|
dff_nb = dff.group_by(f"{org_type}_id", f"{org_type}_nom").agg(
|
||||||
|
pl.len().alias("Attributions"), pl.sum("montant").alias("montant")
|
||||||
|
)
|
||||||
|
dff_nb = dff_nb.sort(by="montant", descending=True)
|
||||||
|
dff_nb = dff_nb.cast(pl.String)
|
||||||
|
dff_nb = dff_nb.fill_null("")
|
||||||
|
dff_nb = format_montant(dff_nb, column="montant")
|
||||||
|
columns, tooltip = setup_table_columns(
|
||||||
|
dff_nb, hideable=False, exclude=[f"{org_type}_id"]
|
||||||
|
)
|
||||||
|
data = dff_nb.to_dicts()
|
||||||
|
data = add_links_in_dict(data, f"{org_type}")
|
||||||
|
|
||||||
|
print(dff_nb)
|
||||||
|
|
||||||
|
return dash_table.DataTable(
|
||||||
|
data=data,
|
||||||
|
markdown_options={"html": True},
|
||||||
|
page_action="native",
|
||||||
|
page_size=10,
|
||||||
|
columns=columns,
|
||||||
|
tooltip_header=tooltip,
|
||||||
|
style_cell_conditional=[
|
||||||
|
{
|
||||||
|
"if": {"column_id": "objet"},
|
||||||
|
"minWidth": "350px",
|
||||||
|
"textAlign": "left",
|
||||||
|
"overflow": "hidden",
|
||||||
|
"lineHeight": "14px",
|
||||||
|
"whiteSpace": "normal",
|
||||||
|
"fontSize": "85%",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"if": {"column_id": "acheteur_nom"},
|
||||||
|
"minWidth": "200px",
|
||||||
|
"textAlign": "left",
|
||||||
|
"overflow": "hidden",
|
||||||
|
"lineHeight": "16px",
|
||||||
|
# "fontSize": "85%",
|
||||||
|
"whiteSpace": "normal",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"if": {"column_id": "titulaire_nom"},
|
||||||
|
"minWidth": "200px",
|
||||||
|
"textAlign": "left",
|
||||||
|
"overflow": "hidden",
|
||||||
|
"lineHeight": "16px",
|
||||||
|
"whiteSpace": "normal",
|
||||||
|
# "fontSize": "85%",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
)
|
||||||
+25
-6
@@ -3,6 +3,7 @@ import datetime
|
|||||||
import polars as pl
|
import polars as pl
|
||||||
from dash import Input, Output, State, callback, dash_table, dcc, html, register_page
|
from dash import Input, Output, State, callback, dash_table, dcc, html, register_page
|
||||||
|
|
||||||
|
from src.callbacks import get_top_org_table
|
||||||
from src.figures import point_on_map
|
from src.figures import point_on_map
|
||||||
from src.utils import (
|
from src.utils import (
|
||||||
add_links_in_dict,
|
add_links_in_dict,
|
||||||
@@ -89,6 +90,13 @@ layout = [
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
html.Div(className="org_map", id="acheteur_map"),
|
html.Div(className="org_map", id="acheteur_map"),
|
||||||
|
html.Div(
|
||||||
|
className="org_top",
|
||||||
|
children=[
|
||||||
|
html.H3("Top titulaires"),
|
||||||
|
html.Div(className="marches_table", id="top10_titulaires"),
|
||||||
|
],
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
# récupérer les données de l'acheteur sur l'api annuaire
|
# récupérer les données de l'acheteur sur l'api annuaire
|
||||||
@@ -146,22 +154,22 @@ def update_acheteur_infos(url):
|
|||||||
Input(component_id="acheteur_data", component_property="data"),
|
Input(component_id="acheteur_data", component_property="data"),
|
||||||
)
|
)
|
||||||
def update_acheteur_stats(data):
|
def update_acheteur_stats(data):
|
||||||
df = pl.DataFrame(data)
|
dff = pl.DataFrame(data)
|
||||||
if df.height == 0:
|
if dff.height == 0:
|
||||||
df = pl.DataFrame(schema=df.collect_schema())
|
dff = pl.DataFrame(schema=df.collect_schema())
|
||||||
df_marches = df.unique("id")
|
df_marches = dff.unique("id")
|
||||||
nb_marches = format_number(df_marches.height)
|
nb_marches = format_number(df_marches.height)
|
||||||
# somme_marches = format_number(int(df_marches.select(pl.sum("montant")).item()))
|
# somme_marches = format_number(int(df_marches.select(pl.sum("montant")).item()))
|
||||||
marches_attribues = [html.Strong(nb_marches), " marchés et accord-cadres attribués"]
|
marches_attribues = [html.Strong(nb_marches), " marchés et accord-cadres attribués"]
|
||||||
# + ", pour un total de ", html.Strong(somme_marches + " €")]
|
# + ", pour un total de ", html.Strong(somme_marches + " €")]
|
||||||
del df_marches
|
del df_marches
|
||||||
|
|
||||||
nb_titulaires = df.unique("titulaire_id").height
|
nb_titulaires = dff.unique("titulaire_id").height
|
||||||
nb_titulaires = [
|
nb_titulaires = [
|
||||||
html.Strong(format_number(nb_titulaires)),
|
html.Strong(format_number(nb_titulaires)),
|
||||||
" titulaires (SIRET) différents",
|
" titulaires (SIRET) différents",
|
||||||
]
|
]
|
||||||
del df
|
del dff
|
||||||
|
|
||||||
return marches_attribues, nb_titulaires
|
return marches_attribues, nb_titulaires
|
||||||
|
|
||||||
@@ -203,8 +211,11 @@ def get_acheteur_marches_data(url, acheteur_year: str) -> list[dict]:
|
|||||||
)
|
)
|
||||||
def get_last_marches_table(data) -> html.Div:
|
def get_last_marches_table(data) -> html.Div:
|
||||||
dff = pl.DataFrame(data)
|
dff = pl.DataFrame(data)
|
||||||
|
if dff.height == 0:
|
||||||
|
return html.Div(html.P("Aucun marché trouvé."))
|
||||||
dff = dff.cast(pl.String)
|
dff = dff.cast(pl.String)
|
||||||
dff = dff.fill_null("")
|
dff = dff.fill_null("")
|
||||||
|
print("1", dff.columns)
|
||||||
dff = format_montant(dff)
|
dff = format_montant(dff)
|
||||||
columns, tooltip = setup_table_columns(
|
columns, tooltip = setup_table_columns(
|
||||||
dff,
|
dff,
|
||||||
@@ -252,6 +263,14 @@ def get_last_marches_table(data) -> html.Div:
|
|||||||
return table
|
return table
|
||||||
|
|
||||||
|
|
||||||
|
@callback(
|
||||||
|
Output(component_id="top10_titulaires", component_property="children"),
|
||||||
|
Input(component_id="acheteur_data", component_property="data"),
|
||||||
|
)
|
||||||
|
def get_top_titulaires(data):
|
||||||
|
return get_top_org_table(data, "titulaire")
|
||||||
|
|
||||||
|
|
||||||
@callback(
|
@callback(
|
||||||
Output("download-acheteur-data", "data"),
|
Output("download-acheteur-data", "data"),
|
||||||
Input("btn-download-acheteur-data", "n_clicks"),
|
Input("btn-download-acheteur-data", "n_clicks"),
|
||||||
|
|||||||
+17
-1
@@ -3,6 +3,7 @@ import datetime
|
|||||||
import polars as pl
|
import polars as pl
|
||||||
from dash import Input, Output, State, callback, dash_table, dcc, html, register_page
|
from dash import Input, Output, State, callback, dash_table, dcc, html, register_page
|
||||||
|
|
||||||
|
from src.callbacks import get_top_org_table
|
||||||
from src.figures import point_on_map
|
from src.figures import point_on_map
|
||||||
from src.utils import (
|
from src.utils import (
|
||||||
add_links_in_dict,
|
add_links_in_dict,
|
||||||
@@ -91,6 +92,13 @@ layout = [
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
html.Div(className="org_map", id="titulaire_map"),
|
html.Div(className="org_map", id="titulaire_map"),
|
||||||
|
html.Div(
|
||||||
|
className="org_top",
|
||||||
|
children=[
|
||||||
|
html.H3("Top acheteurs"),
|
||||||
|
html.Div(className="marches_table", id="top10_acheteurs"),
|
||||||
|
],
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
# récupérer les données de l'acheteur sur l'api annuaire
|
# récupérer les données de l'acheteur sur l'api annuaire
|
||||||
@@ -161,7 +169,7 @@ def update_titulaire_stats(data):
|
|||||||
nb_acheteurs = dff.unique("acheteur_id").height
|
nb_acheteurs = dff.unique("acheteur_id").height
|
||||||
nb_acheteurs = [
|
nb_acheteurs = [
|
||||||
html.Strong(format_number(nb_acheteurs)),
|
html.Strong(format_number(nb_acheteurs)),
|
||||||
" titulaires (SIRET) différents",
|
" acheteurs (SIRET) différents",
|
||||||
]
|
]
|
||||||
del dff
|
del dff
|
||||||
|
|
||||||
@@ -266,6 +274,14 @@ def get_last_marches_table(data) -> html.Div:
|
|||||||
return table
|
return table
|
||||||
|
|
||||||
|
|
||||||
|
@callback(
|
||||||
|
Output(component_id="top10_acheteurs", component_property="children"),
|
||||||
|
Input(component_id="titulaire_data", component_property="data"),
|
||||||
|
)
|
||||||
|
def get_top_acheteurs(data):
|
||||||
|
return get_top_org_table(data, "acheteur")
|
||||||
|
|
||||||
|
|
||||||
@callback(
|
@callback(
|
||||||
Output("download-titulaire-data", "data"),
|
Output("download-titulaire-data", "data"),
|
||||||
Input("btn-download-titulaire-data", "n_clicks"),
|
Input("btn-download-titulaire-data", "n_clicks"),
|
||||||
|
|||||||
+8
-6
@@ -77,15 +77,16 @@ def add_links(dff: pl.DataFrame):
|
|||||||
return dff
|
return dff
|
||||||
|
|
||||||
|
|
||||||
def add_links_in_dict(data: list, org_type: str) -> list:
|
def add_links_in_dict(data: list[dict], org_type: str) -> list:
|
||||||
new_data = []
|
new_data = []
|
||||||
for marche in data:
|
for marche in data:
|
||||||
org_id = marche[org_type + "_id"]
|
org_id = marche[org_type + "_id"]
|
||||||
marche[org_type + "_nom"] = (
|
marche[org_type + "_nom"] = (
|
||||||
f'<a href="/{org_type}s/{org_id}">{marche[org_type + "_nom"]}</a>'
|
f'<a href="/{org_type}s/{org_id}">{marche[org_type + "_nom"]}</a>'
|
||||||
)
|
)
|
||||||
marche["id"] = f'<a href="/marches/{marche["uid"]}">{marche["id"]}</a>'
|
if marche.get("uid"):
|
||||||
marche["uid"] = f'<a href="/marches/{marche["uid"]}">{marche["uid"]}</a>'
|
marche["id"] = f'<a href="/marches/{marche["uid"]}">{marche["id"]}</a>'
|
||||||
|
marche["uid"] = f'<a href="/marches/{marche["uid"]}">{marche["uid"]}</a>'
|
||||||
new_data.append(marche)
|
new_data.append(marche)
|
||||||
return new_data
|
return new_data
|
||||||
|
|
||||||
@@ -124,7 +125,7 @@ def format_number(number) -> str:
|
|||||||
return number
|
return number
|
||||||
|
|
||||||
|
|
||||||
def format_montant(dff: pl.DataFrame) -> pl.DataFrame:
|
def format_montant(dff: pl.DataFrame, column: str = "montant") -> pl.DataFrame:
|
||||||
def format_function(expr, scale=None):
|
def format_function(expr, scale=None):
|
||||||
# https://stackoverflow.com/a/78636786
|
# https://stackoverflow.com/a/78636786
|
||||||
expr = expr.cast(pl.String)
|
expr = expr.cast(pl.String)
|
||||||
@@ -143,7 +144,7 @@ def format_montant(dff: pl.DataFrame) -> pl.DataFrame:
|
|||||||
|
|
||||||
frac: pl.Expr = (
|
frac: pl.Expr = (
|
||||||
pl.when(frac.is_not_null() & ~frac.is_in(["0"]))
|
pl.when(frac.is_not_null() & ~frac.is_in(["0"]))
|
||||||
.then("," + frac)
|
.then("," + frac.str.head(2))
|
||||||
.otherwise(pl.lit(""))
|
.otherwise(pl.lit(""))
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -155,7 +156,8 @@ def format_montant(dff: pl.DataFrame) -> pl.DataFrame:
|
|||||||
|
|
||||||
return montant
|
return montant
|
||||||
|
|
||||||
dff = dff.with_columns(pl.col("montant").pipe(format_function).alias("montant"))
|
print("3", dff.columns)
|
||||||
|
dff = dff.with_columns(pl.col(column).pipe(format_function).alias(column))
|
||||||
return dff
|
return dff
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user