def compute_km_for_entry(journey_profile_id: str | None, journeys: dict) -> dict[str, int]: if not journey_profile_id: return {} profile = journeys.get(journey_profile_id, {}) return dict(profile.get("distances", {})) def compute_co2_grams(km_by_vehicle: dict[str, int], vehicles: dict) -> float: total = 0.0 for vehicle_id, km in km_by_vehicle.items(): vehicle = vehicles.get(vehicle_id, {}) co2 = vehicle.get("co2_per_km", 0) total += km * co2 return total def compute_frais_reels(total_km_voiture: float, tranches: list[dict]) -> float: if not tranches or total_km_voiture <= 0: return 0.0 for tranche in tranches: km_max = tranche["km_max"] if km_max == 0 or total_km_voiture <= km_max: return total_km_voiture * tranche["taux"] + tranche.get("forfait", 0) last = tranches[-1] return total_km_voiture * last["taux"] + last.get("forfait", 0)