def main(): db = mdb.connect(user="******",host="localhost",passwd="konnichiwa1",db="foodgrouper") query = 'Select * from foodgrouper.CityPopulation;' df = psql.frame_query(query, db) cur = db.cursor() for i in range(157,len(df[['latitude','longitude']])): latlong = df[['latitude','longitude']][i-1:i] clusters,data,c_info = foodgroups.foodGroups(latlong['latitude'][i-1],latlong['longitude'][i-1]) cluster_results = pd.DataFrame() cluster_results['labels'] = clusters['labels'] cluster_results['core_samples_mask'] = clusters['core_samples_mask'] cluster_results['eps'] = clusters['eps'] insert_request = "INSERT INTO foodgrouper.requests(latitude,longitude,City,State) VALUES (%f, %f, '%s', '%s');"%(latlong['latitude'][i-1] ,latlong['longitude'][i-1],df['City'][i-1:i][i-1],df['State'][i-1:i][i-1]) print "Writing city %i: %s, %s data to DB."%(i,df['City'][i-1:i][i-1],df['State'][i-1:i][i-1]) a = Thread(target=noInterrupt, args=(db,cur,insert_request,data,c_info,cluster_results)) a.start() a.join() time.sleep(randint(1,3)) cur.close() con.close()
def food_groups_page(): user_location = request.args.get("origin") lat,lon,full_add,data = maps.geocode(user_location) clusters = foodgroups.foodGroups(lat,lon) restaurants = [] for i in range(len(clusters['X'])): restaurants.append(dict(lat=clusters['X'][i][0], long=clusters['X'][i][1], clusterid=clusters['labels'][i])) return render_template('results.html',results=restaurants,user_lat = lat, user_long = lon, faddress = full_add, ncluster = clusters['n_clusters'])
def food_groups_page(): user_location = request.args.get("origin") lat, lon, full_add, data = maps.geocode(user_location) clusters = foodgroups.foodGroups(lat, lon) restaurants = [] for i in range(len(clusters['X'])): restaurants.append( dict(lat=clusters['X'][i][0], long=clusters['X'][i][1], clusterid=clusters['labels'][i])) return render_template('results.html', results=restaurants, user_lat=lat, user_long=lon, faddress=full_add, ncluster=clusters['n_clusters'])
def food_groups_page(): try: user_location = request.args.get("origin") if len(user_location) == 0: return render_template('oops.html') lat,lon,full_add,data = maps.geocode(user_location) sortkey = int(request.args.get("keychain")) clusters,restdata, cluster_info = foodgroups.foodGroups(lat,lon,key = sortkey,cache=True) restaurants = [] for ix,a in restdata.iterrows(): thisdat = a restaurants.append(dict(lat=thisdat['latitude'] ,long=thisdat['longitude'] ,clusterid=thisdat['ranking'] ,url=thisdat['url'] ,name=thisdat['name'] ,pic=thisdat['photo'] )) return render_template('results3.html',results=restaurants,c_info = cluster_info, user_lat = lat, user_long = lon, faddress = full_add, ncluster = clusters['n_clusters']) except: # Well something went wrong in here return render_template('oops.html')