def test_get_similar_users(self): user_id_21 = db_user.create(21, "twenty_one") user_id_22 = db_user.create(22, "twenty_two") user_id_23 = db_user.create(23, "twenty_three") similar_users_21 = {"twenty_two": 0.4, "twenty_three": 0.7} similar_users_22 = {"twenty_one": 0.4} similar_users_23 = {"twenty_one": 0.7} similar_users = { "twenty_one": similar_users_21, "twenty_two": similar_users_22, "twenty_three": similar_users_23, } import_user_similarities(similar_users) self.assertDictEqual( similar_users_21, db_user.get_similar_users(user_id_21).similar_users) self.assertDictEqual( similar_users_22, db_user.get_similar_users(user_id_22).similar_users) self.assertDictEqual( similar_users_23, db_user.get_similar_users(user_id_23).similar_users)
def test_get_similar_users(self): user_id_21 = db_user.create(21, "twenty_one") user_id_22 = db_user.create(22, "twenty_two") user_id_23 = db_user.create(23, "twenty_three") similar_users_21 = { str(user_id_22): [0.4, .01], str(user_id_23): [0.7, 0.001] } similar_users_22 = {str(user_id_21): [0.4, .01]} similar_users_23 = {str(user_id_21): [0.7, .02]} similar_users = { str(user_id_21): similar_users_21, str(user_id_22): similar_users_22, str(user_id_23): similar_users_23, } import_user_similarities(similar_users) self.assertDictEqual( { "twenty_two": 0.4, "twenty_three": 0.7 }, db_user.get_similar_users(user_id_21).similar_users) self.assertDictEqual( {"twenty_one": 0.4}, db_user.get_similar_users(user_id_22).similar_users) self.assertDictEqual( {"twenty_one": 0.7}, db_user.get_similar_users(user_id_23).similar_users)
def handle_similar_users(message): """ Save the similar users data to the DB """ if current_app.config['TESTING']: return import_user_similarities(message['data'])
def handle_similar_users(message): """ Save the similar users data to the DB """ if current_app.config['TESTING']: return user_count, avg_similar_users, error = import_user_similarities( message['data']) if error: send_mail( subject='Similar User data failed to be calculated', text=render_template( 'emails/similar_users_failed_notification.txt', error=error), recipients=['*****@*****.**'], from_name='ListenBrainz', from_addr='noreply@' + current_app.config['MAIL_FROM_DOMAIN'], ) else: send_mail( subject='Similar User data has been calculated', text=render_template( 'emails/similar_users_updated_notification.txt', user_count=str(user_count), avg_similar_users="%.1f" % avg_similar_users), recipients=['*****@*****.**'], from_name='ListenBrainz', from_addr='noreply@' + current_app.config['MAIL_FROM_DOMAIN'], )