Show CO₂ for flights on trip list.
This commit is contained in:
parent
a66565a785
commit
63c7c54bfc
4 changed files with 21 additions and 3 deletions
10
web_view.py
10
web_view.py
|
|
@ -404,13 +404,17 @@ def calc_total_distance(trips: list[Trip]) -> float:
|
|||
"""Total distance for trips."""
|
||||
total = 0.0
|
||||
for item in trips:
|
||||
dist = item.total_distance()
|
||||
if dist:
|
||||
if dist := item.total_distance():
|
||||
total += dist
|
||||
|
||||
return total
|
||||
|
||||
|
||||
def calc_total_co2_kg(trips: list[Trip]) -> float:
|
||||
"""Total CO₂ for trips."""
|
||||
return sum(item.total_co2_kg() for item in trips)
|
||||
|
||||
|
||||
def sum_distances_by_transport_type(trips: list[Trip]) -> list[tuple[str, float]]:
|
||||
"""Sum distances by transport type."""
|
||||
distances_by_transport_type: defaultdict[str, float] = defaultdict(float)
|
||||
|
|
@ -443,6 +447,7 @@ def trip_past_list() -> str:
|
|||
format_list_with_ampersand=format_list_with_ampersand,
|
||||
fx_rate=agenda.fx.get_rates(app.config),
|
||||
total_distance=calc_total_distance(past),
|
||||
total_co2_kg=calc_total_co2_kg(past),
|
||||
distances_by_transport_type=sum_distances_by_transport_type(past),
|
||||
)
|
||||
|
||||
|
|
@ -475,6 +480,7 @@ def trip_future_list() -> str:
|
|||
format_list_with_ampersand=format_list_with_ampersand,
|
||||
fx_rate=agenda.fx.get_rates(app.config),
|
||||
total_distance=calc_total_distance(current + future),
|
||||
total_co2_kg=calc_total_co2_kg(current + future),
|
||||
distances_by_transport_type=sum_distances_by_transport_type(current + future),
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue