コード例 #1
0
def add_new_user():
    """ Add new user to database
    """
    rsdbc = RSDBConnection()
    user = raw_input("What's your name? ")
    user_id = rsdbc.add_user(user)
    while not user_id:
        user = raw_input(
            "This name isn't available. Choose another one: ")
        user_id = rsdbc.add_user(user)
    ratings = collect_user_ratings(rsdbc, user_id)
    rsdbc.insert_user_ratings(user_id, ratings)
    rsdbc.finalize()
コード例 #2
0
ファイル: eval.py プロジェクト: skorzewska/bg-recommender
    def recommend_fun(db_conn_conf, user_ids, group_name):
        ratings, num_players = get_users_ratings_dict(db_conn_conf, user_ids)

        db_conn = RSDBConnection(db_conn_conf)
        full_group_name = "group_" + merge_fun.__name__ + "_" + group_name
        group_user_id = db_conn.add_user(full_group_name)
        db_conn.finalize()

        merge_users(db_conn_conf, group_user_id, ratings, merge_fun)
        return gen_and_print_recommendation(db_conn_conf, full_group_name, num_players)
コード例 #3
0
def make_group_recommendation():
    """Display menu for choose of method of group recommendation.
        Call appropriate method of group recommendation.
        Merge multiple users to one user or merge individual recommendations into group one.
    """
    menu_rec = {}
    menu_rec['2'] = 'Merge users approach '
    menu_rec['1'] = 'Merge recommendations approach '
    menu_rec['0'] = 'Back '
    while(True):
        options = menu_rec.keys()
        options.sort()
        for entry in options:
            print entry, menu_rec[entry]
        selection = raw_input("Please select: ")
        if selection == '2':
            group_ratings, numplayers = create_dict_with_group_ratings()
            group_name = raw_input("Please provide a name for your group: ")

            rsdbc = RSDBConnection()
            user_id = rsdbc.add_user(group_name)
            # while not user_id:
            #     group_name = raw_input(
            #         "This name isn't available. Choose another one: ")
            #     user_id = rsdbc.add_user(group_name)
            rsdbc.finalize()

            menu_user_approach = {}
            menu_user_approach['0'] = 'Back'
            menu_user_approach['1'] = 'User Minimum strategy '
            menu_user_approach['2'] = 'User Maximum strategy '
            menu_user_approach['3'] = 'User Avg strategy '
            options2 = menu_user_approach.keys()
            options2.sort()
            for entry2 in options2:
                print entry2, menu_user_approach[entry2]
            selection2 = raw_input("Please select: ")
            if selection2 == '0':
                break
            elif selection2 == '1':
                merge_user_least_misery(user_id, group_ratings)
                generate_and_print_recommendation(group_name, numplayers)
            elif selection2 == '2':
                merge_user_max(user_id, group_ratings)
                generate_and_print_recommendation(group_name, numplayers)
            elif selection2 == '3':
                merge_user_avg(user_id, group_ratings)
                generate_and_print_recommendation(group_name, numplayers)
            else:
                print 'Wrong option!\n'
        elif selection == '0':
            break
        elif selection == '1':
            group_ratings, numplayers = create_dict_with_group_recommendations()
            menu_rec_approach = {}
            menu_rec_approach['0'] = 'Back'
            menu_rec_approach['1'] = 'Minimum strategy '
            menu_rec_approach['2'] = 'Maximum strategy '
            menu_rec_approach['3'] = 'Avg strategy '
            options3 = menu_rec_approach.keys()
            options3.sort()
            for entry3 in options3:
                print entry3, menu_rec_approach[entry3]
            selection3 = raw_input("Please select: ")
            if selection3 == '0':
                break
            elif selection3 == '1':
                merge_rec_least_misery(group_ratings)
            elif selection3 == '2':
                merge_rec_max(group_ratings)
            elif selection3 == '3':
                merge_rec_avg(group_ratings)
            else:
                print 'Wrong option!\n'
        else:
            print 'Wrong option!\n'