예제 #1
0
    def generate_time_tables(self):
        """
        Create all time tables for time dependant aspects of the graph.
        """
        from dbanalysis.classes import weather_getter
        self.total_routes = 0
        self.failed_routes = 0
        # grab a five day weather forecast
        w_getter = weather_getter.weather_getter()
        weather = w_getter.get_weather()
        import datetime
        #get current datetime
        dt = datetime.datetime.now()
        count = 0
        # for every variation in every route,
        for route in self.routes:
            # some routes are empty, ignore those.
            if len(self.routes[route]) < 1:
                continue
            times = self.time_tabler.get_dep_times_N_days(route,
                                                          dt,
                                                          number_days=7)
            # gets a timetable describing every scheduled departure time for the first stop on that route
            # over the next five days

            for variation in times:

                #if not self.selector.get_unavailable(route,int(variation)):
                try:

                    X = times[variation]

                    #merge with weather data to add weather features.
                    X['matrix'] = pd.merge(
                        X['matrix'],
                        weather[['day', 'hour', 'rain', 'temp']],
                        on=['day', 'hour'])
                    #X['matrix']['rain']=0.08
                    #X['matrix']['temp']=10.0
                    #X['matrix']['vappr']=10.0

                    #run this data frame on the route described in the pattern
                    self.run_route(X['matrix'], X['pattern'])

                #unfortunately, the routes in 'routes' and the routes in the time tabler differ slightly
                #the time table routes include a few variation we haven't managed to model.
                #these will break.
                #Unfortuntely, there wasn't time to properly address this problem.
                except Exception as e:
                    print(str(e))

                    f = open('failedrouteslog.log', 'a')
                    f.write(route + ' ' + str(e))
                    f.close()
예제 #2
0
 def generate_time_tables(self):
     """
     Create all time tables for time dependant aspects of the graph.
     """
     from dbanalysis.classes import weather_getter
     self.total_routes = 0
     self.failed_routes = 0
     w_getter = weather_getter.weather_getter()
     weather = w_getter.get_weather()
     import datetime
     dt = datetime.datetime.now()
     count = 0
     for route in self.routes:
         if len(route) < 1:
             continue            
         times = self.time_tabler.get_dep_times_five_days(route,dt)
         
         for variation in times:
             self.total_routes +=1
             #if not self.selector.get_unavailable(route,int(variation)):
             try:    
                 count +=1
                 print(count,route+'_'+str(variation))
                 X=times[variation]
                 
                     # merge with weather data to add weather features.
                 #X['matrix'] = pd.merge(X['matrix'],weather[['day','hour','rain','temp','vappr']],on = ['day','hour'])
                 X['matrix']['rain']=0.08
                 X['matrix']['temp']=10.0
                 X['matrix']['vappr']=10.0
                 
                 
                 
                 self.run_route(X['matrix'],X['pattern'])
                 try:
                     pass
                 except Exception as e:
                     print(e)
             
             except Exception as e:
                 print(e)
                 self.failed_routes +=1
         try:
             pass    
         except Exception as e:
             
             print(e,'broken timetabler',route)
             pass
예제 #3
0
#from . import weather_getter
from dbanalysis.classes.weather_getter import weather_getter
weather=weather_getter()
df=weather.get_weather()
print(df)