Skip to content

Commit

Permalink
Handle 0 trips rotations.
Browse files Browse the repository at this point in the history
Slim calculate_consumption
  • Loading branch information
PaulScheerRLI committed Jun 12, 2024
1 parent 5cab369 commit a38690e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions simba/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def calculate_consumption(self):
:return: Consumption of rotation [kWh]
:rtype: float
"""
if len(self.trips) == 0:
self.consumption = 0
return self.consumption

# get the specific idle consumption of this vehicle type in kWh/h
v_info = self.schedule.vehicle_types[self.vehicle_type][self.charging_type]

Expand All @@ -94,7 +98,6 @@ def calculate_consumption(self):
self.trips = list(sorted(self.trips, key=lambda trip: trip.arrival_time))

trip = self.trips[0]
next_trip = None
for next_trip in self.trips[1:]:
# get consumption due to driving
driving_consumption, driving_delta_soc = trip.calculate_consumption()
Expand All @@ -109,10 +112,9 @@ def calculate_consumption(self):
rotation_consumption += driving_consumption + idle_consumption
trip = next_trip

if next_trip:
# last trip of the rotation has no idle consumption
next_trip.consumption, next_trip.delta_soc = next_trip.calculate_consumption()
rotation_consumption += next_trip.consumption
# last trip of the rotation has no idle consumption
trip.consumption, trip.delta_soc = trip.calculate_consumption()
rotation_consumption += trip.consumption

self.consumption = rotation_consumption
return rotation_consumption
Expand Down

0 comments on commit a38690e

Please sign in to comment.