Skip to content

Commit

Permalink
Add attribute allow_opp_charging to rotation
Browse files Browse the repository at this point in the history
Only create charge events if rotation is allowed to opp charge.Add test
  • Loading branch information
PaulScheerRLI committed Sep 23, 2024
1 parent 3531dc9 commit bd3f755
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/test_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,32 @@ def basic_run(self):


class TestSchedule(BasicSchedule):
def test_allow_opp_charging(self):
# test if the schedule properly skips charging events if the rotation is not allowed
# to opportunity charge
sched, scen, args = BasicSchedule().basic_run()
oppb_rotations = [rot for rot in sched.rotations.values() if rot.charging_type == "oppb"]
assert len(oppb_rotations) >= 1
oppb_rotation = oppb_rotations[0]
vehicle = oppb_rotation.vehicle_id
assert oppb_rotation.allow_opp_charging is True
index = list(scen.components.vehicles.keys()).index(vehicle)
min_soc = min(s[index] for s in scen.socs if s[index] is not None)
vehicle_event = [e for e in scen.events.vehicle_events if e.vehicle_id == vehicle]
charge_events = 0
for e in vehicle_event:
if vars(e).get("update", {}).get("connected_charging_station") is not None:
charge_events += 1

assert charge_events > 0, \
"Rotation has no charge events to check if allow_opp_charging works"
for rot in oppb_rotations:
rot.allow_opp_charging = False
scen2 = sched.run(args)

index = list(scen2.components.vehicles.keys()).index(vehicle)
min_soc_charging_not_allowed = min(s[index] for s in scen2.socs if s[index] is not None)
assert min_soc_charging_not_allowed < min_soc

def test_timestep(self):
# Get the parser from util. This way the test is directly coupled to the parser arguments
Expand Down

0 comments on commit bd3f755

Please sign in to comment.