コード例 #1
0
    def post(self):
        """Handles POST requests."""
        payload_proto = (
            training_job_response_payload_pb2.TrainingJobResponsePayload())
        payload_proto.ParseFromString(self.request.body)

        if not validate_job_result_message_proto(payload_proto.job_result):
            raise self.InvalidInputException

        job_id = payload_proto.job_result.job_id

        classifier_training_job = (
            classifier_services.get_classifier_training_job_by_id(job_id))
        if classifier_training_job.status == (
                feconf.TRAINING_JOB_STATUS_FAILED):
            # Send email to admin and admin-specified email recipients.
            # Other email recipients are specified on admin config page.
            email_manager.send_job_failure_email(job_id)
            raise self.InternalErrorException(
                'The current status of the job cannot transition to COMPLETE.')

        classifier_data_proto = getattr(
            payload_proto.job_result,
            payload_proto.job_result.WhichOneof('classifier_frozen_model'))
        classifier_services.store_classifier_data(
            job_id, classifier_data_proto)

        # Update status of the training job to 'COMPLETE'.
        classifier_services.mark_training_job_complete(job_id)

        return self.render_json({})
コード例 #2
0
    def test_mark_training_job_complete(self):
        """Test the mark_training_job_complete method."""
        exp_id = u'1'
        next_scheduled_check_time = datetime.datetime.utcnow()
        state_name = 'Home'
        interaction_id = 'TextInput'

        job_id = self._create_classifier_training_job(
            feconf.INTERACTION_CLASSIFIER_MAPPING['TextInput']['algorithm_id'],
            interaction_id, exp_id, 1, next_scheduled_check_time, [],
            state_name, feconf.TRAINING_JOB_STATUS_PENDING, {}, 1)

        classifier_training_job = (
            classifier_services.get_classifier_training_job_by_id(job_id))
        self.assertEqual(classifier_training_job.status,
                         feconf.TRAINING_JOB_STATUS_PENDING)

        classifier_services.mark_training_job_complete(job_id)

        classifier_training_job = (
            classifier_services.get_classifier_training_job_by_id(job_id))
        self.assertEqual(classifier_training_job.status,
                         feconf.TRAINING_JOB_STATUS_COMPLETE)

        # Test that invalid status changes cannot be made.
        with self.assertRaisesRegexp(
                Exception, ('The status change %s to %s is not valid.' %
                            (feconf.TRAINING_JOB_STATUS_COMPLETE,
                             feconf.TRAINING_JOB_STATUS_COMPLETE))):
            classifier_services.mark_training_job_complete(job_id)
コード例 #3
0
 def test_can_not_mark_training_jobs_complete_due_to_invalid_job_id(
         self) -> None:
     with self.assertRaisesRegex(  # type: ignore[no-untyped-call]
             Exception,
             'The ClassifierTrainingJobModel corresponding to the '
             'job_id of the ClassifierTrainingJob does not exist.'):
         classifier_services.mark_training_job_complete('invalid_job_id')
コード例 #4
0
ファイル: classifier.py プロジェクト: nindyahapsari/oppia
    def post(self):
        """Handles POST requests."""
        signature = self.payload.get('signature')
        message = self.payload.get('message')
        vm_id = self.payload.get('vm_id')
        if vm_id == feconf.DEFAULT_VM_ID and not feconf.DEV_MODE:
            raise self.UnauthorizedUserException

        if not validate_job_result_message_dict(message):
            raise self.InvalidInputException
        if not verify_signature(message, vm_id, signature):
            raise self.UnauthorizedUserException

        job_id = message['job_id']
        classifier_data = message['classifier_data']
        classifier_training_job = (
            classifier_services.get_classifier_training_job_by_id(job_id))
        if classifier_training_job.status == (
                feconf.TRAINING_JOB_STATUS_FAILED):
            raise self.InternalErrorException(
                'The current status of the job cannot transition to COMPLETE.')
        try:
            classifier_services.store_classifier_data(job_id, classifier_data)
        except Exception as e:
            raise self.InternalErrorException(e)

        # Update status of the training job to 'COMPLETE'.
        classifier_services.mark_training_job_complete(job_id)

        return self.render_json({})
コード例 #5
0
    def post(self):
        """Handles POST requests."""
        signature = self.payload.get('signature')
        message = self.payload.get('message')
        vm_id = self.payload.get('vm_id')
        if vm_id == feconf.DEFAULT_VM_ID and not constants.DEV_MODE:
            raise self.UnauthorizedUserException

        if not validate_job_result_message_dict(message):
            raise self.InvalidInputException
        if not verify_signature(message, vm_id, signature):
            raise self.UnauthorizedUserException

        job_id = message['job_id']
        # The classifier data received in the payload has all floating point
        # values stored as strings. This is because floating point numbers
        # are represented differently on GAE(Oppia) and GCE(Oppia-ml).
        # Therefore, converting all floating point numbers to string keeps
        # signature consistent on both Oppia and Oppia-ml.
        # For more info visit: https://stackoverflow.com/q/40173295
        classifier_data = (
            classifier_services.
            convert_strings_to_float_numbers_in_classifier_data(  #pylint: disable=line-too-long
                message['classifier_data_with_floats_stringified']))
        classifier_training_job = (
            classifier_services.get_classifier_training_job_by_id(job_id))
        if classifier_training_job.status == (
                feconf.TRAINING_JOB_STATUS_FAILED):
            # Send email to admin and admin-specified email recipients.
            # Other email recipients are specified on admin config page.
            email_manager.send_job_failure_email(job_id)
            raise self.InternalErrorException(
                'The current status of the job cannot transition to COMPLETE.')
        try:
            classifier_services.store_classifier_data(job_id, classifier_data)
        except Exception as e:
            raise self.InternalErrorException(e)

        # Update status of the training job to 'COMPLETE'.
        classifier_services.mark_training_job_complete(job_id)

        return self.render_json({})