Compare commits
2 commits
09eb44b55d
...
c6d39ace60
| Author | SHA1 | Date | |
|---|---|---|---|
| c6d39ace60 | |||
| 4ee2492e5b |
2 changed files with 12 additions and 7 deletions
|
|
@ -202,13 +202,18 @@ class Trip:
|
|||
"""Countries flags for trip."""
|
||||
return "".join(c.flag for c in self.countries)
|
||||
|
||||
def total_distance(self) -> float | None:
|
||||
"""Total distance for trip."""
|
||||
return (
|
||||
sum(t["distance"] for t in self.travel)
|
||||
if all(t.get("distance") for t in self.travel)
|
||||
else None
|
||||
)
|
||||
def total_distance(self) -> float:
|
||||
"""Total distance for trip.
|
||||
|
||||
Sums distances for travel items where a distance value is present.
|
||||
Ignores legs with missing or falsy distances rather than returning None.
|
||||
"""
|
||||
total = 0.0
|
||||
for t in self.travel:
|
||||
distance = t.get("distance")
|
||||
if distance:
|
||||
total += distance
|
||||
return total
|
||||
|
||||
def total_co2_kg(self) -> float | None:
|
||||
"""Total CO₂ for trip."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue