Ilyas KHIAT
commited on
Commit
·
45e3f0f
1
Parent(s):
225177d
emission export
Browse files- empreinte_export.py +39 -9
empreinte_export.py
CHANGED
@@ -4,7 +4,7 @@ import altair as alt
|
|
4 |
import base64
|
5 |
import pdfkit
|
6 |
import io
|
7 |
-
from comparateur import
|
8 |
|
9 |
def load_svg_as_base64(svg_file_path):
|
10 |
with open(svg_file_path, "rb") as svg_file:
|
@@ -14,13 +14,27 @@ def save_pdf(html_content):
|
|
14 |
pdf = pdfkit.from_string(html_content, False)
|
15 |
return pdf
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
def display_cf_comparison():
|
18 |
svg_file_path = "feuille.svg"
|
19 |
svg_base64 = load_svg_as_base64(svg_file_path)
|
20 |
|
21 |
html_content = f"""
|
22 |
-
<
|
23 |
-
|
|
|
|
|
24 |
<br>
|
25 |
"""
|
26 |
|
@@ -38,15 +52,31 @@ def display_cf_comparison():
|
|
38 |
html_content += f"<p>- Empreinte IA (via EcoLogits) : <b>{emission_api*1000:.3f}</b> g eq. CO2 ({pourcentage_api:.2%})</p>"
|
39 |
|
40 |
html_content += "<h2>Votre équivalence</h2>"
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
html_content += f"""
|
47 |
<br>
|
|
|
48 |
<p>Powered by <b>ADEME</b></p>
|
49 |
<a href='https://www.ademe.fr' target='_blank'><img src='https://www.ademe.fr/wp-content/uploads/2022/11/ademe-logo-2022-1.svg' alt='svg' width='30' height='30' style='margin-left: 10px;'></a>
|
|
|
50 |
<br>
|
51 |
"""
|
52 |
|
@@ -78,7 +108,7 @@ def get_carbon_footprint_html():
|
|
78 |
styled_df = table[['Consommation Totale']].rename(columns={'Consommation Totale': 'Consommation Cumulée (g eqCo2)'})
|
79 |
styled_df = styled_df.style.applymap(color_scale, subset=['Consommation Cumulée (g eqCo2)'])
|
80 |
|
81 |
-
|
82 |
html_content += """
|
83 |
<h2>DETAIL PAR TACHE</h2>
|
84 |
"""
|
|
|
4 |
import base64
|
5 |
import pdfkit
|
6 |
import io
|
7 |
+
from comparateur import *
|
8 |
|
9 |
def load_svg_as_base64(svg_file_path):
|
10 |
with open(svg_file_path, "rb") as svg_file:
|
|
|
14 |
pdf = pdfkit.from_string(html_content, False)
|
15 |
return pdf
|
16 |
|
17 |
+
def display_comparaison_html(value_init, ratio_equivalent, icon, unit):
|
18 |
+
link_url = f"https://impactco2.fr/outils/comparateur?value={value_init}&comparisons=tgv,eauenbouteille,voiturethermique"
|
19 |
+
html = f"""
|
20 |
+
<div style='text-align: center;'>
|
21 |
+
<a href='{link_url}' target='_blank'><img src='{icon}' alt='{unit}' width='50'></a>
|
22 |
+
</div>
|
23 |
+
<div style='text-align: center;'>
|
24 |
+
<b>{compare(value_init, ratio_equivalent):.2f}</b> {unit}
|
25 |
+
</div>
|
26 |
+
"""
|
27 |
+
return html
|
28 |
+
|
29 |
def display_cf_comparison():
|
30 |
svg_file_path = "feuille.svg"
|
31 |
svg_base64 = load_svg_as_base64(svg_file_path)
|
32 |
|
33 |
html_content = f"""
|
34 |
+
<div style='display: flex; align-items: center;'>
|
35 |
+
<h2 style='margin: 0;'>Votre consommation Carbone</h2>
|
36 |
+
<img src='data:image/svg+xml;base64,{svg_base64}' alt='svg' width='15' height='15' style='margin-left: 10px;'>
|
37 |
+
</div>
|
38 |
<br>
|
39 |
"""
|
40 |
|
|
|
52 |
html_content += f"<p>- Empreinte IA (via EcoLogits) : <b>{emission_api*1000:.3f}</b> g eq. CO2 ({pourcentage_api:.2%})</p>"
|
53 |
|
54 |
html_content += "<h2>Votre équivalence</h2>"
|
55 |
+
html_content += """
|
56 |
+
<div style='display: flex; justify-content: space-around;'>
|
57 |
+
"""
|
58 |
+
|
59 |
+
html_content += f"""
|
60 |
+
<div>
|
61 |
+
{display_comparaison_html(total_emission, dict_comparaison_1kgCO2["eau en litre"][0]*1000, dict_comparaison_1kgCO2["eau en litre"][1], "ml")}
|
62 |
+
</div>
|
63 |
+
<div>
|
64 |
+
{display_comparaison_html(total_emission, dict_comparaison_1kgCO2["tgv en km"][0], dict_comparaison_1kgCO2["tgv en km"][1], "km")}
|
65 |
+
</div>
|
66 |
+
<div>
|
67 |
+
{display_comparaison_html(total_emission, dict_comparaison_1kgCO2["voiture en km"][0]*1000, dict_comparaison_1kgCO2["voiture en km"][1], "m")}
|
68 |
+
</div>
|
69 |
+
"""
|
70 |
+
|
71 |
+
html_content += "</div><br>"
|
72 |
+
|
73 |
+
|
74 |
html_content += f"""
|
75 |
<br>
|
76 |
+
<div style='display: flex; align-items: center;'>
|
77 |
<p>Powered by <b>ADEME</b></p>
|
78 |
<a href='https://www.ademe.fr' target='_blank'><img src='https://www.ademe.fr/wp-content/uploads/2022/11/ademe-logo-2022-1.svg' alt='svg' width='30' height='30' style='margin-left: 10px;'></a>
|
79 |
+
</div>
|
80 |
<br>
|
81 |
"""
|
82 |
|
|
|
108 |
styled_df = table[['Consommation Totale']].rename(columns={'Consommation Totale': 'Consommation Cumulée (g eqCo2)'})
|
109 |
styled_df = styled_df.style.applymap(color_scale, subset=['Consommation Cumulée (g eqCo2)'])
|
110 |
|
111 |
+
|
112 |
html_content += """
|
113 |
<h2>DETAIL PAR TACHE</h2>
|
114 |
"""
|