Beispiel #1
0
def get_completed_collection_summaries(user_id):
    """Returns a list of summaries of the completed collection ids, the
    number of collections deleted from the list as they are no longer present
    and the number of collections being shifted to the incomplete section on
    account of new addition of explorations.

    Args:
        user_id: str. The id of the learner.

    Returns:
        list(CollectionSummary). A list with the summary domain objects of the
            completed collections.
        int. The number of explorations deleted from the list as they are no
            longer present.
        int. The number of collections moved to the incomplete section on
            account of new explorations being added to them.
    """
    completed_collection_ids = get_all_completed_collection_ids(user_id)

    number_deleted = 0
    completed_to_incomplete_collections = []
    for collection_id in completed_collection_ids:
        if not collection_services.does_collection_exists(collection_id):
            number_deleted = number_deleted + 1
            remove_collection_from_completed_list(user_id, collection_id)
        elif collection_services.get_next_exploration_ids_to_complete_by_user(
                user_id, collection_id):
            remove_collection_from_completed_list(user_id, collection_id)
            mark_collection_as_incomplete(user_id, collection_id)
            completed_to_incomplete_collections.append(
                collection_services.get_collection_titles_and_categories(
                    [collection_id])[collection_id]['title'])

    return collection_services.get_collection_summaries_matching_ids(
        completed_collection_ids), number_deleted, completed_to_incomplete_collections  # pylint: disable=line-too-long
Beispiel #2
0
    def get(self, exploration_id):
        """Handles GET requests."""
        collection_id = self.request.get('collection_id')
        include_system_recommendations = self.request.get(
            'include_system_recommendations')
        try:
            author_recommended_exp_ids = json.loads(self.request.get(
                'stringified_author_recommended_ids'))
        except Exception:
            raise self.PageNotFoundException

        auto_recommended_exp_ids = []
        if self.user_id and collection_id:
            next_exp_ids_in_collection = (
                collection_services.get_next_exploration_ids_to_complete_by_user( # pylint: disable=line-too-long
                    self.user_id, collection_id))
            auto_recommended_exp_ids = list(
                set(next_exp_ids_in_collection) -
                set(author_recommended_exp_ids))
        else:
            next_exp_ids_in_collection = []
            if collection_id:
                collection = collection_services.get_collection_by_id(
                    collection_id)
                next_exp_ids_in_collection = (
                    collection.get_next_exploration_ids_in_sequence(
                        exploration_id))
            if next_exp_ids_in_collection:
                auto_recommended_exp_ids = list(
                    set(next_exp_ids_in_collection) -
                    set(author_recommended_exp_ids))
            elif include_system_recommendations:
                system_chosen_exp_ids = (
                    recommendations_services.get_exploration_recommendations(
                        exploration_id))
                filtered_exp_ids = list(
                    set(system_chosen_exp_ids) -
                    set(author_recommended_exp_ids))
                auto_recommended_exp_ids = random.sample(
                    filtered_exp_ids,
                    min(MAX_SYSTEM_RECOMMENDATIONS, len(filtered_exp_ids)))

        self.values.update({
            'summaries': (
                summary_services.get_displayable_exp_summary_dicts_matching_ids(
                    author_recommended_exp_ids + auto_recommended_exp_ids)),
        })
        self.render_json(self.values)
Beispiel #3
0
    def get(self, exploration_id):
        """Handles GET requests."""
        collection_id = self.request.get('collection_id')
        include_system_recommendations = self.request.get(
            'include_system_recommendations')
        try:
            author_recommended_exp_ids = json.loads(self.request.get(
                'stringified_author_recommended_ids'))
        except Exception:
            raise self.PageNotFoundException

        auto_recommended_exp_ids = []
        if self.user_id and collection_id:
            next_exp_ids_in_collection = (
                collection_services.get_next_exploration_ids_to_complete_by_user(  # pylint: disable=line-too-long
                    self.user_id, collection_id))
            auto_recommended_exp_ids = list(
                set(next_exp_ids_in_collection) -
                set(author_recommended_exp_ids))
        else:
            next_exp_ids_in_collection = []
            if collection_id:
                collection = collection_services.get_collection_by_id(
                    collection_id)
                next_exp_ids_in_collection = (
                    collection.get_next_exploration_ids_in_sequence(
                        exploration_id))
            if next_exp_ids_in_collection:
                auto_recommended_exp_ids = list(
                    set(next_exp_ids_in_collection) -
                    set(author_recommended_exp_ids))
            elif include_system_recommendations:
                system_chosen_exp_ids = (
                    recommendations_services.get_exploration_recommendations(
                        exploration_id))
                filtered_exp_ids = list(
                    set(system_chosen_exp_ids) -
                    set(author_recommended_exp_ids))
                auto_recommended_exp_ids = random.sample(
                    filtered_exp_ids,
                    min(MAX_SYSTEM_RECOMMENDATIONS, len(filtered_exp_ids)))

        self.values.update({
            'summaries': (
                summary_services.get_displayable_exp_summary_dicts_matching_ids(
                    author_recommended_exp_ids + auto_recommended_exp_ids)),
        })
        self.render_json(self.values)
Beispiel #4
0
    def get(self, exploration_id):
        """Handles GET requests."""
        collection_id = self.request.get('collection_id')

        recommended_exp_ids = []
        if self.user_id and collection_id:
            recommended_exp_ids = (
                collection_services.get_next_exploration_ids_to_complete_by_user(
                    self.user_id, collection_id))
        else:
            recommended_exp_ids = (
                recommendations_services.get_exploration_recommendations(
                    exploration_id))

        self.values.update({
            'recommended_exp_ids': recommended_exp_ids
        })
        self.render_json(self.values)
Beispiel #5
0
    def post(self, exploration_id):
        """Handles POST requests.

        Args:
            exploration_id: str. The ID of the exploration.
        """

        # This will be None if the exploration is not being played within the
        # context of a collection.
        collection_id = self.payload.get('collection_id')
        user_id = self.user_id

        event_services.CompleteExplorationEventHandler.record(
            exploration_id,
            self.payload.get('version'),
            self.payload.get('state_name'),
            self.payload.get('session_id'),
            self.payload.get('client_time_spent_in_secs'),
            self.payload.get('params'),
            feconf.PLAY_TYPE_NORMAL)

        if user_id:
            learner_progress_services.mark_exploration_as_completed(
                user_id, exploration_id)

        if user_id and collection_id:
            collection_services.record_played_exploration_in_collection_context(
                user_id, collection_id, exploration_id)
            collections_left_to_complete = (
                collection_services.get_next_exploration_ids_to_complete_by_user( # pylint: disable=line-too-long
                    user_id, collection_id))

            if not collections_left_to_complete:
                learner_progress_services.mark_collection_as_completed(
                    user_id, collection_id)
            else:
                learner_progress_services.mark_collection_as_incomplete(
                    user_id, collection_id)

        self.render_json(self.values)