def test_parse_route_stop_for_user(self): 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) self.assertEqual(parse_route_stop_for_user(route_stops, user_inital_stop, destination_stop), '14, 15, 17, 19, 38, 36, 34, 32')
def gets_user_itinerary(agency, route_code, destination_stop, user_inital_stop, route_name): """returns a list of the user's stops from inital to destination >>> agency = u'BART' >>> route_code = u'920' >>> destination_stop = u'32' >>> user_inital_stop = u'14' >>> route_name = u'Daly City - Dublin/Pleasanton' >>> user_itinerary = gets_user_itinerary(agency, route_code, destination_stop, user_inital_stop, route_name) >>> user_itinerary '14, 15, 17, 19, 38, 36, 34, 32' """ route = gets_route_id_db(route_code) if not route: route = gets_route_db(route_code) destination_stop = gets_stop_db(destination_stop) user_inital_stop = gets_stop_db(user_inital_stop) route_stops = gets_stops_from_route(str(route.stop_list), route.agency.agency_id) itinerary = parse_route_stop_for_user(route_stops, user_inital_stop, destination_stop) return itinerary
def setUp(self): """Creating mock data to test aganist""" user_db = User.query.filter_by(user_name="Jessica").first() user_inital_stop = '14' user_inital_stop = gets_stop_db(user_inital_stop) destination_stop = '32' destination_stop = gets_stop_db(destination_stop) route_code = '153' route = gets_route_id_db(route_code) agency = 'BART' arrival_time_datetime = datetime.datetime(2016, 7, 31, 4, 39, 53, 25840) adds_transit_request(user_inital_stop.stop_code, destination_stop.stop_code, agency, route.name, route.route_code, arrival_time_datetime, user_db)
def test_process_lat_lng_get_arrival_datetime(self): user_lat = 37.784991 user_lon = -122.406857 destination_stop = '32' destination_stop = gets_stop_db(destination_stop) result = process_lat_lng_get_arrival_datetime(user_lat, user_lon, destination_stop) from datetime import datetime now = datetime.now() self.assertEqual(result.year, now.year)
def test_parse_route_stop_for_user(self): 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) self.assertEqual( parse_route_stop_for_user(route_stops, user_inital_stop, destination_stop), '14, 15, 17, 19, 38, 36, 34, 32')
def process_user_info(): """recieves the user data and processes data""" user_name = request.form.get("name") raw_user_phone_num = request.form.get("phone") agency = request.form.get("agency") route_code = request.form.get("route") user_inital_stop = request.form.get("user_stop") destination_stop = request.form.get("destination_stop") user_lat = request.form.get("lat") user_lon = request.form.get("lng") route = gets_route_id_db(route_code) if user_lat: user_inital_stop = gets_user_stop_id(user_lat, user_lon, route) user_inital_stop = gets_stop_db(user_inital_stop) if not user_lat: user_lat = user_inital_stop.lat user_lon = user_inital_stop.lon destination_stop = gets_stop_db(destination_stop) arrival_time_datetime = process_lat_lng_get_arrival_datetime(user_lat, user_lon, destination_stop) user_phone = convert_to_e164(raw_user_phone_num) user_db = checks_user_db(user_name, user_phone) adds_transit_request(user_inital_stop.stop_code, destination_stop.stop_code, agency, route.name, route.route_code, arrival_time_datetime, user_db) return render_template("/thank_you.html", user_fname=user_name, user_phone=user_phone, route=route, user_inital_stop=user_inital_stop, destination_stop=destination_stop)
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"