예제 #1
0
    def get_thread_analytics_multi(cls, exploration_ids):
        """Gets the thread analytics for the explorations specified by the
        exploration_ids.

        Args:
            exploration_ids: list(str). IDs of the explorations to get
            analytics for.

        Returns:
            list(dict). Each dict in this list corresponds to an
            exploration ID in the input list, and has two keys:
            - num_open_threads: int. The count of open feedback threads
              for this exploration.
            - num_total_threads: int. The count of all feedback threads
              for this exploration.
        """
        realtime_model_ids = cls.get_multi_active_realtime_layer_ids(
            exploration_ids)
        realtime_models = cls._get_realtime_datastore_class().get_multi(
            realtime_model_ids)
        feedback_thread_analytics_models = (
            feedback_models.FeedbackAnalyticsModel.get_multi(
                exploration_ids))

        return [feedback_domain.FeedbackAnalytics(
            exploration_ids[i],
            (realtime_models[i].num_open_threads
             if realtime_models[i] is not None else 0) +
            (feedback_thread_analytics_models[i].num_open_threads
             if feedback_thread_analytics_models[i] is not None else 0),
            (realtime_models[i].num_total_threads
             if realtime_models[i] is not None else 0) +
            (feedback_thread_analytics_models[i].num_total_threads
             if feedback_thread_analytics_models[i] is not None else 0)
        ) for i in range(len(exploration_ids))]
예제 #2
0
 def test_to_dict(self) -> None:
     expected_thread_analytics = feedback_domain.FeedbackAnalytics(
         feconf.ENTITY_TYPE_EXPLORATION, self.EXP_ID, 1, 2)
     self.assertDictEqual(expected_thread_analytics.to_dict(), {
         'num_open_threads': 1,
         'num_total_threads': 2
     })
예제 #3
0
 def test_to_dict(self):
     expected_thread_analytics = feedback_domain.FeedbackAnalytics(
         self.EXP_ID, 1, 2)
     self.assertDictEqual(expected_thread_analytics.to_dict(), {
         'num_open_threads': 1,
         'num_total_threads': 2
     })
예제 #4
0
    def get_thread_analytics_multi(cls, exploration_ids):
        """
        Args:
          - exploration_ids: ids of the explorations to get statistics for.

        Returns a list of dicts, each with two keys: 'num_open_threads' and
        'num_total_threads', representing the counts of open and all feedback
        threads, respectively.
        """
        realtime_model_ids = cls.get_multi_active_realtime_layer_ids(
            exploration_ids)
        realtime_models = cls._get_realtime_datastore_class().get_multi(
            realtime_model_ids)
        feedback_thread_analytics_models = (
            feedback_models.FeedbackAnalyticsModel.get_multi(exploration_ids))

        return [
            feedback_domain.FeedbackAnalytics(
                exploration_ids[i], (realtime_models[i].num_open_threads if
                                     realtime_models[i] is not None else 0) +
                (feedback_thread_analytics_models[i].num_open_threads
                 if feedback_thread_analytics_models[i] is not None else 0),
                (realtime_models[i].num_total_threads
                 if realtime_models[i] is not None else 0) +
                (feedback_thread_analytics_models[i].num_total_threads
                 if feedback_thread_analytics_models[i] is not None else 0))
            for i in range(len(exploration_ids))
        ]
예제 #5
0
def get_thread_analytics_multi(exploration_ids):
    """Fetches all FeedbackAnalytics, for all the given exploration ids.

    A FeedbackAnalytics contains the exploration id the analytics belongs to,
    how many open threads exist for the exploration, how many total threads
    exist for the exploration.

    Args:
        exploration_ids: list(str). A list of exploration ids.

    Returns:
        list(FeedbackAnalytics). Analytics in the the same order as the input
        list. If an exploration id is invalid, the number of threads in the
        corresponding FeedbackAnalytics object will be zero.
    """
    feedback_thread_analytics_models = (
        feedback_models.FeedbackAnalyticsModel.get_multi(exploration_ids))
    return [
        feedback_domain.FeedbackAnalytics(
            feconf.ENTITY_TYPE_EXPLORATION, exp_id,
            model.num_open_threads if model is not None else 0,
            model.num_total_threads if model is not None else 0)
        for exp_id, model in python_utils.ZIP(
            exploration_ids, feedback_thread_analytics_models)
    ]
예제 #6
0
    def get_thread_analytics(cls, exploration_id):
        """
        Args:
          - exploration_id: id of the exploration to get statistics for.

        Returns a dict with two keys: 'num_open_threads' and
        'num_total_threads', representing the counts of open and all feedback
        threads, respectively.
        """
        realtime_model = cls._get_realtime_datastore_class().get(
            cls.get_active_realtime_layer_id(exploration_id), strict=False)
        feedback_thread_analytics_model = (
            feedback_models.FeedbackAnalyticsModel.get(exploration_id,
                                                       strict=False))

        num_open_threads = 0
        num_total_threads = 0
        if realtime_model:
            num_open_threads = realtime_model.num_open_threads
            num_total_threads = realtime_model.num_total_threads
        if feedback_thread_analytics_model:
            num_open_threads += feedback_thread_analytics_model.num_open_threads
            num_total_threads += (
                feedback_thread_analytics_model.num_total_threads)

        return feedback_domain.FeedbackAnalytics(exploration_id,
                                                 num_open_threads,
                                                 num_total_threads)
예제 #7
0
 def mock_get_thread_analytics_multi(unused_exploration_ids):
     return [feedback_domain.FeedbackAnalytics(self.EXP_ID, 2, 3)]
예제 #8
0
 def mock_get_thread_analytics_multi(unused_exploration_ids):
     return [feedback_domain.FeedbackAnalytics(
         feconf.ENTITY_TYPE_EXPLORATION, self.EXP_ID, 2, 3)]