import streamlit as st import pandas as pd dict_comparaison_1kgCO2 = { "eau en litre":[374/100,"https://impactco2.fr/icons/eauenbouteille.svg"], "smartphones": [1.16/100,"https://impactco2.fr/icons/smartphone.svg"], "voiture en km": [460/100,"https://impactco2.fr/icons/voiturethermique.svg"], "tgv en km":[34130/100,"https://impactco2.fr/icons/tgv.svg"], } def compare(value_init, ratio_equivalent): return ratio_equivalent * value_init if ratio_equivalent else None def display_comparaison(container,value_init, ratio_equivalent,icon, unit): #value_init must be in kgCO2 link_url = f"https://impactco2.fr/outils/comparateur?value={value_init}&comparisons=tgv,eauenbouteille,voiturethermique" container.markdown(f"
{unit}
", unsafe_allow_html=True) container.markdown(f"
{compare(value_init, ratio_equivalent):.2f} {unit}
", unsafe_allow_html=True) def custom_cumsum(ecologits_series, codecarbon_series): cumsum = 0 result = [] for eco, code in zip(ecologits_series, codecarbon_series): if code == 0: result.append(0) else: cumsum += eco result.append(cumsum) return pd.Series(result, index=ecologits_series.index) def get_table_empreintes_detailed() -> pd.DataFrame: emissions_data = st.session_state["partial_emissions"] emissions_df = pd.DataFrame(emissions_data).T # Transpose to match the desired format # Rename columns and index values emissions_df = emissions_df.rename(columns={"cc": "CodeCarbon (Cumulative)", "el": "EcoLogits (par requete)"}) emissions_df = emissions_df.applymap(lambda x: x * 1000) emissions_df = emissions_df.round(2) emissions_df = emissions_df.rename(index={ "Scrapping": "Collecte de documents et scrapping", "extraction_pp": "Extraction des parties prenantes (serveur et IA)", "cartographie": "Sauvegarde de la cartographie", "chatbot": "Dialogue avec chatBot IA", "download_rapport": "Téléchargement cartographie" }) # Make Ecologits column cumulative emissions_df["EcoLogits (Cumulative)"] = custom_cumsum(emissions_df["EcoLogits (par requete)"], emissions_df["CodeCarbon (Cumulative)"]) emissions_df['Consommation Totale'] = emissions_df["CodeCarbon (Cumulative)"] + emissions_df["EcoLogits (Cumulative)"] emissions_df = emissions_df.round(2) return emissions_df