Exemple #1
0
    def test_rating_assignation(self):
        """Check ratings are correctly assigned to an exploration"""

        exp_services.save_new_exploration(
            self.EXP_ID,
            exp_domain.Exploration.create_default_exploration(
                self.EXP_ID, 'A title', 'A category'))

        self.assertEqual(
            rating_services.get_overall_ratings_for_exploration(self.EXP_ID), {
                '1': 0,
                '2': 0,
                '3': 0,
                '4': 0,
                '5': 0
            })

        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_1, self.EXP_ID), None)

        rating_services.assign_rating_to_exploration(self.USER_ID_1,
                                                     self.EXP_ID, 2)
        rating_services.assign_rating_to_exploration(self.USER_ID_2,
                                                     self.EXP_ID, 4)
        rating_services.assign_rating_to_exploration(self.USER_ID_1,
                                                     self.EXP_ID, 3)

        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_1, self.EXP_ID), 3)
        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_2, self.EXP_ID), 4)
        self.assertEqual(
            rating_services.get_overall_ratings_for_exploration(self.EXP_ID), {
                '1': 0,
                '2': 0,
                '3': 1,
                '4': 1,
                '5': 0
            })

        rating_services.assign_rating_to_exploration(self.USER_ID_1,
                                                     self.EXP_ID, 4)

        self.assertEqual(
            rating_services.get_overall_ratings_for_exploration(self.EXP_ID), {
                '1': 0,
                '2': 0,
                '3': 0,
                '4': 2,
                '5': 0
            })
Exemple #2
0
    def test_rating_assignations_do_not_conflict(self) -> None:
        """Check that ratings of different explorations are independent."""

        exp_id_a: Final = 'exp_id_A'
        exp_id_b: Final = 'exp_id_B'

        exp_services.save_new_exploration(  # type: ignore[no-untyped-call]
            exp_id_a,
            exp_domain.Exploration.create_default_exploration(
                exp_id_a))  # type: ignore[no-untyped-call]
        exp_services.save_new_exploration(  # type: ignore[no-untyped-call]
            exp_id_b,
            exp_domain.Exploration.create_default_exploration(
                exp_id_b))  # type: ignore[no-untyped-call]

        rating_services.assign_rating_to_exploration(self.USER_ID_1, exp_id_a,
                                                     1)
        rating_services.assign_rating_to_exploration(self.USER_ID_1, exp_id_b,
                                                     3)
        rating_services.assign_rating_to_exploration(self.USER_ID_2, exp_id_a,
                                                     2)
        rating_services.assign_rating_to_exploration(self.USER_ID_2, exp_id_b,
                                                     5)

        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_1, exp_id_a), 1)
        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_1, exp_id_b), 3)
        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_2, exp_id_a), 2)
        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_2, exp_id_b), 5)

        self.assertEqual(
            rating_services.get_overall_ratings_for_exploration(exp_id_a), {
                '1': 1,
                '2': 1,
                '3': 0,
                '4': 0,
                '5': 0
            })
        self.assertEqual(
            rating_services.get_overall_ratings_for_exploration(exp_id_b), {
                '1': 0,
                '2': 0,
                '3': 1,
                '4': 0,
                '5': 1
            })
Exemple #3
0
    def test_rating_assignations_do_not_conflict(self):
        """Check that ratings of different explorations are independant."""

        exp_id_a = 'exp_id_A'
        exp_id_b = 'exp_id_B'

        exp_services.save_new_exploration(
            exp_id_a,
            exp_domain.Exploration.create_default_exploration(
                exp_id_a, 'A title', 'A category'))
        exp_services.save_new_exploration(
            exp_id_b,
            exp_domain.Exploration.create_default_exploration(
                exp_id_b, 'A title', 'A category'))

        rating_services.assign_rating_to_exploration(self.USER_ID_1, exp_id_a,
                                                     1)
        rating_services.assign_rating_to_exploration(self.USER_ID_1, exp_id_b,
                                                     3)
        rating_services.assign_rating_to_exploration(self.USER_ID_2, exp_id_a,
                                                     2)
        rating_services.assign_rating_to_exploration(self.USER_ID_2, exp_id_b,
                                                     5)

        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_1, exp_id_a), 1)
        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_1, exp_id_b), 3)
        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_2, exp_id_a), 2)
        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_2, exp_id_b), 5)

        self.assertEqual(
            rating_services.get_overall_ratings_for_exploration(exp_id_a), {
                '1': 1,
                '2': 1,
                '3': 0,
                '4': 0,
                '5': 0
            })
        self.assertEqual(
            rating_services.get_overall_ratings_for_exploration(exp_id_b), {
                '1': 0,
                '2': 0,
                '3': 1,
                '4': 0,
                '5': 1
            })
Exemple #4
0
    def test_rating_assignations_do_not_conflict(self):
        """Check that ratings of different explorations are independant."""

        EXP_ID_A = 'exp_id_A'
        EXP_ID_B = 'exp_id_B'

        self.exploration = exp_domain.Exploration.create_default_exploration(
            EXP_ID_A, 'A title', 'A category')
        exp_services.save_new_exploration(EXP_ID_A, self.exploration)
        self.exploration = exp_domain.Exploration.create_default_exploration(
            EXP_ID_B, 'A title', 'A category')
        exp_services.save_new_exploration(EXP_ID_B, self.exploration)

        rating_services.assign_rating_to_exploration(self.USER_ID_1, EXP_ID_A,
                                                     1)
        rating_services.assign_rating_to_exploration(self.USER_ID_1, EXP_ID_B,
                                                     3)
        rating_services.assign_rating_to_exploration(self.USER_ID_2, EXP_ID_A,
                                                     2)
        rating_services.assign_rating_to_exploration(self.USER_ID_2, EXP_ID_B,
                                                     5)

        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_1, EXP_ID_A), 1)
        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_1, EXP_ID_B), 3)
        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_2, EXP_ID_A), 2)
        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_2, EXP_ID_B), 5)

        self.assertEqual(
            rating_services.get_overall_ratings_for_exploration(EXP_ID_A), {
                '1': 1,
                '2': 1,
                '3': 0,
                '4': 0,
                '5': 0
            })
        self.assertEqual(
            rating_services.get_overall_ratings_for_exploration(EXP_ID_B), {
                '1': 0,
                '2': 0,
                '3': 1,
                '4': 0,
                '5': 1
            })
    def test_rating_assignation(self):
        """Check ratings are correctly assigned to an exploration"""

        exp_services.save_new_exploration(
            self.EXP_ID,
            exp_domain.Exploration.create_default_exploration(self.EXP_ID))

        self.assertEqual(
            rating_services.get_overall_ratings_for_exploration(self.EXP_ID),
            {'1': 0, '2': 0, '3': 0, '4': 0, '5': 0})

        exp_summary = exp_services.get_exploration_summary_by_id(self.EXP_ID)
        self.assertEqual(
            exp_summary.scaled_average_rating, 0)

        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_1, self.EXP_ID), None)

        rating_services.assign_rating_to_exploration(
            self.USER_ID_1, self.EXP_ID, 2)
        rating_services.assign_rating_to_exploration(
            self.USER_ID_2, self.EXP_ID, 4)
        rating_services.assign_rating_to_exploration(
            self.USER_ID_1, self.EXP_ID, 3)

        exp_summary = exp_services.get_exploration_summary_by_id(self.EXP_ID)
        self.assertAlmostEqual(
            exp_summary.scaled_average_rating, 1.5667471839848, places=4)

        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_1, self.EXP_ID), 3)
        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_2, self.EXP_ID), 4)
        self.assertEqual(
            rating_services.get_overall_ratings_for_exploration(self.EXP_ID),
            {'1': 0, '2': 0, '3': 1, '4': 1, '5': 0})

        rating_services.assign_rating_to_exploration(
            self.USER_ID_1, self.EXP_ID, 4)

        self.assertEqual(
            rating_services.get_overall_ratings_for_exploration(self.EXP_ID),
            {'1': 0, '2': 0, '3': 0, '4': 2, '5': 0})
Exemple #6
0
    def test_rating_assignation(self):
        """Check ratings are correctly assigned to an exploration."""

        exp_services.save_new_exploration(
            self.EXP_ID,
            exp_domain.Exploration.create_default_exploration(self.EXP_ID))

        self.assertEqual(
            rating_services.get_overall_ratings_for_exploration(self.EXP_ID),
            {'1': 0, '2': 0, '3': 0, '4': 0, '5': 0})

        exp_summary = exp_services.get_exploration_summary_by_id(self.EXP_ID)
        self.assertEqual(
            exp_summary.scaled_average_rating, 0)

        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_1, self.EXP_ID), None)

        rating_services.assign_rating_to_exploration(
            self.USER_ID_1, self.EXP_ID, 2)
        rating_services.assign_rating_to_exploration(
            self.USER_ID_2, self.EXP_ID, 4)
        rating_services.assign_rating_to_exploration(
            self.USER_ID_1, self.EXP_ID, 3)

        exp_summary = exp_services.get_exploration_summary_by_id(self.EXP_ID)
        self.assertAlmostEqual(
            exp_summary.scaled_average_rating, 1.5667471839848, places=4)

        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_1, self.EXP_ID), 3)
        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_2, self.EXP_ID), 4)
        self.assertEqual(
            rating_services.get_overall_ratings_for_exploration(self.EXP_ID),
            {'1': 0, '2': 0, '3': 1, '4': 1, '5': 0})

        rating_services.assign_rating_to_exploration(
            self.USER_ID_1, self.EXP_ID, 4)

        self.assertEqual(
            rating_services.get_overall_ratings_for_exploration(self.EXP_ID),
            {'1': 0, '2': 0, '3': 0, '4': 2, '5': 0})
    def test_rating_assignations_do_not_conflict(self):
        """Check that ratings of different explorations are independant."""

        exp_id_a = 'exp_id_A'
        exp_id_b = 'exp_id_B'

        exp_services.save_new_exploration(
            exp_id_a,
            exp_domain.Exploration.create_default_exploration(
                exp_id_a, 'A title', 'A category'))
        exp_services.save_new_exploration(
            exp_id_b,
            exp_domain.Exploration.create_default_exploration(
                exp_id_b, 'A title', 'A category'))

        rating_services.assign_rating_to_exploration(
            self.USER_ID_1, exp_id_a, 1)
        rating_services.assign_rating_to_exploration(
            self.USER_ID_1, exp_id_b, 3)
        rating_services.assign_rating_to_exploration(
            self.USER_ID_2, exp_id_a, 2)
        rating_services.assign_rating_to_exploration(
            self.USER_ID_2, exp_id_b, 5)

        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_1, exp_id_a), 1)
        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_1, exp_id_b), 3)
        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_2, exp_id_a), 2)
        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_2, exp_id_b), 5)

        self.assertEqual(
            rating_services.get_overall_ratings_for_exploration(exp_id_a),
            {'1': 1, '2': 1, '3': 0, '4': 0, '5': 0})
        self.assertEqual(
            rating_services.get_overall_ratings_for_exploration(exp_id_b),
            {'1': 0, '2': 0, '3': 1, '4': 0, '5': 1})
Exemple #8
0
 def get(self, exploration_id):
     """Handles GET requests."""
     self.values.update({
         'overall_ratings':
             rating_services.get_overall_ratings_for_exploration(
                 exploration_id),
         'user_rating': (
             rating_services.get_user_specific_rating_for_exploration(
                 self.user_id, exploration_id) if self.user_id else None)
     })
     self.render_json(self.values)
Exemple #9
0
 def get(self, exploration_id):
     """Handles GET requests."""
     self.values.update({
         'overall_ratings':
             rating_services.get_overall_ratings_for_exploration(
                 exploration_id),
         'user_rating': (
             rating_services.get_user_specific_rating_for_exploration(
                 self.user_id, exploration_id) if self.user_id else None)
     })
     self.render_json(self.values)
    def test_rating_assignations_do_not_conflict(self):
        """Check that ratings of different explorations are independant."""

        EXP_ID_A = 'exp_id_A'
        EXP_ID_B = 'exp_id_B'

        self.exploration = exp_domain.Exploration.create_default_exploration(
            EXP_ID_A, 'A title', 'A category')
        exp_services.save_new_exploration(EXP_ID_A, self.exploration)
        self.exploration = exp_domain.Exploration.create_default_exploration(
            EXP_ID_B, 'A title', 'A category')
        exp_services.save_new_exploration(EXP_ID_B, self.exploration)

        rating_services.assign_rating_to_exploration(
            self.USER_ID_1, EXP_ID_A, 1)
        rating_services.assign_rating_to_exploration(
            self.USER_ID_1, EXP_ID_B, 3)
        rating_services.assign_rating_to_exploration(
            self.USER_ID_2, EXP_ID_A, 2)
        rating_services.assign_rating_to_exploration(
            self.USER_ID_2, EXP_ID_B, 5)

        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_1, EXP_ID_A), 1)
        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_1, EXP_ID_B), 3)
        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_2, EXP_ID_A), 2)
        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_2, EXP_ID_B), 5)

        self.assertEqual(
            rating_services.get_overall_ratings_for_exploration(EXP_ID_A),
            {'1': 1, '2': 1, '3': 0, '4': 0, '5': 0})
        self.assertEqual(
            rating_services.get_overall_ratings_for_exploration(EXP_ID_B),
            {'1': 0, '2': 0, '3': 1, '4': 0, '5': 1})
    def test_rating_assignation(self):
        """Check ratings are correctly assigned to an exploration"""

        exp_services.save_new_exploration(
            self.EXP_ID,
            exp_domain.Exploration.create_default_exploration(
                self.EXP_ID, 'A title', 'A category'))

        self.assertEqual(
            rating_services.get_overall_ratings_for_exploration(self.EXP_ID),
            {'1': 0, '2': 0, '3': 0, '4': 0, '5': 0})

        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_1, self.EXP_ID), None)

        rating_services.assign_rating_to_exploration(
            self.USER_ID_1, self.EXP_ID, 2)
        rating_services.assign_rating_to_exploration(
            self.USER_ID_2, self.EXP_ID, 4)
        rating_services.assign_rating_to_exploration(
            self.USER_ID_1, self.EXP_ID, 3)

        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_1, self.EXP_ID), 3)
        self.assertEqual(
            rating_services.get_user_specific_rating_for_exploration(
                self.USER_ID_2, self.EXP_ID), 4)
        self.assertEqual(
            rating_services.get_overall_ratings_for_exploration(self.EXP_ID),
            {'1': 0, '2': 0, '3': 1, '4': 1, '5': 0})

        rating_services.assign_rating_to_exploration(
            self.USER_ID_1, self.EXP_ID, 4)

        self.assertEqual(
            rating_services.get_overall_ratings_for_exploration(self.EXP_ID),
            {'1': 0, '2': 0, '3': 0, '4': 2, '5': 0})
    def _get_exp_impact_score(cls, exploration_id):
        # Get ratings and compute average rating score.
        rating_frequencies = (
            rating_services.get_overall_ratings_for_exploration(
                exploration_id))
        total_num_ratings = 0
        total_rating = 0.0
        for rating, num_ratings in rating_frequencies.iteritems():
            total_rating += (int(rating) * num_ratings)
            total_num_ratings += num_ratings
        # Only divide by a non-zero number.
        if total_num_ratings == 0:
            return 0
        average_rating = total_rating / total_num_ratings

        # Get rating term to use in impact calculation.
        rating_term = average_rating - cls.MIN_AVERAGE_RATING
        # Only explorations with an average rating greater than the minimum
        # have an impact.
        if rating_term <= 0:
            return 0

        # Get num_ratings_scaler.
        if total_num_ratings < cls.NUM_RATINGS_SCALER_CUTOFF:
            num_ratings_scaler = cls.NUM_RATINGS_SCALER * total_num_ratings
        else:
            num_ratings_scaler = 1.0

        # Get number of completions/playthroughs.
        num_completions = (
            stats_jobs_continuous.StatisticsAggregator.get_statistics(
                exploration_id, stats_jobs_continuous.VERSION_ALL)[
                    'complete_exploration_count'])
        # Only take the log of a non-zero number.
        if num_completions <= 0:
            return 0
        num_completions_term = math.log(num_completions)

        exploration_impact_score = (
            rating_term *
            num_completions_term *
            num_ratings_scaler *
            cls.MULTIPLIER
        )

        return exploration_impact_score
Exemple #13
0
    def _get_exp_impact_score(cls, exploration_id):
        # Get ratings and compute average rating score.
        rating_frequencies = rating_services.get_overall_ratings_for_exploration(
            exploration_id)
        total_num_ratings = 0
        total_rating = 0.0
        for rating, num_ratings in rating_frequencies.iteritems():
            total_rating += (int(rating) * num_ratings)
            total_num_ratings += num_ratings
        # Only divide by a non-zero number.
        if total_num_ratings == 0:
            return 0
        average_rating = total_rating / total_num_ratings

        # Get rating term to use in impact calculation.
        rating_term = average_rating - cls.MIN_AVERAGE_RATING
        # Only explorations with an average rating greater than the minimum
        # have an impact.
        if rating_term <= 0:
            return 0

        # Get num_ratings_scaler.
        if total_num_ratings < cls.NUM_RATINGS_SCALER_CUTOFF:
            num_ratings_scaler = cls.NUM_RATINGS_SCALER * total_num_ratings
        else:
            num_ratings_scaler = 1.0

        # Get number of completions/playthroughs.
        num_completions = stats_jobs_continuous.StatisticsAggregator.get_statistics(
            exploration_id,
            stats_jobs_continuous.VERSION_ALL)['complete_exploration_count']
        # Only take the log of a non-zero number.
        if num_completions <= 0:
            return 0
        num_completions_term = math.log(num_completions)

        exploration_impact_score = (
            rating_term *
            num_completions_term *
            num_ratings_scaler *
            cls.MULTIPLIER
        )

        return exploration_impact_score