def storeCalTrainStop():

    Transit = get_transit_db()
    todo = {}
    stops = []
    get_transit_db().remove({'type': 'CalTrain'})
    # print(root[1][0].find('name').text)
    file_name = '/Users/Mogeng/Berkeley/Semester2/E-Mission/Transit_routes/CalTrain.csv'
    with open(file_name, 'rU') as csvfile:
        r = csv.reader(csvfile, delimiter=',', quotechar='|')
        for row in r:
            time.sleep(1)
            print(row[0])
            # print(add)
            url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' + urllib.quote_plus(
                row[0] + ' caltrain station')
            print(url)
            geo = json.load(urllib.urlopen(url))
            result = geo['results'][0]
            print(result['geometry']['location'])
            stops.append([
                result['geometry']['location']['lat'],
                result['geometry']['location']['lng']
            ])

    todo['type'] = 'CalTrain'
    todo['route'] = 'CalTrain'
    todo['stops'] = stops
    Transit.insert(todo)
def storeTransitStop(type, route):
    Transit = get_transit_db()
    todo = {}
    stops = []
    tree = ET.ElementTree(file=urllib2.urlopen(
        'http://api.bart.gov/api/stn.aspx?cmd=stns&key=MW9S-E7SL-26DU-VV8V'))
    root = tree.getroot()
    # print(root[1][0].find('name').text)
    file_name = '/Users/Mogeng/Berkeley/Semester2/E-Mission/Transit_routes/' + type + '_' + route + '.csv'
    with open(file_name, 'rU') as csvfile:
        r = csv.reader(csvfile, delimiter=',', quotechar='|')
        for row in r:
            print(row[0])
            for i in range(len(root[1])):
                if row[0].replace(' / ', '/').replace('Street', 'St.').replace(
                        'International',
                        "Int'l") == root[1][i].find('name').text:
                    print(float(root[1][i].find('gtfs_latitude').text),
                          float(root[1][i].find('gtfs_longitude').text))
                    stops.append([
                        float(root[1][i].find('gtfs_latitude').text),
                        float(root[1][i].find('gtfs_longitude').text)
                    ])
                    break

    todo['type'] = type
    todo['route'] = route
    todo['stops'] = stops
    Transit.insert(todo)
def transit_stop_match_score(segment,radius1=300):
    Transits=get_transit_db()
    transitMatch={}
    route_seg=getRoute(segment['_id'])
    for type in Transits.distinct('type'):
        for entry in Transits.find({'type':type}):
            transitMatch[type]=matchTransitStops(route_seg,entry['stops'],radius1)
            if transitMatch[entry['type']]==1:
                break
    return transitMatch
def transit_route_match_score(segment,step1=100000,step2=100000,method='lcs',radius1=2500,threshold=0.5):
    Transits=get_transit_db()
    transitMatch={}
    route_seg=getRoute(segment['_id'])
    for type in Transits.distinct('type'):
        for entry in Transits.find({'type':type}):
            transitMatch[type]=matchTransitRoutes(route_seg,entry['stops'],step1,step2,method,radius1,threshold)
            if transitMatch[entry['type']]==1:
                break
    return transitMatch
Example #5
0
def transit_stop_match_score(segment, radius1=300):
    Transits = get_transit_db()
    transitMatch = {}
    route_seg = getRoute(segment['_id'])
    for type in Transits.distinct('type'):
        for entry in Transits.find({'type': type}):
            transitMatch[type] = matchTransitStops(route_seg, entry['stops'],
                                                   radius1)
            if transitMatch[entry['type']] == 1:
                break
    return transitMatch
Example #6
0
def transit_route_match_score(segment,
                              step1=100000,
                              step2=100000,
                              method='lcs',
                              radius1=2500,
                              threshold=0.5):
    Transits = get_transit_db()
    transitMatch = {}
    route_seg = getRoute(segment['_id'])
    for type in Transits.distinct('type'):
        for entry in Transits.find({'type': type}):
            transitMatch[type] = matchTransitRoutes(route_seg, entry['stops'],
                                                    step1, step2, method,
                                                    radius1, threshold)
            if transitMatch[entry['type']] == 1:
                break
    return transitMatch