def get_training_task_params(training_workflow_uuid): """ Retrieve the training examples and algorithm ID associated with a training task. Args: training_workflow_uuid (str): The UUID of the training workflow. Returns: dict with keys: * training_examples (list of dict): The examples used to train the classifiers. * course_id (unicode): The course ID that the training task is associated with. * item_id (unicode): Identifies the item that the AI will be training to grade. * algorithm_id (unicode): The ID of the algorithm to use for training. Raises: AITrainingRequestError AITrainingInternalError Example usage: >>> params = get_training_task_params('abcd1234') >>> params['algorithm_id'] u'ease' >>> params['training_examples'] [ { "text": u"Example answer number one", "scores": { "vocabulary": 1, "grammar": 2 } }, { "text": u"Example answer number two", "scores": { "vocabulary": 3, "grammar": 1 } } ] """ try: workflow = AITrainingWorkflow.objects.get(uuid=training_workflow_uuid) returned_examples = [] for example in workflow.training_examples.all(): scores = { option.criterion.name: option.points for option in example.options_selected.all() } returned_examples.append({ 'text': essay_text_from_submission({'answer': example.answer}), 'scores': scores }) return { 'training_examples': returned_examples, 'algorithm_id': workflow.algorithm_id, 'course_id': workflow.course_id, 'item_id': workflow.item_id } except AITrainingWorkflow.DoesNotExist: msg = ( u"Could not retrieve AI training workflow with UUID {}" ).format(training_workflow_uuid) raise AITrainingRequestError(msg) except DatabaseError: msg = ( u"An unexpected error occurred while retrieving " u"training examples for the AI training workflow with UUID {}" ).format(training_workflow_uuid) logger.exception(msg) raise AITrainingInternalError(msg)
def test_essay_text_from_submission(self, input, output): self.assertEqual(essay_text_from_submission(input), output)
def get_training_task_params(training_workflow_uuid): """ Retrieve the training examples and algorithm ID associated with a training task. Args: training_workflow_uuid (str): The UUID of the training workflow. Returns: dict with keys: * training_examples (list of dict): The examples used to train the classifiers. * course_id (unicode): The course ID that the training task is associated with. * item_id (unicode): Identifies the item that the AI will be training to grade. * algorithm_id (unicode): The ID of the algorithm to use for training. Raises: AITrainingRequestError AITrainingInternalError Example usage: >>> params = get_training_task_params('abcd1234') >>> params['algorithm_id'] u'ease' >>> params['training_examples'] [ { "text": u"Example answer number one", "scores": { "vocabulary": 1, "grammar": 2 } }, { "text": u"Example answer number two", "scores": { "vocabulary": 3, "grammar": 1 } } ] """ try: workflow = AITrainingWorkflow.objects.get(uuid=training_workflow_uuid) returned_examples = [] for example in workflow.training_examples.all(): scores = { option.criterion.name: option.points for option in example.options_selected.all() } returned_examples.append({ 'text': essay_text_from_submission({'answer': example.answer}), 'scores': scores }) return { 'training_examples': returned_examples, 'algorithm_id': workflow.algorithm_id, 'course_id': workflow.course_id, 'item_id': workflow.item_id } except AITrainingWorkflow.DoesNotExist: msg = (u"Could not retrieve AI training workflow with UUID {}" ).format(training_workflow_uuid) raise AITrainingRequestError(msg) except DatabaseError: msg = (u"An unexpected error occurred while retrieving " u"training examples for the AI training workflow with UUID {}" ).format(training_workflow_uuid) logger.exception(msg) raise AITrainingInternalError(msg)