コード例 #1
0
def parse_route_stop_for_user(route_stops, user_inital_stop_db,
                                    destination_stop_db, count=0):
    """creates an itinerary from the user's inital stop to their destination

        >>> route_stops = ['Daly City', 'Balboa Park (SF)', 'Glen Park (SF)', '24th St. Mission (SF)', '16th St. Mission (SF)', 'Civic Center (SF)', 'Powell St. (SF)', 'Montgomery St. (SF)', 'Embarcadero (SF)', 'West Oakland', 'Lake Merritt (Oakland)', 'Fruitvale (Oakland)', 'Coliseum/Oakland Airport', 'San Leandro', 'Bayfair (San Leandro)', 'Castro Valley', 'West Dublin', 'Dublin/Pleasanton']
        >>> user_inital_stop = u'14'
        >>> destination_stop = u'32'
        >>> destination_stop = gets_stop_db(destination_stop)
        >>> user_inital_stop = gets_stop_db(user_inital_stop)
        >>> itinerary = parse_route_stop_for_user(route_stops, user_inital_stop,destination_stop)
        >>> itinerary
        '14, 15, 17, 19, 38, 36, 34, 32'

    """

    start = False
    itinerary = ""

    for stop in route_stops:
        if stop == str(user_inital_stop_db.name):
            start = True
        if start:
            stop_db = gets_stop_name_db(stop)
            if stop_db == []:
                continue
            itinerary = itinerary + str(stop_db[0].stop_code) + ', '
            if stop == str(destination_stop_db.name):
                return itinerary[:-2]

    route_stops.reverse()
    if count == 1:
        return itinerary

    return parse_route_stop_for_user(route_stops, user_inital_stop_db,
                                    destination_stop_db, 1)
コード例 #2
0
def adds_routestop_to_db(stop_routes_agencies_info_bart):
    """add the relationship between routes and stops to db"""
    # import pdb; pdb.set_trace()
    for route in stop_routes_agencies_info_bart:
        route_code = stop_routes_agencies_info_bart[route]['route_code']
        direction = stop_routes_agencies_info_bart[route]['direction']
        agency_code = stop_routes_agencies_info_bart[route]['agency_code']

        if agency_code == 3:

            route_db = gets_route_db(route)
            if not route_db:
                continue

            for stop in stop_routes_agencies_info_bart[route]['stop_list']:

                stops = gets_stop_name_db(stop)
                if len(stops) > 0:

                    route_stop = Route_Stop(
                                            route_id=route_db.route_id,
                                            stop_id=stops[0].stop_code,
                                            )
                    db.session.add(route_stop)
                    db.session.commit()
        else:
            route_db = gets_route_db(route_code, direction)

            for stop in stop_routes_agencies_info_bart[route]['stop_list']:
                stop_id = stop[1]

                stops = gets_stop_db(stop_id)
                route_stop = Route_Stop(
                                        route_id=route_db.route_id,
                                        stop_id=stop_id,
                                        )
                db.session.add(route_stop)
                db.session.commit()

        db.session.commit()
    print "RouteStops Added to DB"
コード例 #3
0
ファイル: process_data.py プロジェクト: rayray1/Rideminder
def parse_route_stop_for_user(route_stops,
                              user_inital_stop_db,
                              destination_stop_db,
                              count=0):
    """creates an itinerary from the user's inital stop to their destination

        >>> route_stops = ['Daly City', 'Balboa Park (SF)', 'Glen Park (SF)', '24th St. Mission (SF)', '16th St. Mission (SF)', 'Civic Center (SF)', 'Powell St. (SF)', 'Montgomery St. (SF)', 'Embarcadero (SF)', 'West Oakland', 'Lake Merritt (Oakland)', 'Fruitvale (Oakland)', 'Coliseum/Oakland Airport', 'San Leandro', 'Bayfair (San Leandro)', 'Castro Valley', 'West Dublin', 'Dublin/Pleasanton']
        >>> user_inital_stop = u'14'
        >>> destination_stop = u'32'
        >>> destination_stop = gets_stop_db(destination_stop)
        >>> user_inital_stop = gets_stop_db(user_inital_stop)
        >>> itinerary = parse_route_stop_for_user(route_stops, user_inital_stop,destination_stop)
        >>> itinerary
        '14, 15, 17, 19, 38, 36, 34, 32'

    """

    start = False
    itinerary = ""

    for stop in route_stops:
        if stop == str(user_inital_stop_db.name):
            start = True
        if start:
            stop_db = gets_stop_name_db(stop)
            if stop_db == []:
                continue
            itinerary = itinerary + str(stop_db[0].stop_code) + ', '
            if stop == str(destination_stop_db.name):
                return itinerary[:-2]

    route_stops.reverse()
    if count == 1:
        return itinerary

    return parse_route_stop_for_user(route_stops, user_inital_stop_db,
                                     destination_stop_db, 1)