def get(self, exploration_id): """Populates the data on the individual exploration page. Args: exploration_id: str. The ID of the exploration. """ version = self.request.get('v') version = int(version) if version else None try: exploration = exp_fetchers.get_exploration_by_id(exploration_id, version=version) except Exception as e: raise self.PageNotFoundException(e) exploration_rights = rights_manager.get_exploration_rights( exploration_id, strict=False) user_settings = user_services.get_user_settings(self.user_id) preferred_audio_language_code = None if user_settings is not None: preferred_audio_language_code = ( user_settings.preferred_audio_language_code) # Retrieve all classifiers for the exploration. state_classifier_mapping = {} classifier_training_jobs = ( classifier_services.get_classifier_training_jobs( exploration_id, exploration.version, list(exploration.states.keys()))) for index, state_name in enumerate(exploration.states.keys()): if classifier_training_jobs[index] is not None: state_classifier_mapping[state_name] = ( classifier_training_jobs[index].to_player_dict()) self.values.update({ 'can_edit': (rights_manager.check_can_edit_activity(self.user, exploration_rights)), 'exploration': exploration.to_player_dict(), 'exploration_id': exploration_id, 'is_logged_in': bool(self.user_id), 'session_id': utils.generate_new_session_id(), 'version': exploration.version, 'preferred_audio_language_code': preferred_audio_language_code, 'state_classifier_mapping': state_classifier_mapping, 'auto_tts_enabled': exploration.auto_tts_enabled, 'correctness_feedback_enabled': (exploration.correctness_feedback_enabled), 'record_playthrough_probability': (config_domain.RECORD_PLAYTHROUGH_PROBABILITY.value), }) self.render_json(self.values)
def get(self, exploration_id): """Populates the data on the individual exploration page. Args: exploration_id: str. The ID of the exploration. """ version = self.request.get('v') version = int(version) if version else None try: exploration = exp_services.get_exploration_by_id(exploration_id, version=version) except Exception as e: raise self.PageNotFoundException(e) exploration_rights = rights_manager.get_exploration_rights( exploration_id, strict=False) user_settings = user_services.get_user_settings(self.user_id) preferred_audio_language_code = None if user_settings is not None: preferred_audio_language_code = ( user_settings.preferred_audio_language_code) # Retrieve all classifiers for the exploration. state_classifier_mapping = {} classifier_training_jobs = ( classifier_services.get_classifier_training_jobs( exploration_id, exploration.version, exploration.states)) for index, state_name in enumerate(exploration.states): if classifier_training_jobs[index] is not None: classifier_data = classifier_training_jobs[ index].classifier_data algorithm_id = classifier_training_jobs[index].algorithm_id data_schema_version = ( classifier_training_jobs[index].data_schema_version) state_classifier_mapping[state_name] = { 'algorithm_id': algorithm_id, 'classifier_data': classifier_data, 'data_schema_version': data_schema_version } self.values.update({ 'can_edit': (rights_manager.check_can_edit_activity(self.user, exploration_rights)), 'exploration': exploration.to_player_dict(), 'exploration_id': exploration_id, 'is_logged_in': bool(self.user_id), 'session_id': utils.generate_new_session_id(), 'version': exploration.version, 'preferred_audio_language_code': preferred_audio_language_code, 'state_classifier_mapping': state_classifier_mapping, 'auto_tts_enabled': exploration.auto_tts_enabled, 'correctness_feedback_enabled': (exploration.correctness_feedback_enabled), }) self.render_json(self.values)
def setUp(self): super(TrainedClassifierHandlerTests, self).setUp() self.exp_id = 'exp_id1' self.title = 'Testing Classifier storing' self.category = 'Test' yaml_path = os.path.join( feconf.TESTS_DATA_DIR, 'string_classifier_test.yaml') with open(yaml_path, 'r') as yaml_file: self.yaml_content = yaml_file.read() self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.signup('*****@*****.**', 'mod') assets_list = [] with self.swap(feconf, 'ENABLE_ML_CLASSIFIERS', True): exp_services.save_new_exploration_from_yaml_and_assets( feconf.SYSTEM_COMMITTER_ID, self.yaml_content, self.exp_id, assets_list) self.exploration = exp_services.get_exploration_by_id(self.exp_id) self.classifier_data_with_floats_stringified = { '_alpha': '0.1', '_beta': '0.001', '_prediction_threshold': '0.5', '_training_iterations': 25, '_prediction_iterations': 5, '_num_labels': 10, '_num_docs': 12, '_num_words': 20, '_label_to_id': {'text': 1}, '_word_to_id': {'hello': 2}, '_w_dp': [], '_b_dl': [], '_l_dp': [], '_c_dl': [], '_c_lw': [], '_c_l': [], } classifier_training_jobs = ( classifier_services.get_classifier_training_jobs( self.exp_id, self.exploration.version, ['Home'])) self.assertEqual(len(classifier_training_jobs), 1) classifier_training_job = classifier_training_jobs[0] self.job_id = classifier_training_job.job_id # TODO(pranavsid98): Replace the three commands below with # mark_training_job_pending after Giritheja's PR gets merged. classifier_training_job_model = ( classifier_models.ClassifierTrainingJobModel.get( self.job_id, strict=False)) classifier_training_job_model.status = ( feconf.TRAINING_JOB_STATUS_PENDING) classifier_training_job_model.put() self.job_result_dict = { 'job_id': self.job_id, 'classifier_data_with_floats_stringified': ( self.classifier_data_with_floats_stringified) } self.payload = {} self.payload['vm_id'] = feconf.DEFAULT_VM_ID self.payload['message'] = self.job_result_dict secret = feconf.DEFAULT_VM_SHARED_SECRET self.payload['signature'] = classifier.generate_signature( secret, self.payload['message'])
def get(self, exploration_id): """Populates the data on the individual exploration page. Args: exploration_id: str. The ID of the exploration. """ version = self.request.get('v') story_id = self.request.get('story_id') version = int(version) if version else None try: exploration = exp_services.get_exploration_by_id( exploration_id, version=version) except Exception as e: raise self.PageNotFoundException(e) exploration_rights = rights_manager.get_exploration_rights( exploration_id, strict=False) user_settings = user_services.get_user_settings(self.user_id) preferred_audio_language_code = None if user_settings is not None: preferred_audio_language_code = ( user_settings.preferred_audio_language_code) # Retrieve all classifiers for the exploration. state_classifier_mapping = {} classifier_training_jobs = ( classifier_services.get_classifier_training_jobs( exploration_id, exploration.version, exploration.states)) for index, state_name in enumerate(exploration.states): if classifier_training_jobs[index] is not None: classifier_data = classifier_training_jobs[ index].classifier_data algorithm_id = classifier_training_jobs[index].algorithm_id data_schema_version = ( classifier_training_jobs[index].data_schema_version) state_classifier_mapping[state_name] = { 'algorithm_id': algorithm_id, 'classifier_data': classifier_data, 'data_schema_version': data_schema_version } pretest_question_dicts = [] next_cursor = None if story_id: story = story_services.get_story_by_id(story_id, strict=False) if story is None: raise self.InvalidInputException if not story.has_exploration(exploration_id): raise self.InvalidInputException pretest_questions, next_cursor = ( question_services.get_questions_by_skill_ids( feconf.NUM_PRETEST_QUESTIONS, story.get_prerequisite_skill_ids_for_exp_id(exploration_id), '') ) pretest_question_dicts = [ question.to_dict() for question in pretest_questions ] self.values.update({ 'can_edit': ( rights_manager.check_can_edit_activity( self.user, exploration_rights)), 'exploration': exploration.to_player_dict(), 'exploration_id': exploration_id, 'pretest_question_dicts': pretest_question_dicts, 'next_cursor_for_pretests': next_cursor, 'is_logged_in': bool(self.user_id), 'session_id': utils.generate_new_session_id(), 'version': exploration.version, 'preferred_audio_language_code': preferred_audio_language_code, 'state_classifier_mapping': state_classifier_mapping, 'auto_tts_enabled': exploration.auto_tts_enabled, 'correctness_feedback_enabled': ( exploration.correctness_feedback_enabled), }) self.render_json(self.values)