def trip(request, agency_id, route_id, trip_id): """ Browse the information of a trip """ trip_loader = TripLoader(trip_id) trip_loader.load() trip_entity = trip_loader.get_trip() agency_entity = trip_loader.get_agency() route_entity = trip_loader.get_route() trip_entity = trEntity(trip_entity, request) agency_entity = trEntity(agency_entity, request) route_entity = trEntity(route_entity, request) stop_list = [trEntity(stop, request) for stop in trip_loader.get_stop_list()] faretrip_list = [] for faretrip in trip_loader.get_faretrip_list(): entity = trEntity(faretrip, request) entity["fare_range"] = None if entity["max_fare"] > 0: if entity["max_fare"] != entity["min_fare"]: entity["fare_range"] = "$%0.1f - $%0.1f" % (entity["min_fare"], entity["max_fare"]) else: entity["fare_range"] = "$%0.1f" % (entity["min_fare"]) faretrip_list.append(entity) pathbar = Pathbar(agency=(agency_entity, route_entity, trip_entity)) return render_to_response( request, "gogogo/transit/trip.html", { "page_title": trip_entity["headsign"], "pathbar": pathbar, "object_type": "trip", "agency": agency_entity, "route": route_entity, "trip": trip_entity, "stop_list": stop_list, "faretrip_list": faretrip_list, "faretrip_kind": "faretrip", }, )
def load(self): """ Load graph from bigtable """ route_list = [] agency_list = [] cluster_list = [] trip_list = [] query = Agency.all().filter("no_service = ", False) for agency in query: agency_list.append(agency) # Load all the trip by using TripLoader trip_loader_list = [] stop_table = {} limit = 1000 entities = Trip.all(keys_only=True).fetch(limit) while entities: for key in entities: loader = TripLoader(key.id_or_name()) loader.load(stop_table=stop_table) stop_list = loader.get_stop_list() for stop in stop_list: stop_table[stop["id"]] = stop agency = loader.get_agency() if agency["free_transfer"] == False: # Ignore agency with free transfer service trip_loader_list.append(loader) entities = Trip.all(keys_only=True).filter("__key__ >", entities[-1]).fetch(limit) # Load all cluster query = Cluster.all() for cluster in query: cluster_list.append(cluster) cluster_name = cluster.key().id_or_name() node = Node(name=cluster.key().id_or_name()) # Cluster to ID matching self.cluster_id[cluster.key().id_or_name()] = self.add_node(node) # logging.info(cluster.key().id_or_name()) for key in cluster.members: name = key.id_or_name() if name in stop_table: self.stop_to_cluster[name] = cluster_name # Process agency with "free_transfer" for agency in agency_list: if agency.free_transfer: logging.info("Processing " + agency.key().id_or_name()) query = db.GqlQuery( "SELECT __key__ from gogogo_farestop WHERE agency = :1 and default = True limit 1", agency ) key = query.get() if key == None: continue farestop_loader = FareStopLoader(key.id_or_name()) farestop_loader.load() farestop = farestop_loader.get_farestop() pair_list = farestop_loader.get_pair_list() for pair in pair_list: try: a = self.get_node_by_stop(pair["from"]) b = self.get_node_by_stop(pair["to"]) arc = TransitArc(agency=agency.key().id_or_name(), weight=pair["fare"]) arc.link(a, b) self.add_arc(arc) except KeyError, e: logging.error(str(e) + "not found")