Beispiel #1
0
    def test_get_multi_stats_models(self) -> None:
        stats_models.ExplorationStatsModel.create('exp_id1', 1, 0, 0, 0, 0, 0,
                                                  0, {})
        stats_models.ExplorationStatsModel.create('exp_id1', 2, 0, 0, 0, 0, 0,
                                                  0, {})
        stats_models.ExplorationStatsModel.create('exp_id2', 1, 0, 0, 0, 0, 0,
                                                  0, {})

        exp_version_reference_dicts = [
            exp_domain.ExpVersionReference('exp_id1',
                                           1),  # type: ignore[no-untyped-call]
            exp_domain.ExpVersionReference('exp_id1',
                                           2),  # type: ignore[no-untyped-call]
            exp_domain.ExpVersionReference('exp_id2', 1)
        ]  # type: ignore[no-untyped-call]

        stat_models = stats_models.ExplorationStatsModel.get_multi_stats_models(
            exp_version_reference_dicts)

        # Ruling out the possibility of None for mypy type checking.
        assert stat_models[0] is not None
        assert stat_models[1] is not None
        assert stat_models[2] is not None
        self.assertEqual(len(stat_models), 3)
        self.assertEqual(stat_models[0].exp_id, 'exp_id1')
        self.assertEqual(stat_models[0].exp_version, 1)
        self.assertEqual(stat_models[1].exp_id, 'exp_id1')
        self.assertEqual(stat_models[1].exp_version, 2)
        self.assertEqual(stat_models[2].exp_id, 'exp_id2')
        self.assertEqual(stat_models[2].exp_version, 1)
Beispiel #2
0
    def test_get_multi_stats_models(self):
        stats_models.ExplorationStatsModel.create(
            'exp_id1', 1, 0, 0, 0, 0, 0, 0, {})
        stats_models.ExplorationStatsModel.create(
            'exp_id1', 2, 0, 0, 0, 0, 0, 0, {})
        stats_models.ExplorationStatsModel.create(
            'exp_id2', 1, 0, 0, 0, 0, 0, 0, {})

        exp_version_reference_dicts = [
            exp_domain.ExpVersionReference('exp_id1', 1),
            exp_domain.ExpVersionReference('exp_id1', 2),
            exp_domain.ExpVersionReference('exp_id2', 1)]

        stat_models = stats_models.ExplorationStatsModel.get_multi_stats_models(
            exp_version_reference_dicts)

        self.assertEqual(len(stat_models), 3)
        self.assertEqual(stat_models[0].exp_id, 'exp_id1')
        self.assertEqual(stat_models[0].exp_version, 1)
        self.assertEqual(stat_models[1].exp_id, 'exp_id1')
        self.assertEqual(stat_models[1].exp_version, 2)
        self.assertEqual(stat_models[2].exp_id, 'exp_id2')
        self.assertEqual(stat_models[2].exp_version, 1)
Beispiel #3
0
def get_displayable_exp_summary_dicts(exploration_summaries):
    """Gets a summary of explorations in human readable form.

    Given a list of exploration summary domain objects, returns a list,
    with the same number of elements, of the corresponding human-readable
    exploration summary dicts.
    This assumes that all the exploration summary domain objects passed in are
    valid (i.e., none of them are None).

    Args:
        exploration_summaries: list(ExplorationSummary). List of exploration
            summary objects.

    Returns:
        list(dict). A list of exploration summary dicts in human readable form.
        Example:

        [ {
            'category': u'A category',
            'community_owned': False,
            'id': 'eid2',
            'language_code': 'en',
            'num_views': 0,
            'objective': u'An objective',
            'status': 'public',
            'tags': [],
            'thumbnail_bg_color': '#a33f40',
            'thumbnail_icon_url': self.get_static_asset_url(
                '/images/subjects/Lightbulb.svg'),
            'title': u'Exploration 2 Albert title',
        }, ]
    """
    exp_version_references = [
        exp_domain.ExpVersionReference(exp_summary.id, exp_summary.version)
        for exp_summary in exploration_summaries
    ]
    exp_stats_list = stats_services.get_exploration_stats_multi(
        exp_version_references)
    view_counts = [exp_stats.num_starts for exp_stats in exp_stats_list]

    displayable_exp_summaries = []

    for ind, exploration_summary in enumerate(exploration_summaries):
        if exploration_summary:
            summary_dict = {
                'id':
                exploration_summary.id,
                'title':
                exploration_summary.title,
                'activity_type':
                constants.ACTIVITY_TYPE_EXPLORATION,
                'category':
                exploration_summary.category,
                'created_on_msec':
                utils.get_time_in_millisecs(
                    exploration_summary.exploration_model_created_on),
                'objective':
                exploration_summary.objective,
                'language_code':
                exploration_summary.language_code,
                'last_updated_msec':
                utils.get_time_in_millisecs(
                    exploration_summary.exploration_model_last_updated),
                'human_readable_contributors_summary':
                (get_human_readable_contributors_summary(
                    exploration_summary.contributors_summary)),
                'status':
                exploration_summary.status,
                'ratings':
                exploration_summary.ratings,
                'community_owned':
                exploration_summary.community_owned,
                'tags':
                exploration_summary.tags,
                'thumbnail_icon_url':
                utils.get_thumbnail_icon_url_for_category(
                    exploration_summary.category),
                'thumbnail_bg_color':
                utils.get_hex_color_for_category(exploration_summary.category),
                'num_views':
                view_counts[ind],
            }

            displayable_exp_summaries.append(summary_dict)

    return displayable_exp_summaries