def data_received(self,data): result = self.rtsim.updateVehicles(xml=data) if result: print result ((trip_id, offset, error), segment) = result gpssched = GPSBusTrack.GPSBusSchedule( segment = segment, trip_id = trip_id, offset = offset ); if config['store_intermediate'] is True: db.export_lateness_data( gpssched, error ) rtdb.record_observations( gpssched ) print "GTFS Matchup Discovered" print "Trip:",trip_id for actual_arrival in gpssched.getGPSSchedule(): if actual_arrival['actual_arrival_time_seconds']: lateness = int(actual_arrival['actual_arrival_time_seconds'] - actual_arrival['departure_time_seconds']) else: lateness = None print " Arrived at stop %s at time %s, which was %s seconds late" \ % (actual_arrival['stop_id'], actual_arrival['actual_arrival_time_seconds'], lateness) # in all cases db.commit()
vehdata[attr] = vehicle.getAttribute(attr) if (not routes) or (vehdata['routeTag'] in routes): updated_data.append(vehdata) return updated_data if __name__ == "__main__": if len(sys.argv) < 2: print print "Usage: %s filename" % sys.argv print " The file should have a line-by-line listing of route ID's." print " You may comment out lines with a #" print print " *** To retrieve ALL route ID's, try '%s ALL'." % sys.argv print sys.exit(1) print "Retrieving data on", time.ctime(), "..." sys.stdout.flush() fname = sys.argv[1] if fname == "ALL": routes = None else: routes = read_routes(fname) updated_routes = get_updated_routes(routes) db.update_routes(updated_routes) db.commit() print "... Done (", time.ctime(), ").\n" sys.stdout.flush()
if __name__=="__main__": from os import sys if len(sys.argv) <= 1: print "Usage: %s cmd" %(sys.argv[0],) print " where cmd (and its effect) is one of the following:" print """ trips -- populates the trip information populate_ridtags -- autopopulates route_id/dirtag matchup match_trips [timezonediff] -- match gtfs<-> gps trips timezonediff is the hours to add to the time recorded in the DB in order to match up with the times listed in the GTFS data. gps_schedules -- from gps trips find actual schedules fix_earlybirds -- fix too-early gps trips """ sys.exit(0) arg = sys.argv[1] if arg == 'trips': populate_all_trip_information() elif arg == 'match_trips': try: tzdiff = int(sys.argv[2]) except: raise Exception, "Required to enter timezone diff (integer) for match_trips" load_and_cache_routes(db.get_route_names(),tzdiff) elif arg == 'gps_schedules': create_all_actual_timetables() elif arg == 'fix_earlybirds': fix_all_earlybirds() elif arg == 'populate_ridtags': auto_populate_rid_dirtags() db.commit()
vehdata[attr] = vehicle.getAttribute(attr); if (not routes) or (vehdata['routeTag'] in routes): updated_data.append(vehdata); return updated_data; if __name__ == "__main__": if len(sys.argv) < 2: print print "Usage: %s filename" % sys.argv print " The file should have a line-by-line listing of route ID's." print " You may comment out lines with a #" print print " *** To retrieve ALL route ID's, try '%s ALL'." % sys.argv print sys.exit(1) print "Retrieving data on",time.ctime(),"..." sys.stdout.flush() fname = sys.argv[1] if fname=="ALL": routes = None else: routes = read_routes(fname); updated_routes = get_updated_routes(routes); db.update_routes(updated_routes); db.commit(); print "... Done (",time.ctime(),").\n" sys.stdout.flush()