Spaces:
Sleeping
Sleeping
| """Equivalences post-processor mapping kgCO2eq to concrete equivalents.""" | |
| from config import settings | |
| from ..context import RunContext | |
| class EquivalencesProcessor: | |
| name = "equivalences" | |
| def process(self, ctx: RunContext) -> None: | |
| kg = ctx.metadata_out.get("emissions_kgCO2eq") | |
| if kg is None: | |
| return | |
| ratios = getattr(settings, "equivalence_ratios", {}) | |
| try: | |
| eq = { | |
| "water_liters": round(kg * float(ratios.get("water_l_per_kgCO2eq", 0)), 4), | |
| "car_km": round(kg * float(ratios.get("car_km_per_kgCO2eq", 0)), 4), | |
| "tgv_km": round(kg * float(ratios.get("tgv_km_per_kgCO2eq", 0)), 4), | |
| "smartphone": round(kg * float(ratios.get("smartphone_per_kgCO2eq", 0)), 4), | |
| } | |
| except Exception: | |
| return | |
| ctx.metadata_out["equivalences"] = eq | |