Exemplo n.º 1
0
    def __init__(self,
                 train=False,
                 load_from_pickle=False,
                 load_timetables=True):
        self.stops_dict = json.loads(
            open(
                '/home/student/dbanalysis/dbanalysis/resources/stops_trimmed.json',
                'r').read())
        stops_map = rt.map_all_stops()
        self.nodes = {}
        self.routes = json.loads(
            open(
                '/home/student/dbanalysis/dbanalysis/resources/trimmed_routes.json',
                'r').read())
        self.route_keys = [
            i.split('_')[0]
            for i in os.listdir('/home/student/data/routesplits')
        ]
        self.time_tabler = time_tabler.time_tabler()

        if load_timetables:
            #load with models built and timetables computed
            import pickle
            with open('/home/student/networkpickle', 'rb') as handle:
                self.nodes = pickle.load(handle)

        elif load_from_pickle:
            #load with models already built
            import pickle
            with open(
                    '/home/student/dbanalysis/dbanalysis/resources/models/simple_linear_network1532452086.8646586.pickle',
                    'rb') as handle:
                self.nodes = pickle.load(handle)
        elif train:
            #load and train models
            for stop in [stop for stop in self.stops_dict\
                    if os.path.isdir('/home/student/data/stops/'+str(stop))\
                    and len(os.listdir('/home/student/data/stops/'+str(stop))) > 1]:

                print('Modelling stop', stop)
                self.nodes[str(stop)]=(bus_stop.stop(stop,\
                                    name=self.stops_dict[str(stop)]['stop_name'],\
                                    coords=[self.stops_dict[str(stop)]['lat'],\
                                    self.stops_dict[str(stop)]['lon']]\
                                    , from_pickle = False))

            print('Only found data for',
                  len(self.nodes) / len(stops_map), 'stops')

            self.dump_network(
                '/home/student/dbanalysis/dbanalysis/resources/models')
Exemplo n.º 2
0
print(route[1]['pattern'])
to_model = set()
all_routes = tt.get_all_routes()
for key in all_routes:
    route = tt.get_dep_times(key, dt)
    for r in route:
        for x in r['pattern'][:-1]:
            to_model.add(x)

models = {}
from dbanalysis.classes import stop
t1 = time.time()
for s in to_model:
    print(s)
    try:
        models[s] = stop.stop(s, from_pickle=False)
    except:
        print(stop)
print('models built in ', time.time() - t1)

all_routes = tt.get_all_routes()
#now feed the matrix into these stops...
matrix = route[1]['matrix']
import time
t1 = time.time()
count = 0
fails = 0
for key in all_routes:
    route = tt.get_dep_times(key, dt)
    for r in route:
        try: