def main(): """ Artificially creating user, their responses and changing tables values """ database_path = os.path.join(os.getcwd(), "data.db") # create a code connection conn = create_connection(database_path) with conn: valid = False satire = False valid_articles, fake_artickles, satire_articles = partition_list( 101, 3) good_users, bad_users = partition_list(1001, 2) for id_news in range(1, 101): news_id = id_news if news_id in valid_articles: valid = True elif news_id in satire_articles: satire = True random_users = set() user_cnt = random.randint(50, 100) while len(random_users) < user_cnt: random_users.add(random.randint(1, 1000)) for random_usr, user in enumerate(random_users): news_column = get_news_columns(conn, news_id) id, title, url, rating, review_count, category = news_column[0] if valid: if user in good_users: given_score = random.uniform(8.0, 10.0) else: given_score = random.uniform(2.0, 7.0) elif satire: if user in good_users: given_score = random.uniform(5.0, 7.0) else: given_score = random.uniform(7.5, 8.0) else: if user in good_users: given_score = random.uniform(2.0, 7.0) else: given_score = random.uniform(5.0, 10.0) user_info = get_user_info(conn, user) user_id, first_name, last_name, email, user_rating, user_cnt = user_info[ 0] news_new_rating, old_rating, review_count = compute_news_user_score( rating, review_count, given_score, user_rating) update_news_info( conn, (review_count, round(news_new_rating, 3), id_news)) user_new_rating, user_cnt = compute_user_rating_iterative( given_score, user_rating, user_cnt, old_rating, review_count - 1) update_user_info( conn, (user_cnt, round(user_new_rating, 3), user_id))
def main_compute_user_rating(): """ Creating user's output and comparing it to expert_response :return: """ database_path = os.path.join(os.getcwd(), "data.db") # create a code connection conn = create_connection(database_path) with conn: users = get_users(conn) discount_factor_experience = 0.7 for i, user in enumerate(users): curr_diff = 0.0 beg = 1.0 end = 10.0 num_transactions = 100 for _ in range(num_transactions): tr_id = random.randint(1, 100) user_response = random.uniform(beg, end) expert_response = get_expert_transaction_id(conn, tr_id)[0][0] curr_diff += abs(expert_response - user_response) total_score = 9 * num_transactions user_rating = discount_factor_experience * ( 1 - (curr_diff / total_score)) update_user_rating(conn, (round(user_rating, 3), user[0]))
def main_create_experts(): database_path = os.path.join(os.getcwd(), "data.db") # create a code connection conn = create_connection(database_path) with conn: # create a new project for i in range(100): first_name = faker.first_name() last_name = faker.last_name() email = first_name + '_' + last_name + "@gmail.com" expert = (first_name, last_name, email) expert_id = create_expert(conn, expert)
def main_create_expert_transactions(): database_path = os.path.join(os.getcwd(), "data.db") # create a code connection conn = create_connection(database_path) with conn: # create a new project for i in range(200): expert_id = random.randint(1, 100) news_id = random.randint(1, 100) given_score = round(random.uniform(1.0, 10.0), 2) tr_expert = (expert_id, news_id, given_score) tr_expert_id = create_expert_transaction(conn, tr_expert)
def main_create_users(): database_path = os.path.join(os.getcwd(), "data.db") # create a code connection conn = create_connection(database_path) with conn: # create a new project for i in range(1000): first_name = faker.first_name() last_name = faker.last_name() email = first_name + '_' + last_name + "@gmail.com" rating = 0.0 review_count = 0 user = (first_name, last_name, email, rating, review_count) user_id = create_user(conn, user)