def from_entity(self, graph, entity): self.agency = None self.trip = None Arc.from_entity(self, graph, entity) if "agency" in entity: self.agency = entity["agency"] if "trip" in entity: self.trip = entity["trip"]
def __init__(self, **kwargs): self.agency = None self.trip = None if "agency" in kwargs: self.agency = kwargs["agency"] del kwargs["agency"] if "trip" in kwargs: self.trip = kwargs["trip"] del kwargs["trip"] Arc.__init__(self, **kwargs)
def to_entity(self): entity = Arc.to_entity(self) if self.agency: entity["agency"] = self.agency if self.trip: entity["trip"] = self.trip return entity
def load(self): """ Load from database or bigtable """ agency_loader = AgencyLoader(self.id) agency_loader.load() trip_id_list = agency_loader.get_trip_id_list() trip_loader_list = [] stop_table = {} for trip_id in trip_id_list: trip_loader = TripLoader(trip_id) trip_loader.load(stop_table=stop_table) trip_loader_list.append(trip_loader) prev_node = None for stop in trip_loader.get_stop_list(): node = self.search_node(stop["id"]) if node == None: node = Node(name=stop["id"]) self.add_node(node) if prev_node: arc = Arc(weight=1) arc.link(prev_node, node) self.add_arc(arc) prev_node = node agency = agency_loader.get_agency() key = db.Key.from_path(Agency.kind(), str(agency["id"])) query = Transfer.all().filter("agency = ", key) stop_a_property = getattr(Transfer, "stop_a") stop_b_property = getattr(Transfer, "stop_b") for transfer in query: stop_a = stop_a_property.get_value_for_datastore(transfer) stop_b = stop_b_property.get_value_for_datastore(transfer) node_a = self.search_node(stop_a.id_or_name()) if node_a == None: node_a = Node(name=stop_a.id_or_name()) self.add_node(node_a) node_b = self.search_node(stop_b.id_or_name()) if node_b == None: node_b = Node(name=stop_b.id_or_name()) self.add_node(node_b) arc = Arc(weight=1) arc.link(node_a, node_b) self.add_arc(arc) # logging.info("%s => %s" %(arc.src.name , arc.dest.name)) arc = Arc(weight=1) arc.link(node_b, node_a) self.add_arc(arc)