Ejemplo n.º 1
0
    def test_record_and_retrieve_single_answer(self):
        state_answers = stats_services.get_state_answers(
            self.EXP_ID, self.exploration.version,
            self.exploration.init_state_name)
        self.assertIsNone(state_answers)

        stats_services.record_answer(
            self.EXP_ID, self.exploration.version,
            self.exploration.init_state_name, 'TextInput',
            stats_domain.SubmittedAnswer(
                'some text', 'TextInput', 0,
                1, exp_domain.EXPLICIT_CLASSIFICATION, {},
                'a_session_id_val', 10.0))

        state_answers = stats_services.get_state_answers(
            self.EXP_ID, self.exploration.version,
            self.exploration.init_state_name)
        self.assertEqual(state_answers.exploration_id, 'exp_id0')
        self.assertEqual(state_answers.exploration_version, 1)
        self.assertEqual(
            state_answers.state_name, feconf.DEFAULT_INIT_STATE_NAME)
        self.assertEqual(state_answers.interaction_id, 'TextInput')
        self.assertEqual(state_answers.get_submitted_answer_dict_list(), [{
            'answer': 'some text',
            'time_spent_in_sec': 10.0,
            'answer_group_index': 0,
            'rule_spec_index': 1,
            'classification_categorization': 'explicit',
            'session_id': 'a_session_id_val',
            'interaction_id': 'TextInput',
            'params': {}
        }])
Ejemplo n.º 2
0
 def _record_answer(
         self, answer_str, exploration, state_name,
         classification=exp_domain.DEFAULT_OUTCOME_CLASSIFICATION):
     stats_services.record_answer(
         exploration.id, exploration.version, state_name, 'TextInput',
         stats_domain.SubmittedAnswer(
             answer_str, 'TextInput', 0, 0, classification, {}, 'session',
             self.DEFAULT_TIME_SPENT))
Ejemplo n.º 3
0
 def _handle_event(
         cls, exploration_id, exploration_version, state_name,
         interaction_id, answer_group_index, rule_spec_index,
         classification_categorization, session_id, time_spent_in_secs,
         params, normalized_answer):
     """Records an event when an answer triggers a rule. The answer recorded
     here is a Python-representation of the actual answer submitted by the
     user.
     """
     # TODO(sll): Escape these args?
     stats_services.record_answer(
         exploration_id, exploration_version, state_name, interaction_id,
         stats_domain.SubmittedAnswer(
             normalized_answer, interaction_id, answer_group_index,
             rule_spec_index, classification_categorization, params,
             session_id, time_spent_in_secs))
Ejemplo n.º 4
0
    def _handle_event(cls, exploration_id, exploration_version, state_name,
                      interaction_id, answer_group_index, rule_spec_index,
                      classification_categorization, session_id,
                      time_spent_in_secs, params, normalized_answer):
        """Records an event when an answer triggers a rule. The answer recorded
        here is a Python-representation of the actual answer submitted by the
        user.
        """
        # TODO(sll): Escape these args?
        stats_services.record_answer(
            exploration_id, exploration_version, state_name, interaction_id,
            stats_domain.SubmittedAnswer(normalized_answer, interaction_id,
                                         answer_group_index, rule_spec_index,
                                         classification_categorization, params,
                                         session_id, time_spent_in_secs))

        feedback_is_useful = (classification_categorization !=
                              (exp_domain.DEFAULT_OUTCOME_CLASSIFICATION))

        stats_models.AnswerSubmittedEventLogEntryModel.create(
            exploration_id, exploration_version, state_name, session_id,
            time_spent_in_secs, feedback_is_useful)
Ejemplo n.º 5
0
    def setUp(self):
        """Complete the signup process for self.ADMIN_EMAIL."""
        super(DataExtractionQueryHandlerTests, self).setUp()
        self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME)
        self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME)
        self.editor_id = self.get_user_id_from_email(self.EDITOR_EMAIL)
        self.exploration = self.save_new_valid_exploration(
            self.EXP_ID, self.editor_id, end_state_name='End')

        stats_services.record_answer(
            self.EXP_ID, self.exploration.version,
            self.exploration.init_state_name, 'TextInput',
            stats_domain.SubmittedAnswer('first answer', 'TextInput', 0, 0,
                                         exp_domain.EXPLICIT_CLASSIFICATION,
                                         {}, 'a_session_id_val', 1.0))

        stats_services.record_answer(
            self.EXP_ID, self.exploration.version,
            self.exploration.init_state_name, 'TextInput',
            stats_domain.SubmittedAnswer('second answer', 'TextInput', 0, 0,
                                         exp_domain.EXPLICIT_CLASSIFICATION,
                                         {}, 'a_session_id_val', 1.0))
Ejemplo n.º 6
0
    def test_record_answer_without_retrieving_it_first(self):
        stats_services.record_answer(
            self.EXP_ID, self.exploration.version,
            self.exploration.init_state_name, 'TextInput',
            stats_domain.SubmittedAnswer(
                'first answer', 'TextInput', 0,
                0, exp_domain.EXPLICIT_CLASSIFICATION, {},
                'a_session_id_val', 1.0))

        state_answers = stats_services.get_state_answers(
            self.EXP_ID, self.exploration.version,
            self.exploration.init_state_name)
        self.assertEqual(state_answers.get_submitted_answer_dict_list(), [{
            'answer': 'first answer',
            'time_spent_in_sec': 1.0,
            'answer_group_index': 0,
            'rule_spec_index': 0,
            'classification_categorization': 'explicit',
            'session_id': 'a_session_id_val',
            'interaction_id': 'TextInput',
            'params': {}
        }])
Ejemplo n.º 7
0
    def test_record_many_answers_with_preexisting_entry(self):
        stats_services.record_answer(
            self.EXP_ID, self.exploration.version,
            self.exploration.init_state_name, 'TextInput',
            stats_domain.SubmittedAnswer('1 answer', 'TextInput', 0, 0,
                                         exp_domain.EXPLICIT_CLASSIFICATION,
                                         {}, 'a_session_id_val', 1.0))

        state_answers = stats_services.get_state_answers(
            self.EXP_ID, self.exploration.version,
            self.exploration.init_state_name)
        self.assertEqual(state_answers.get_submitted_answer_dict_list(),
                         [{
                             'answer': '1 answer',
                             'time_spent_in_sec': 1.0,
                             'answer_group_index': 0,
                             'rule_spec_index': 0,
                             'classification_categorization': 'explicit',
                             'session_id': 'a_session_id_val',
                             'interaction_id': 'TextInput',
                             'params': {}
                         }])

        submitted_answer_list = [
            stats_domain.SubmittedAnswer('answer aaa', 'TextInput', 0, 1,
                                         exp_domain.EXPLICIT_CLASSIFICATION,
                                         {}, 'session_id_v', 10.0),
            stats_domain.SubmittedAnswer('answer ccccc', 'TextInput', 1, 1,
                                         exp_domain.EXPLICIT_CLASSIFICATION,
                                         {}, 'session_id_v', 3.0),
            stats_domain.SubmittedAnswer('answer bbbbbbb', 'TextInput', 1, 0,
                                         exp_domain.EXPLICIT_CLASSIFICATION,
                                         {}, 'session_id_v', 7.5),
        ]
        stats_services.record_answers(self.EXP_ID, self.exploration.version,
                                      self.exploration.init_state_name,
                                      'TextInput', submitted_answer_list)

        # The order of the answers returned depends on the size of the answers.
        state_answers = stats_services.get_state_answers(
            self.EXP_ID, self.exploration.version,
            self.exploration.init_state_name)
        self.assertEqual(state_answers.exploration_id, 'exp_id0')
        self.assertEqual(state_answers.exploration_version, 1)
        self.assertEqual(state_answers.state_name,
                         feconf.DEFAULT_INIT_STATE_NAME)
        self.assertEqual(state_answers.interaction_id, 'TextInput')
        self.assertEqual(state_answers.get_submitted_answer_dict_list(),
                         [{
                             'answer': '1 answer',
                             'time_spent_in_sec': 1.0,
                             'answer_group_index': 0,
                             'rule_spec_index': 0,
                             'classification_categorization': 'explicit',
                             'session_id': 'a_session_id_val',
                             'interaction_id': 'TextInput',
                             'params': {}
                         }, {
                             'answer': 'answer aaa',
                             'time_spent_in_sec': 10.0,
                             'answer_group_index': 0,
                             'rule_spec_index': 1,
                             'classification_categorization': 'explicit',
                             'session_id': 'session_id_v',
                             'interaction_id': 'TextInput',
                             'params': {}
                         }, {
                             'answer': 'answer ccccc',
                             'time_spent_in_sec': 3.0,
                             'answer_group_index': 1,
                             'rule_spec_index': 1,
                             'classification_categorization': 'explicit',
                             'session_id': 'session_id_v',
                             'interaction_id': 'TextInput',
                             'params': {}
                         }, {
                             'answer': 'answer bbbbbbb',
                             'time_spent_in_sec': 7.5,
                             'answer_group_index': 1,
                             'rule_spec_index': 0,
                             'classification_categorization': 'explicit',
                             'session_id': 'session_id_v',
                             'interaction_id': 'TextInput',
                             'params': {}
                         }])
Ejemplo n.º 8
0
    def test_record_many_answers_with_preexisting_entry(self):
        stats_services.record_answer(
            self.EXP_ID, self.exploration.version,
            self.exploration.init_state_name, 'TextInput',
            stats_domain.SubmittedAnswer(
                '1 answer', 'TextInput', 0,
                0, exp_domain.EXPLICIT_CLASSIFICATION, {},
                'a_session_id_val', 1.0))

        state_answers = stats_services.get_state_answers(
            self.EXP_ID, self.exploration.version,
            self.exploration.init_state_name)
        self.assertEqual(state_answers.get_submitted_answer_dict_list(), [{
            'answer': '1 answer',
            'time_spent_in_sec': 1.0,
            'answer_group_index': 0,
            'rule_spec_index': 0,
            'classification_categorization': 'explicit',
            'session_id': 'a_session_id_val',
            'interaction_id': 'TextInput',
            'params': {}
        }])

        submitted_answer_list = [
            stats_domain.SubmittedAnswer(
                'answer aaa', 'TextInput', 0, 1,
                exp_domain.EXPLICIT_CLASSIFICATION, {}, 'session_id_v', 10.0),
            stats_domain.SubmittedAnswer(
                'answer ccccc', 'TextInput', 1, 1,
                exp_domain.EXPLICIT_CLASSIFICATION, {}, 'session_id_v', 3.0),
            stats_domain.SubmittedAnswer(
                'answer bbbbbbb', 'TextInput', 1, 0,
                exp_domain.EXPLICIT_CLASSIFICATION, {}, 'session_id_v', 7.5),
        ]
        stats_services.record_answers(
            self.EXP_ID, self.exploration.version,
            self.exploration.init_state_name, 'TextInput',
            submitted_answer_list)

        # The order of the answers returned depends on the size of the answers.
        state_answers = stats_services.get_state_answers(
            self.EXP_ID, self.exploration.version,
            self.exploration.init_state_name)
        self.assertEqual(state_answers.exploration_id, 'exp_id0')
        self.assertEqual(state_answers.exploration_version, 1)
        self.assertEqual(
            state_answers.state_name, feconf.DEFAULT_INIT_STATE_NAME)
        self.assertEqual(state_answers.interaction_id, 'TextInput')
        self.assertEqual(state_answers.get_submitted_answer_dict_list(), [{
            'answer': '1 answer',
            'time_spent_in_sec': 1.0,
            'answer_group_index': 0,
            'rule_spec_index': 0,
            'classification_categorization': 'explicit',
            'session_id': 'a_session_id_val',
            'interaction_id': 'TextInput',
            'params': {}
        }, {
            'answer': 'answer aaa',
            'time_spent_in_sec': 10.0,
            'answer_group_index': 0,
            'rule_spec_index': 1,
            'classification_categorization': 'explicit',
            'session_id': 'session_id_v',
            'interaction_id': 'TextInput',
            'params': {}
        }, {
            'answer': 'answer ccccc',
            'time_spent_in_sec': 3.0,
            'answer_group_index': 1,
            'rule_spec_index': 1,
            'classification_categorization': 'explicit',
            'session_id': 'session_id_v',
            'interaction_id': 'TextInput',
            'params': {}
        }, {
            'answer': 'answer bbbbbbb',
            'time_spent_in_sec': 7.5,
            'answer_group_index': 1,
            'rule_spec_index': 0,
            'classification_categorization': 'explicit',
            'session_id': 'session_id_v',
            'interaction_id': 'TextInput',
            'params': {}
        }])