def Item_based(): user_id=session['user_id'][0] productData = functions.flipPersonToPlaces(reviewdata1.reviews) print "Finding similar Places " # for single place similar_item=functions.mostSimilar(productData,"4iTRjN_uAdAb7_YZDVHJdg") print dict(similar_item) b_data=[] for bid in dict(similar_item).keys(): sql = ("SELECT B_NAME, PHOTO_URL,RATING from BUSINESS_CA where B_ID = '%s'" % bid) cursor.execute(sql) data = cursor.fetchone() if data != None: b_data.append([data[0],data[1],data[2]]) print b_data print "******************" print "Computing Item Similarity" # for entire product data itemSimilarity = functions.computeItemSimilarities(productData) print itemSimilarity print "******************" print "Item Based Filtering for Recommendations" recommendedplc_ib=functions.itemBasedFiltering(reviewdata1.reviews,str(user_id),itemSimilarity) print recommendedplc_ib.keys() #send to shivani locations =[] for bid in recommendedplc_ib.keys(): sql = ("SELECT B_NAME, LATITUDE, LONGITUDE, ADDRESS, RATING from BUSINESS_CA where B_ID = '%s'" % bid) cursor.execute(sql) data_map = cursor.fetchone() if data_map!=None: value=[str(data_map[0]),float(data_map[1]),float(data_map[2]),str(data_map[3]),data_map[4]] locations.append(value) print "locations is" print locations return render_template('ItemRecommend.html',location=locations,similarplaces=b_data)
def user_based(): user_id=session['user_id'][0] print "Most similar reviewers/Users " similar_user=functions.mostSimilar(reviewdata1.reviews,str(user_id)) #similar_user=functions.mostSimilar(reviewdata.reviews,"T9hGHsbJW9Hw1cJAlIAWmw") u_data = [] print dict(similar_user).keys() print "###########" for uid in dict(similar_user).keys(): sql = ("SELECT USER_NAME from USER where USER_ID = '%s'" % uid) cursor.execute(sql) data = cursor.fetchone() if data != None: rating= random.randint(3,5) u_data.append([data[0],rating]) print "U_DATA" print u_data print "###########" print "Place Recommendations for a user" recommendplc_ub=functions.getRecommendations(reviewdata1.reviews,str(user_id)) #how much will one user like a particular place print "************" locations =[] for bid in recommendplc_ub.keys(): sql = ("SELECT B_NAME, LATITUDE, LONGITUDE, ADDRESS, RATING from BUSINESS_CA where B_ID = '%s'" % bid) cursor.execute(sql) data_map = cursor.fetchone() if data_map!=None: value=[str(data_map[0]),float(data_map[1]),float(data_map[2]),str(data_map[3]),data_map[4]] locations.append(value) return render_template('UserRecommend.html', location=locations,similarusers=u_data)