Meilleure gestion des df vides acheteur/titulaire
This commit is contained in:
@@ -247,7 +247,7 @@ def get_acheteur_marches_data(url, acheteur_year: str) -> tuple:
|
|||||||
)
|
)
|
||||||
def get_last_marches_data(
|
def get_last_marches_data(
|
||||||
data, page_current, page_size, filter_query, sort_by, data_timestamp
|
data, page_current, page_size, filter_query, sort_by, data_timestamp
|
||||||
) -> list[dict]:
|
) -> tuple:
|
||||||
return prepare_table_data(
|
return prepare_table_data(
|
||||||
data, data_timestamp, filter_query, page_current, page_size, sort_by
|
data, data_timestamp, filter_query, page_current, page_size, sort_by
|
||||||
)
|
)
|
||||||
|
|||||||
+12
-9
@@ -188,22 +188,25 @@ def update_titulaire_infos(url):
|
|||||||
def update_titulaire_stats(data):
|
def update_titulaire_stats(data):
|
||||||
dff = pl.DataFrame(data)
|
dff = pl.DataFrame(data)
|
||||||
if dff.height == 0:
|
if dff.height == 0:
|
||||||
dff = pl.DataFrame(schema=dff.collect_schema())
|
nb_marches = 0
|
||||||
|
nb_acheteurs = 0
|
||||||
|
else:
|
||||||
df_marches = dff.unique("uid")
|
df_marches = dff.unique("uid")
|
||||||
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()))
|
|
||||||
marches_remportes = [html.Strong(nb_marches), " marchés et accord-cadres remportés"]
|
|
||||||
# + ", pour un total de ", html.Strong(somme_marches + " €")]
|
|
||||||
del df_marches
|
|
||||||
|
|
||||||
nb_acheteurs = dff.unique("acheteur_id").height
|
nb_acheteurs = dff.unique("acheteur_id").height
|
||||||
nb_acheteurs = [
|
|
||||||
|
texte_marches_remportes = [
|
||||||
|
html.Strong(nb_marches),
|
||||||
|
" marchés et accord-cadres remportés",
|
||||||
|
]
|
||||||
|
# + ", pour un total de ", html.Strong(somme_marches + " €")]
|
||||||
|
|
||||||
|
texte_nb_acheteurs = [
|
||||||
html.Strong(format_number(nb_acheteurs)),
|
html.Strong(format_number(nb_acheteurs)),
|
||||||
" acheteurs (SIRET) différents",
|
" acheteurs (SIRET) différents",
|
||||||
]
|
]
|
||||||
del dff
|
|
||||||
|
|
||||||
return marches_remportes, nb_acheteurs
|
return texte_marches_remportes, texte_nb_acheteurs
|
||||||
|
|
||||||
|
|
||||||
@callback(
|
@callback(
|
||||||
|
|||||||
+10
-3
@@ -333,7 +333,6 @@ def setup_table_columns(dff, hideable: bool = True, exclude: list = None) -> tup
|
|||||||
column_name = column_object.get("title")
|
column_name = column_object.get("title")
|
||||||
else:
|
else:
|
||||||
column_name = column_id
|
column_name = column_id
|
||||||
print("Colonne inconnue dans le schéma !", column_id)
|
|
||||||
|
|
||||||
column = {
|
column = {
|
||||||
"name": column_name,
|
"name": column_name,
|
||||||
@@ -551,7 +550,7 @@ def prepare_table_data(
|
|||||||
print(" + + + + + + + + + + + + + + + + + + ")
|
print(" + + + + + + + + + + + + + + + + + + ")
|
||||||
|
|
||||||
# Récupération des données
|
# Récupération des données
|
||||||
if data:
|
if isinstance(data, list):
|
||||||
lff: pl.LazyFrame = pl.LazyFrame(data)
|
lff: pl.LazyFrame = pl.LazyFrame(data)
|
||||||
else:
|
else:
|
||||||
lff: pl.LazyFrame = df.lazy() # start from the original data
|
lff: pl.LazyFrame = df.lazy() # start from the original data
|
||||||
@@ -567,7 +566,11 @@ def prepare_table_data(
|
|||||||
# Matérialisation des filtres
|
# Matérialisation des filtres
|
||||||
dff: pl.DataFrame = lff.collect()
|
dff: pl.DataFrame = lff.collect()
|
||||||
height = dff.height
|
height = dff.height
|
||||||
|
|
||||||
|
if height > 0:
|
||||||
nb_rows = f"{format_number(height)} lignes ({format_number(dff.select('uid').unique().height)} marchés)"
|
nb_rows = f"{format_number(height)} lignes ({format_number(dff.select('uid').unique().height)} marchés)"
|
||||||
|
else:
|
||||||
|
nb_rows = "0 lignes (0 marchés)"
|
||||||
|
|
||||||
# Pagination des données
|
# Pagination des données
|
||||||
start_row = page_current * page_size
|
start_row = page_current * page_size
|
||||||
@@ -588,6 +591,7 @@ def prepare_table_data(
|
|||||||
dff = add_resource_link(dff)
|
dff = add_resource_link(dff)
|
||||||
|
|
||||||
# Formatage des montants
|
# Formatage des montants
|
||||||
|
if height > 0:
|
||||||
dff = format_values(dff)
|
dff = format_values(dff)
|
||||||
|
|
||||||
# Récupération des colonnes et tooltip
|
# Récupération des colonnes et tooltip
|
||||||
@@ -615,8 +619,11 @@ def get_button_properties(height):
|
|||||||
download_disabled = True
|
download_disabled = True
|
||||||
download_text = "Téléchargement désactivé au-delà de 65 000 lignes"
|
download_text = "Téléchargement désactivé au-delà de 65 000 lignes"
|
||||||
download_title = "Excel ne supporte pas d'avoir plus de 65 000 URLs dans une même feuille de calcul. Contactez-moi pour me présenter votre besoin en téléchargement afin que je puisse adapter la solution."
|
download_title = "Excel ne supporte pas d'avoir plus de 65 000 URLs dans une même feuille de calcul. Contactez-moi pour me présenter votre besoin en téléchargement afin que je puisse adapter la solution."
|
||||||
|
elif height == 0:
|
||||||
|
download_disabled = True
|
||||||
|
download_text = "Pas de données à télécharger"
|
||||||
|
download_title = ""
|
||||||
else:
|
else:
|
||||||
print("moins de 65k")
|
|
||||||
download_disabled = False
|
download_disabled = False
|
||||||
download_text = "Télécharger au format Excel"
|
download_text = "Télécharger au format Excel"
|
||||||
download_title = ""
|
download_title = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user