Skip to content

Commit

Permalink
Fix formula and add average fuel consumption to trips model (#327)
Browse files Browse the repository at this point in the history
* Fix formula and add average fuel consumption to trips model
  • Loading branch information
CM000n committed Feb 13, 2024
1 parent c0507c3 commit 4eb285c
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions mytoyota/models/trips.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,39 @@ def ev_distance(self) -> Optional[float]:

@property
def fuel_consumed(self) -> float:
"""The amount of fuel consumed.
"""The total amount of fuel consumed.
Returns
-------
float: The fuel consumed in liters if metric or gallons
float: The total amount of fuel consumed in liters if metric or gallons
"""
if self._trip.summary.fuel_consumption:
return (
round(self._trip.summary.fuel_consumption / 4546.0, 3)
round(self._trip.summary.fuel_consumption / 1000.0, 3)
if self._metric
else (self._trip.summary.fuel_consumption / 1000.0)
else round(self._trip.summary.fuel_consumption / 3785.0, 3)
)

return 0.0

@property
def average_fuel_consumed(self) -> float:
"""The average amount of fuel consumed.
Returns
-------
float: The average amount of fuel consumed in l/100km if metric or mpg
"""
if self._trip.summary.fuel_consumption:
avg_fuel_consumed = (
self._trip.summary.fuel_consumption / self._trip.summary.length
) * 100
return (
round(avg_fuel_consumed, 3)
if self._metric
else round(235.215 * avg_fuel_consumed, 3)
)

return 0.0
Expand Down

0 comments on commit 4eb285c

Please sign in to comment.