Exemplo n.º 1
0
def test_sanitising_time_going_over_24_hrs():
    t = use_schedule.sanitise_time('25:46:20')
    assert t == datetime(year=1970,
                         month=1,
                         day=2,
                         hour=1,
                         minute=46,
                         second=20)
Exemplo n.º 2
0
def test_sanitising_time_with_non_default_day():
    t = use_schedule.sanitise_time('15:46:20', gtfs_day='20200401')
    assert t == datetime(year=2020,
                         month=4,
                         day=1,
                         hour=15,
                         minute=46,
                         second=20)
Exemplo n.º 3
0
def test_sanitising_time_with_default_day():
    t = use_schedule.sanitise_time('12:46:20')
    assert t == datetime(year=1970,
                         month=1,
                         day=1,
                         hour=12,
                         minute=46,
                         second=20)
Exemplo n.º 4
0
 def generate_trips_dataframe(self, gtfs_day='19700101'):
     df = None
     _df = DataFrame({
         'departure_time': [
             use_schedule.get_offset(self.departure_offsets[i])
             for i in range(len(self.ordered_stops) - 1)
         ],
         'arrival_time': [
             use_schedule.get_offset(self.arrival_offsets[i])
             for i in range(1, len(self.ordered_stops))
         ],
         'from_stop': [
             self.ordered_stops[i]
             for i in range(len(self.ordered_stops) - 1)
         ],
         'to_stop':
         [self.ordered_stops[i] for i in range(1, len(self.ordered_stops))]
     })
     for trip_id, trip_dep_time in self.trips.items():
         trip_df = _df.copy()
         trip_df['trip'] = trip_id
         trip_dep_time = use_schedule.sanitise_time(trip_dep_time,
                                                    gtfs_day=gtfs_day)
         trip_df[
             'departure_time'] = trip_dep_time + trip_df['departure_time']
         trip_df['arrival_time'] = trip_dep_time + trip_df['arrival_time']
         if df is None:
             df = trip_df
         else:
             df = df.append(trip_df)
     df['route'] = self.id
     df['route_name'] = self.route_short_name.replace("\\", "_").replace(
         "/", "_")
     df['mode'] = self.mode
     df['from_stop_name'] = df['from_stop'].apply(
         lambda x: self.stop(x).name.replace("\\", "_").replace("/", "_"))
     df['to_stop_name'] = df['to_stop'].apply(
         lambda x: self.stop(x).name.replace("\\", "_").replace("/", "_"))
     df = df.reset_index(drop=True)
     return df