From 46400696985edabbb8207d808f5a762b006f1d07 Mon Sep 17 00:00:00 2001 From: LucasJavaudin Date: Wed, 18 Aug 2021 10:18:12 +0200 Subject: [PATCH] do not cut trips --- metrosim/models/pt_network.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/metrosim/models/pt_network.py b/metrosim/models/pt_network.py index ef950c6..b6adfb4 100644 --- a/metrosim/models/pt_network.py +++ b/metrosim/models/pt_network.py @@ -117,12 +117,14 @@ class PTNetwork(nx.MultiDiGraph): # Sort stop_times by increasing stop_sequence. stop_times = sorted( stop_times, key=lambda x: int(x['stop_sequence'])) + first_departure = _parse_time(stop_times[0]['departure_time']) + last_arrival = _parse_time(stop_times[-1]['arrival_time']) + if first_departure > to_time or last_arrival < from_time: + # This trip is not in the desired time window. + continue for prev_stop, next_stop in zip(stop_times[:-1], stop_times[1:]): dep_time = _parse_time(prev_stop['departure_time']) arr_time = _parse_time(next_stop['arrival_time']) - if dep_time < from_time or arr_time > to_time: - # This trip stop is not in the desired time window. - continue route_id = self.trips[trip_id]['route_id'] self.add_edge( prev_stop['stop_id'],