Formatage des montants #45
This commit is contained in:
@@ -6,6 +6,7 @@ from dash import Input, Output, State, callback, dash_table, dcc, html, register
|
|||||||
from src.figures import point_on_map
|
from src.figures import point_on_map
|
||||||
from src.utils import (
|
from src.utils import (
|
||||||
add_org_links_in_dict,
|
add_org_links_in_dict,
|
||||||
|
format_montant,
|
||||||
format_number,
|
format_number,
|
||||||
get_annuaire_data,
|
get_annuaire_data,
|
||||||
get_departement_region,
|
get_departement_region,
|
||||||
@@ -180,6 +181,7 @@ def get_acheteur_marches_data(url, acheteur_year: str) -> pl.LazyFrame:
|
|||||||
"objet",
|
"objet",
|
||||||
"dateNotification",
|
"dateNotification",
|
||||||
"titulaire_id",
|
"titulaire_id",
|
||||||
|
"titulaire_typeIdentifiant",
|
||||||
"titulaire_nom",
|
"titulaire_nom",
|
||||||
"montant",
|
"montant",
|
||||||
"codeCPV",
|
"codeCPV",
|
||||||
@@ -210,6 +212,9 @@ def get_last_marches_table(data) -> html.Div:
|
|||||||
"dureeMois",
|
"dureeMois",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
dff = pl.DataFrame(data)
|
||||||
|
dff = format_montant(dff)
|
||||||
|
data = dff.to_dicts()
|
||||||
data = add_org_links_in_dict(data, "titulaire")
|
data = add_org_links_in_dict(data, "titulaire")
|
||||||
|
|
||||||
table = html.Div(
|
table = html.Div(
|
||||||
@@ -231,7 +236,7 @@ def get_last_marches_table(data) -> html.Div:
|
|||||||
"hideable": False,
|
"hideable": False,
|
||||||
}
|
}
|
||||||
for i in columns
|
for i in columns
|
||||||
if i not in ["titulaire_id"]
|
if i not in ["titulaire_id", "titulaire_typeIdentifiant"]
|
||||||
],
|
],
|
||||||
page_size=10,
|
page_size=10,
|
||||||
style_cell_conditional=[
|
style_cell_conditional=[
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from src.utils import (
|
|||||||
add_org_links,
|
add_org_links,
|
||||||
add_resource_link,
|
add_resource_link,
|
||||||
filter_table_data,
|
filter_table_data,
|
||||||
|
format_montant,
|
||||||
format_number,
|
format_number,
|
||||||
lf,
|
lf,
|
||||||
meta_content,
|
meta_content,
|
||||||
@@ -184,6 +185,9 @@ def update_table(page_current, page_size, filter_query, sort_by, data_timestamp)
|
|||||||
# Ajout des liens vers les fichiers Open Data
|
# Ajout des liens vers les fichiers Open Data
|
||||||
dff = add_resource_link(dff)
|
dff = add_resource_link(dff)
|
||||||
|
|
||||||
|
# Formatage des montants
|
||||||
|
dff = format_montant(dff)
|
||||||
|
|
||||||
# Liste finale de colonnes
|
# Liste finale de colonnes
|
||||||
columns = [
|
columns = [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from dash import Input, Output, State, callback, dash_table, dcc, html, register
|
|||||||
from src.figures import point_on_map
|
from src.figures import point_on_map
|
||||||
from src.utils import (
|
from src.utils import (
|
||||||
add_org_links_in_dict,
|
add_org_links_in_dict,
|
||||||
|
format_montant,
|
||||||
format_number,
|
format_number,
|
||||||
get_annuaire_data,
|
get_annuaire_data,
|
||||||
get_departement_region,
|
get_departement_region,
|
||||||
@@ -213,7 +214,11 @@ def get_last_marches_table(data) -> html.Div:
|
|||||||
"dureeMois",
|
"dureeMois",
|
||||||
]
|
]
|
||||||
|
|
||||||
# Ajout des liens vers les acheteurs
|
dff = pl.DataFrame(data)
|
||||||
|
dff = format_montant(dff)
|
||||||
|
data = dff.to_dicts()
|
||||||
|
# Idéalement on utiliserait add_org_links(), mais le résultat attendu
|
||||||
|
# est différent de home.py (Tableau)
|
||||||
data = add_org_links_in_dict(data, "acheteur")
|
data = add_org_links_in_dict(data, "acheteur")
|
||||||
|
|
||||||
table = html.Div(
|
table = html.Div(
|
||||||
|
|||||||
@@ -119,6 +119,34 @@ def format_number(number) -> str:
|
|||||||
return number
|
return number
|
||||||
|
|
||||||
|
|
||||||
|
def format_montant(dff: pl.DataFrame) -> pl.DataFrame:
|
||||||
|
def format_function(expr, scale=None):
|
||||||
|
# https://stackoverflow.com/a/78636786
|
||||||
|
expr = expr.cast(pl.String).str.splitn(".", 2)
|
||||||
|
|
||||||
|
num = expr.struct[0]
|
||||||
|
frac = expr.struct[1]
|
||||||
|
|
||||||
|
# Ajout des espaces
|
||||||
|
num = (
|
||||||
|
num.str.reverse()
|
||||||
|
.str.replace_all(r"\d{3}", "$0 ")
|
||||||
|
.str.reverse()
|
||||||
|
.str.replace(r"^ ", "")
|
||||||
|
)
|
||||||
|
|
||||||
|
frac: pl.Expr = (
|
||||||
|
pl.when(frac.is_not_null() & ~frac.is_in(["0"]))
|
||||||
|
.then("," + frac)
|
||||||
|
.otherwise(pl.lit(""))
|
||||||
|
)
|
||||||
|
|
||||||
|
return num + frac + pl.lit(" €")
|
||||||
|
|
||||||
|
dff = dff.with_columns(pl.col("montant").pipe(format_function).alias("montant"))
|
||||||
|
return dff
|
||||||
|
|
||||||
|
|
||||||
def get_annuaire_data(siret: str) -> dict:
|
def get_annuaire_data(siret: str) -> dict:
|
||||||
url = f"https://recherche-entreprises.api.gouv.fr/search?q={siret}"
|
url = f"https://recherche-entreprises.api.gouv.fr/search?q={siret}"
|
||||||
response = get(url)
|
response = get(url)
|
||||||
|
|||||||
Reference in New Issue
Block a user