def plot_each_route_cluster_for_user(user_id, method='lcs'): i = 0 Sections = get_section_db() user_route_clusters = get_routeCluster_db().find_one( {'$and': [{ 'user': user_id }, { 'method': method }]}) # plot each cluster as a file. for idx in user_route_clusters['clusters'].keys(): print idx gmap = pygmaps.maps(37.8717, -122.2728, 14) # gmap = pygmaps.maps(getRoute(idx)[0][0], getRoute(idx)[0][1], 14) section = Sections.find_one({'_id': idx}) r = lambda: random.randint(0, 255) color = '#%02X%02X%02X' % (r(), r(), r()) drawSection(section, 'path', gmap, color) print len(user_route_clusters['clusters'][idx]) first = True for idi in user_route_clusters['clusters'][idx]: # print(Sections.find({'_id': idi}).count()) section = Sections.find_one({'_id': idi}) if first: print section first = False color = '#%02X%02X%02X' % (r(), r(), r()) drawSection(section, 'path', gmap, color) gmap.draw(str(user_id) + '_' + method + '_' + str(i) + '.html') i += 1 break
def compareTrips(section1, section2): startPoint = section1['section_start_point']['coordinates'] # coordinates are in GeoJSON format, ie lng, lat gmap = pygmaps.maps(startPoint[1], startPoint[0], 14) drawSection(section1, PATH,gmap,COLOR[1]) drawSection(section2, PATH,gmap,COLOR[4]) gmap.draw('gmap_display/compare.html')
def plot_each_route_cluster_for_user(user_id,method='lcs'): i=0 Sections = get_section_db() user_route_clusters = get_routeCluster_db().find_one({'$and':[{'user':user_id},{'method':method}]}) # plot each cluster as a file. for idx in user_route_clusters['clusters'].keys(): print idx gmap = pygmaps.maps(37.8717, -122.2728, 14) # gmap = pygmaps.maps(getRoute(idx)[0][0], getRoute(idx)[0][1], 14) section=Sections.find_one({'_id': idx}) r = lambda: random.randint(0,255) color = '#%02X%02X%02X' % (r(),r(),r()) drawSection(section, 'path', gmap,color) print len(user_route_clusters['clusters'][idx]) first = True for idi in user_route_clusters['clusters'][idx]: # print(Sections.find({'_id': idi}).count()) section=Sections.find_one({'_id': idi}) if first: print section first = False color = '#%02X%02X%02X' % (r(),r(),r()) drawSection(section, 'path', gmap,color) gmap.draw(str(user_id) + '_'+ method+ '_'+str(i) + '.html') i+=1 break
def display_trip(user, date, option): user_id = UUID(user) user_home = detect_home(user_id) gmap = pygmaps.maps(user_home[1], user_home[0], 14) start, end = Date(date) for section in get_section_db().find({"$and":[{'user_id':user_id},{"section_start_datetime": {"$gte": start, "$lt": end}}]}): drawSection(section, option, gmap) gmap.draw('gmap_display/' + str(start)[:10] + '_' + user + '.html')
def drawSectionsFromList(sectionIdList, outPath): sectionJsonList = [get_section_db().find_one({"_id": sid}) for sid in sectionIdList] bounds = tauq.get_bounds(sectionJsonList) gmap = pygmaps.maps((bounds[0].lat + bounds[1].lat)/2, (bounds[0].lon + bounds[1].lon)/2, 10) drawSections(sectionJsonList, ALL, gmap, "random") gmap.draw(outPath)
def display_home(): mymap_home = pygmaps.maps(37.8556475757, -122.248774009,14) for user in get_section_db().distinct('user_id'): print(user) user_home=detect_home(user) print(user_home) if user_home!='N/A': mymap_home.addpoint(user_home[1], user_home[0], "#FF0000") mymap_home.draw('mymap_home.html')
def plot_common_routes_for_user(user_id, method='lcs'): Sections = get_section_db() idxs = get_common_routes_for_user(user_id, method) gmap = pygmaps.maps(37.8717, -122.2728, 14) for idx in idxs: r = lambda: random.randint(0, 255) color = '#%02X%02X%02X' % (r(), r(), r()) section = Sections.find_one({'_id': idx}) print section drawSection(section, 'path', gmap, color) gmap.draw(str(user_id) + '_' + method + '.html')
def plot_common_routes_for_user(user_id,method='lcs'): Sections = get_section_db() idxs = get_common_routes_for_user(user_id,method) gmap = pygmaps.maps(37.8717, -122.2728, 14) for idx in idxs: r = lambda: random.randint(0,255) color = '#%02X%02X%02X' % (r(),r(),r()) section = Sections.find_one({'_id': idx}) print section drawSection(section,'path',gmap,color) gmap.draw(str(user_id) + '_'+ method + '.html')
def drawSectionsFromList(sectionIdList, outPath): sectionJsonList = [ get_section_db().find_one({"_id": sid}) for sid in sectionIdList ] bounds = tauq.get_bounds(sectionJsonList) gmap = pygmaps.maps((bounds[0].lat + bounds[1].lat) / 2, (bounds[0].lon + bounds[1].lon) / 2, 10) drawSections(sectionJsonList, ALL, gmap, "random") gmap.draw(outPath)
def searchTrip(user, period, startpoint, endpoint, mode, option): user_id = UUID(user) user_home = detect_home(user_id) gmap = pygmaps.maps(user_home[1], user_home[0], 14) start, end = Date(period) sectionList = [] startpoint = Geocoder.geocode(startpoint)[0].coordinates endpoint = Geocoder.geocode(endpoint)[0].coordinates for section in get_section_db().find({ "$and": [{ "mode": mode }, { "mode": { "$ne": 'airplane' } }, { "mode": { "$ne": 7 } }, { "section_start_point": { "$ne": None } }, { "section_end_point": { "$ne": None } }] }): point_start = section['section_start_point']['coordinates'] point_end = section['section_end_point']['coordinates'] if calDistance(startpoint, point_start) < 100 and calDistance( endpoint, point_end) < 100: sectionList.append(section['_id']) gmap.addpoint(point_end[1], point_end[0], COLOR[1]) gmap.addpoint(point_start[1], point_start[0], COLOR[1]) drawSection(section, option, gmap) gmap.draw('gmap_display/' + 'SearchResult' + str(start)[:10] + '-' + str(end)[:10] + '_' + user + '.html')
def searchTrip(user, period, startpoint, endpoint, mode, option): user_id = UUID(user) user_home = detect_home(user_id) gmap = pygmaps.maps(user_home[1], user_home[0], 14) start, end = Date(period) sectionList = [] startpoint = Geocoder.geocode(startpoint)[0].coordinates endpoint = Geocoder.geocode(endpoint)[0].coordinates for section in get_section_db().find({"$and":[ {"mode": mode}, {"mode": {"$ne": 'airplane'}}, {"mode": {"$ne":7}}, {"section_start_point": {"$ne": None}}, {"section_end_point": {"$ne": None}}]}): point_start = section['section_start_point']['coordinates'] point_end = section['section_end_point']['coordinates'] if calDistance(startpoint, point_start) < 100 and calDistance(endpoint, point_end) < 100: sectionList.append(section['_id']) gmap.addpoint(point_end[1], point_end[0], COLOR[1]) gmap.addpoint(point_start[1], point_start[0], COLOR[1]) drawSection(section, option, gmap) gmap.draw('gmap_display/' + 'SearchResult' + str(start)[:10] + '-' + str(end)[:10] + '_' + user + '.html')
get_section_db().find_one({"_id": sid}) for sid in sectionIdList ] bounds = tauq.get_bounds(sectionJsonList) gmap = pygmaps.maps((bounds[0].lat + bounds[1].lat) / 2, (bounds[0].lon + bounds[1].lon) / 2, 10) drawSections(sectionJsonList, ALL, gmap, "random") gmap.draw(outPath) def drawSectionsSeparatelyFromId(sectionIdList, outPath): drawSectionsSeparately( [get_section_db().find_one({"_id": sid}) for sid in sectionIdList], outPath) def drawSectionsSeparately(sectionJSONList, outPath): try: os.mkdir(outPath) except OSError, e: logging.warn("Error %s while creating result directory" % e) pass for sectionJSON in sectionJSONList: print("Drawing section %s" % sectionJSON) sectionCenter = tauq.get_center_for_section(sectionJSON) gmap = pygmaps.maps(sectionCenter[0], sectionCenter[1], 10) drawSection(sectionJSON, ALL, gmap, "#000000") gmap.draw("%s/%s.html" % (outPath, sectionJSON["_id"]))
Given a user plot all the trips for that user """ sections = db.Stage_Sections.find({'user_id': user_uuid}) drawSections(sections, ALL, gmap) def drawSectionsFromList(sectionIdList, outPath): sectionJsonList = [get_section_db().find_one({"_id": sid}) for sid in sectionIdList] bounds = tauq.get_bounds(sectionJsonList) gmap = pygmaps.maps((bounds[0].lat + bounds[1].lat)/2, (bounds[0].lon + bounds[1].lon)/2, 10) drawSections(sectionJsonList, ALL, gmap, "random") gmap.draw(outPath) def drawSectionsSeparatelyFromId(sectionIdList, outPath): drawSectionsSeparately([get_section_db().find_one({"_id": sid}) for sid in sectionIdList], outPath) def drawSectionsSeparately(sectionJSONList, outPath): try: os.mkdir(outPath) except OSError, e: logging.warn("Error %s while creating result directory" % e) pass for sectionJSON in sectionJSONList: print ("Drawing section %s" % sectionJSON) sectionCenter = tauq.get_center_for_section(sectionJSON) gmap = pygmaps.maps(sectionCenter[0], sectionCenter[1], 10) drawSection(sectionJSON, ALL, gmap, "#000000") gmap.draw("%s/%s.html" % (outPath, sectionJSON["_id"]))