Esempio n. 1
0
 def test(self):
     """
     Function for testing the module train_io.py
     """
     print "CALL1:"
     print "TrainIo('Oslo')._print_class_vars()"
     self._print_class_vars()
     print "CALL2:"
     print "time_diff('10:15', '11:09')"
     print time_diff('10:15', '11:09')
Esempio n. 2
0
 def _cache_windows(self, scheduled, dep_windows, arr_windows):
     """
     Finds windows for a dict/list of trains
     re
     """
     for sched in scheduled:
         for train in self.get_all_trains():
             if not str_eq(sched, train):
                 #Spags?
                 done = False
                 while not done:
                     for row in self.all_data[train]:
                         if not str_eq(row, 'missing'):
                             #Check if train departs within a 15 min window
                             #of scheds departure/arrival
                             if(row[self.legend['Pl.avg.']] and
                                abs(time_diff(row[self.legend['Pl.avg.']],
                                              scheduled[sched]))
                                < self.windowsize/2.):
                                 if not sched in dep_windows:
                                     dep_windows[sched] = []
                                 dep_windows[sched].append(train)
                                 done = True
                             #Check if train arrives within a 15 min window
                             #of scheds departure/arrival
                             if(row[self.legend['Pl.ank.']] and
                                    abs(time_diff(row[self.legend['Pl.ank.']]
                                                  , scheduled[sched]))
                                < self.windowsize/2.):
                                 if not sched in arr_windows:
                                     arr_windows[sched] = []
                                 arr_windows[sched].append(train)
                                 done = True
                         if done:
                             """
                             Here I make the assumption that if a train has a
                             scheduled departure/arrival time then it is
                             stored in all the csv files. Also that the
                             planned departure/arrival time is the same
                             for all days, which is not always the case,
                             but for most trains it is.
                             """#pylint:disable=pointless-string-statement
                             break
                     done = True
     return dep_windows, arr_windows
Esempio n. 3
0
    def data_to_array(self, train, plan, act):
        """
        Stores the delay times for a specified
        trainnumber read from dict all_data
        """
        train_data = self.all_data[train]
        delay_list = []
        for row in train_data:
            if str_eq('missing', row):
                delay_list.append(float('Nan'))
            else:
                try:
                    delay_list.append(time_diff(row[self.legend[act]],
                                                row[self.legend[plan]]))
                except ValueError:
                    delay_list.append(float('Nan'))

        return numpy.array(delay_list) #pylint:disable=no-member