def get_user_ratings_for_game(): """Function for getting ratings of chosen game_name """ ratings = {} menu = {} menu['0'] = 'End.' menu['1'] = 'Add rating' user_name = raw_input("Give your username\n") rsdbc = RSDBConnection() user_id = rsdbc.get_user_id(user_name) rsdbc.finalize() while(True): options = menu.keys() options.sort() for entry in options: print entry, menu[entry] selection = raw_input("Please select: ") if selection == '0': return user_id, ratings elif selection == '1': game_name = raw_input("Please give the name of the game you want to rate: ") game_name = game_name.lower() game_name = '%' + game_name + '%' rsdbc = RSDBConnection() games = rsdbc.get_game_full_name(user_id, game_name) rsdbc.finalize() print("\nPlease rate the game you meant).\n" "If it's not the one you meant, just hit ENTER.\n" "If you want to quit, just write '-1' and ENTER\n") rating = 100 i = 0 while (rating != 0): if len(games) == 0: print 'Cannot find the game!\n' break rating = raw_input('"{}": '.format(games[i][1])) if rating: rating = float(rating) if rating< 1: rating = 1.0 elif rating > 10: rating= 10.0 ratings[games[i][0]] = rating if i +1 < len(games): i += 1 else: break else: print "Unknown option selected!\n"
def show_user_ratings(): """Show ratings for a given user """ rsdbc = RSDBConnection() user_name = raw_input("Please enter your username\n") user_id = rsdbc.get_user_id(user_name) ratings = rsdbc.get_user_ratings(user_id) print '\n\nrating\t\t game' for elem in ratings: game_name = rsdbc.get_game_name(elem[0]) print '{1}\t\t {0}'.format(game_name, elem[1]) print "\n\n" rsdbc.finalize()
def generate_individual_recommendation(user_name): """Generate recommendation for single user """ rec_file = open('recommendations/'+user_name, 'w+') rsdbc = RSDBConnection() user_id = rsdbc.get_user_id(user_name) data = download_data(rsdbc) recommender = build_recommender(data) print "Recommending items..." recommendation = recommender.recommend(user_id) #print "Recommendations:\nprob\tgame" for game_id, prob in recommendation: #game = rsdbc.get_game_name(game_id) #print '{:.3f}\t{}'.format(prob, game) rec_file.write('{};{}\n'.format(game_id, prob)) rsdbc.finalize() rec_file.close() return recommendation
def gen_individual_recommendation(db_conn_conf, user_name): """Generate recommendation for single user """ rec_file = open("recommendations/" + user_name, "w+") db_conn = RSDBConnection(db_conn_conf) user_id = db_conn.get_user_id(user_name) data = db_conn.get_data_for_rs() db_conn.finalize() recommender = build_recommender(data) print "Recommending items for user:"******"{};{}\n".format(game_id, prob)) rec_file.close() return recommendation
def create_dict_with_group_ratings(): """Function that creates a dict with user ratings from our group """ rsdbc = RSDBConnection() menu = {} menu['1'] = 'Add user to group' menu['0'] = 'End' user_ids = [] ratings = {} game_ratings = {} while(True): options = menu.keys() options.sort() for entry in options: print entry, menu[entry] selection = raw_input("Please select: ") if selection == '1': user_name = raw_input("Please give the user name of existing user: ") user_id = rsdbc.get_user_id(user_name) user_ids.append(user_id) elif selection == '0': break else: print 'Wrong option!\n' for user_id in user_ids: rating = rsdbc.get_user_ratings(user_id) ratings[user_id] = rating rsdbc.finalize() for user_id, game_dict in ratings.iteritems(): for game_id, rating in game_dict: if game_id in game_ratings: game_ratings[game_id] [user_id] = rating else: game_ratings[game_id] = {user_id:rating} return game_ratings, len(user_ids)