diff --git a/co2calculator/calculate.py b/co2calculator/calculate.py index 89a8d40..1cebcd7 100644 --- a/co2calculator/calculate.py +++ b/co2calculator/calculate.py @@ -232,6 +232,20 @@ def calc_co2_pedelec(weekly_distance): return co2e * weekly_distance +def calc_co2_tram(weekly_distance): + """Calculate co2 emissions for commuting by pedelec + + :param weekly_distance: distance in km per week + """ + co2e = emission_factors.get( + { + "category": EmissionCategory.TRANSPORT, + "subcategory": TransportationMode.TRAM, + } + ) + return co2e * weekly_distance + + def calc_co2_electricity( consumption: float, fuel_type: ElectricityFuel = None, energy_share: float = 1 ) -> Kilogram: @@ -484,15 +498,7 @@ def calc_co2_commuting( elif transportation_mode == TransportationMode.BICYCLE: weekly_co2e = calc_co2_bicycle(weekly_distance) elif transportation_mode == TransportationMode.TRAM: - fuel_type = BusFuel.ELECTRIC # ok like that? - size = Size.AVERAGE - co2e = emission_factors.get( - EmissionCategory.TRANSPORT, - transportation_mode, - fuel_type=fuel_type, - size=size, - ) - weekly_co2e = co2e * weekly_distance + weekly_co2e = calc_co2_tram(weekly_distance) else: raise ValueError( f"Transportation mode {transportation_mode} not found in database" diff --git a/tests/functional/test_calculate.py b/tests/functional/test_calculate.py index d61d174..db80145 100644 --- a/tests/functional/test_calculate.py +++ b/tests/functional/test_calculate.py @@ -150,8 +150,8 @@ class TestCalculateCommuting: "transportation_mode,expected_emissions", [ pytest.param("car", 9.03, id="transportation_mode: 'car'"), - pytest.param("bus", 1.63, id="transportation_mode: 'bus'"), - pytest.param("train", 2.54, id="transportation_mode: 'train'"), + pytest.param("bus", 1.65, id="transportation_mode: 'bus'"), + pytest.param("train", 1.38, id="transportation_mode: 'train'"), pytest.param("bicycle", 0.38, id="transportation_mode: 'bicycle'"), pytest.param("pedelec", 0.63, id="transportation_mode: 'pedelec'"), pytest.param("motorbike", 4.77, id="transportation_mode: 'motorbike'"),