def setUp(self): super(ExplorationRecommendationsModelValidatorTests, self).setUp() self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME) self.user_id = self.get_user_id_from_email(self.OWNER_EMAIL) explorations = [ exp_domain.Exploration.create_default_exploration( '%s' % i, title='title %d' % i, category='category%d' % i, ) for i in python_utils.RANGE(6) ] for exp in explorations: exp_services.save_new_exploration(self.user_id, exp) recommendations_services.set_exploration_recommendations( '0', ['3', '4']) recommendations_services.set_exploration_recommendations('1', ['5']) self.model_instance_0 = ( recommendations_models.ExplorationRecommendationsModel.get_by_id( '0')) self.model_instance_1 = ( recommendations_models.ExplorationRecommendationsModel.get_by_id( '1')) self.job_class = (prod_validation_jobs_one_off. ExplorationRecommendationsModelAuditOneOffJob)
def reduce(key, stringified_values): other_exploration_similarities = sorted( [ast.literal_eval(v) for v in stringified_values], reverse=True, key=lambda x: x['similarity_score']) recommended_exploration_ids = [ item['exp_id'] for item in other_exploration_similarities[:MAX_RECOMMENDATIONS]] recommendations_services.set_exploration_recommendations( key, recommended_exploration_ids)
def test_get_and_set_exploration_recommendations(self): recommended_exp_ids = ['exp_id_2', 'exp_id_3'] recommendations_services.set_exploration_recommendations( 'exp_id_1', recommended_exp_ids) saved_recommendation_ids = ( recommendations_services.get_exploration_recommendations( 'exp_id_1')) self.assertEqual(recommended_exp_ids, saved_recommendation_ids) recommended_exp_ids = ['exp_id_3'] recommendations_services.set_exploration_recommendations( 'exp_id_1', recommended_exp_ids) saved_recommendation_ids = ( recommendations_services.get_exploration_recommendations( 'exp_id_1')) self.assertEqual(recommended_exp_ids, saved_recommendation_ids)
def test_delete_exploration_from_recommendations(self): recommendations_services.set_exploration_recommendations( 'exp_id_1', ['exp_id_3', 'exp_id_4']) recommendations_services.set_exploration_recommendations( 'exp_id_2', ['exp_id_1', 'exp_id_3', 'exp_id_4']) recommendations_services.delete_explorations_from_recommendations( ['exp_id_3', 'exp_id_4']) recommendations_1 = ( recommendations_models.ExplorationRecommendationsModel.get_by_id( 'exp_id_1')) recommendations_2 = ( recommendations_models.ExplorationRecommendationsModel.get_by_id( 'exp_id_2')) self.assertEqual([], recommendations_1.recommended_exploration_ids) self.assertEqual(['exp_id_1'], recommendations_2.recommended_exploration_ids)
def setUp(self): super(CleanUpExplorationRecommendationsOneOffJob, self).setUp() self.signup('user@email', 'user') self.user_id = self.get_user_id_from_email('user@email') explorations = [exp_domain.Exploration.create_default_exploration( '%s' % i, title='title %d' % i, category='category%d' % i, ) for i in python_utils.RANGE(4)] for exp in explorations: exp_services.save_new_exploration(self.user_id, exp) recommendations_services.set_exploration_recommendations( '0', ['1', '2'])