Skip to content

Commit

Permalink
test: fix tests where emission factor was changed. added function for…
Browse files Browse the repository at this point in the history
… trams
  • Loading branch information
redfrexx committed May 4, 2024
1 parent 80450a1 commit bb07633
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
24 changes: 15 additions & 9 deletions co2calculator/calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/test_calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'"),
Expand Down

0 comments on commit bb07633

Please sign in to comment.