Example #1
0
    def test_estimated_arrival_time_from_destination(self):
        origin = Stop("NMC", "New Mills Central", 100, 200)
        destination = Stop("MAN", "Manchester", 200, 300)
        train = Train("ID", origin, destination, 1, False)

        arrival_time = train.estimated_arrival_time()

        self.assertEqual(arrival_time, 300)
Example #2
0
    def test_scheduled_departure_time_from_origin(self):
        origin = Stop("NMC", "New Mills Central", 100, 200)
        destination = Stop("MAN", "Manchester", 200, 300)
        train = Train("ID", origin, destination, 1, False)

        departure_time = train.scheduled_departure_time()

        self.assertEqual(departure_time, 100)
Example #3
0
def main():
    num_rows = count_num_rows()
    num_iter = (num_rows + CHUNK_SIZE - 1) // CHUNK_SIZE

    for index_chunk in range(num_iter):
        train = Train(index_chunk)
        train.cv()

    merge_mul_df()
Example #4
0
 def test_sort_departures(self):
     fake_darwin_service = {}
     departures = [
         Train("123", Stop("NMC", "New Mills Central", 100, 100),
               Stop("MAN", "Manchester", 200, 200), 1),
         Train("321", Stop("NMC", "New Mills Central", 50, 50),
               Stop("MAN", "Manchester", 100, 100), 1)
     ]
     app = TrainApp(fake_darwin_service)
     sorted_departures = app.sort_departures(departures)
     self.assertEqual(sorted_departures[0].id, '321')
Example #5
0
    def build_train(self, service_data, from_crs, to_crs):
        station_list = StationList()
        scheduled_departure_time = time_to_integer(service_data['std'])
        estimated_departure_time = time_to_integer(
            self.calculate_estimated_time(service_data['etd'],
                                          service_data['std']))

        origin = Stop(from_crs, station_list.get_station_name(from_crs),
                      scheduled_departure_time, estimated_departure_time)

        calling_points = self.extract_calling_points(service_data)
        destination = self.extract_destination(calling_points, to_crs)
        scheduled_time = destination['st']
        estimated_time = destination['et']
        estimated_time = self.calculate_estimated_time(scheduled_time,
                                                       estimated_time)

        destination = Stop(to_crs, station_list.get_station_name(to_crs),
                           time_to_integer(scheduled_time),
                           time_to_integer(estimated_time))

        platform = self.extract_platform(service_data)
        is_cancelled = self.extract_cancelled(service_data['isCancelled'])
        is_delayed = self.extract_delayed(service_data['std'])

        train = Train(service_data['serviceID'], origin, destination, platform,
                      is_cancelled, is_delayed)
        return train
Example #6
0
 def add_train(self, index: int, line, direction: int, nb_trains: int,
               start_minute: int):
     l: Line = line
     train = Train(self.config, l, l.all_stations[index], direction,
                   nb_trains, start_minute)
     l.add_train(train)
     nb_trains += 1
     self.trains.append(train)
     return nb_trains
def plot_train_val(patterns, fontsize=15):
    import matplotlib.pyplot as plt
    import seaborn as sns
    import matplotlib.ticker as ticker

    dummy_trainer = Train(None, None, None, None)
    for pattern in patterns:
        for cpt_fn in glob.glob(pattern):
            cpt = torch.load(cpt_fn)
            name = cpt_fn.split('.')[0].split('/')[-1]
            l = cpt['train_losses']
            dummy_trainer.all_losses = l
            plt.plot(dummy_trainer.smooth_loss(), label=name)

    plt.legend(loc='center right', bbox_to_anchor=(1.5, 0.5))
    plt.title('training loss (RMSE)', fontsize=fontsize)
    plt.grid()
    plt.show()

    for pattern in patterns:
        for cpt_fn in glob.glob(pattern):
            cpt = torch.load(cpt_fn)
            name = cpt_fn.split('.')[0].split('/')[-1]
            l = cpt['val_losses']
            dummy_trainer.val_losses = l
            plt.plot(dummy_trainer.smooth_valloss(), label=name)

    plt.legend(loc='center right', bbox_to_anchor=(1.5, 0.5))
    plt.title('validation loss (RMSE)', fontsize=fontsize)
    plt.grid()
    plt.show()
Example #8
0
    def test_is_cancelled(self):
        origin = Stop("NMC", "New Mills Central", 100, 200)
        destination = Stop("MAN", "Manchester", 200, 300)
        cancelled_train = Train("ID", origin, destination, 1, True)
        non_cancelled_train = Train("ID", origin, destination, 1, False)

        self.assertTrue(cancelled_train.is_cancelled())
        self.assertFalse(non_cancelled_train.is_cancelled())
def get_train_val_curves(pattern):
    dummy_trainer = Train(None, None, None, None)
    tr_curves = []
    val_curves = []
    name = ""
    for cpt_fn in glob.glob(pattern):
        cpt = torch.load(cpt_fn)
        name = cpt_fn.split('.')[0].split('/')[-1]
        dummy_trainer.all_losses = cpt['train_losses']
        dummy_trainer.val_losses = cpt['val_losses']

        tr_curves.append(dummy_trainer.smooth_loss())
        val_curves.append(dummy_trainer.smooth_valloss())
    return tr_curves, val_curves, name