def storeCalTrainStop(): Transit = edb.get_transit_db() todo = {} stops = [] edb.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.parse.quote_plus( row[0] + ' caltrain station') print(url) geo = json.load(urllib.request.urlopen(url)) result = geo['results'][0] print(result['geometry']['location']) stops.append([ result['geometry']['location']['lng'], result['geometry']['location']['lat'] ]) todo['type'] = 'CalTrain' todo['route'] = 'CalTrain' todo['stops'] = stops Transit.insert(todo)
def storeCalTrainStop(): Transit=edb.get_transit_db() todo={} stops=[] edb.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.parse.quote_plus(row[0]+' caltrain station') print(url) geo= json.load(urllib.request.urlopen(url)) result=geo['results'][0] print(result['geometry']['location']) stops.append([result['geometry']['location']['lng'],result['geometry']['location']['lat']]) todo['type']='CalTrain' todo['route']='CalTrain' todo['stops']=stops Transit.insert(todo)
def storeTransitStop(type, route): Transit = edb.get_transit_db() todo = {} stops = [] tree = ET.ElementTree(file=urllib.request.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_longitude').text), float(root[1][i].find('gtfs_latitude').text))) stops.append([ float(root[1][i].find('gtfs_longitude').text), float(root[1][i].find('gtfs_latitude').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
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
def storeTransitStop(type,route): Transit=edb.get_transit_db() todo={} stops=[] tree = ET.ElementTree(file=urllib.request.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_longitude').text),float(root[1][i].find('gtfs_latitude').text))) stops.append([float(root[1][i].find('gtfs_longitude').text),float(root[1][i].find('gtfs_latitude').text)]) break todo['type']=type todo['route']=route todo['stops']=stops Transit.insert(todo)