Spaces:
Running
Running
File size: 2,563 Bytes
17b2024 0dc8c45 17b2024 dffe458 17b2024 91832df 17b2024 0dc8c45 b8f7efd 0dc8c45 5b07f21 a306650 0dc8c45 5b07f21 0dc8c45 bc6ee94 b8f7efd 0dc8c45 a306650 0dc8c45 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
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"<div style='text-align: center;'><a href='{link_url}' target='_blank'><img src='{icon}' alt='{unit}' width='50'></div>", unsafe_allow_html=True)
container.markdown(f"<div style='text-align: center;'><b>{compare(value_init, ratio_equivalent):.2f}</b> {unit}</div>", 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 |