Skip to content

Commit

Permalink
python: fix railjson_generator bug (simulation_builder)
Browse files Browse the repository at this point in the history
  • Loading branch information
shenriotpro committed Dec 28, 2023
1 parent 6c12f67 commit c2cbdfe
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions python/railjson_generator/railjson_generator/simulation_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,20 @@ def add_train_schedule(self, *locations: Location, **kwargs) -> TrainSchedule:
return train_schedule

def add_train_schedule_group(
self, locations: Union[Sequence[Location], Sequence[DirectedLocation]], *train_schedules: TrainSchedule
self, locations: Sequence[Union[Location, DirectedLocation]], *train_schedules: TrainSchedule
) -> TrainScheduleGroup:
"""Creates a train schedule group containing the given train schedules.
Simple locations are expanded to directed locations in all directions."""
if len(locations) < 2:
raise ValueError(f"Expected at least 2 locations, got {len(locations)}")
if isinstance(locations[0], Location):
locations = [
[DirectedLocation.from_location(loc, direction) for direction in Direction] for loc in locations
]
else:
locations = [[loc] for loc in locations]
train_schedule_group = TrainScheduleGroup(list(train_schedules), locations)
directed_locations = [
[loc]
if isinstance(loc, DirectedLocation)
else [DirectedLocation.from_location(loc, direction) for direction in Direction]
for loc in locations
]
train_schedule_group = TrainScheduleGroup(list(train_schedules), directed_locations)
self.simulation.train_schedule_groups.append(train_schedule_group)
return train_schedule_group

Expand Down

0 comments on commit c2cbdfe

Please sign in to comment.