示例#1
0
def agency(request, agency_id):
    """
    Browse the information of a transport agency
    """

    agency_loader = AgencyLoader(agency_id)
    agency_loader.load()

    agency = trEntity(agency_loader.get_agency_entity(), request)
    agency["type"] = TransitTypeProperty.get_type_name(agency["type"])

    pathbar = Pathbar(agency=(agency,))

    route_list = agency_loader.get_route_list()
    route_list = [trEntity(route, request) for route in route_list]

    trip_id_list = agency_loader.get_trip_id_list()

    showMap = agency["show_map_in_transit_page"]

    t = loader.get_template("gogogo/transit/agency.html")
    c = RequestContext(
        request,
        {
            "page_title": agency["name"],
            "pathbar": pathbar,
            "agency_kind": "agency",
            "route_kind": "route",
            "agency": agency,
            "showMap": showMap,
            "trip_id_list": trip_id_list,
            "route_list": route_list,
        },
    )

    return HttpResponse(t.render(c))
示例#2
0
    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)