コード例 #1
0
 def test_update_assessments_format(self, input_prompt, output):
     self.assertEqual(
         update_assessments_format([{
             'examples': input_prompt,
         }]), [{
             'examples': output,
         }])
コード例 #2
0
ファイル: openassessmentblock.py プロジェクト: edx/edx-ora2
    def valid_assessments(self):
        """
        Return a list of assessment dictionaries that we recognize.
        This allows us to gracefully handle situations in which unrecognized
        assessment types are stored in the XBlock field (e.g. because
        we roll back code after releasing a feature).

        Returns:
            list

        """
        _valid_assessments = [
            asmnt for asmnt in self.rubric_assessments
            if asmnt.get('name') in VALID_ASSESSMENT_TYPES
        ]
        return update_assessments_format(copy.deepcopy(_valid_assessments))
コード例 #3
0
    def valid_assessments(self):
        """
        Return a list of assessment dictionaries that we recognize.
        This allows us to gracefully handle situations in which unrecognized
        assessment types are stored in the XBlock field (e.g. because
        we roll back code after releasing a feature).

        Returns:
            list

        """
        _valid_assessments = [
            asmnt for asmnt in self.rubric_assessments
            if asmnt.get('name') in VALID_ASSESSMENT_TYPES
        ]
        return update_assessments_format(copy.deepcopy(_valid_assessments))
コード例 #4
0
ファイル: xml.py プロジェクト: sendr/edx-ora2
def serialize_assessments(assessments_root, oa_block):
    """
    Serialize the assessment modules for an OpenAssessment XBlock.

    Args:
        assessments_root (lxml.etree.Element): The <assessments> XML element.
        oa_block (OpenAssessmentXBlock): The XBlock with configuration to
            serialize.

    Returns:
        None

    """
    for assessment_dict in update_assessments_format(
            oa_block.rubric_assessments):

        assessment = etree.SubElement(assessments_root, 'assessment')

        # Set assessment attributes, defaulting to empty values
        assessment.set('name', str(assessment_dict.get('name', '')))

        if 'must_grade' in assessment_dict:
            assessment.set('must_grade', str(assessment_dict['must_grade']))

        if 'must_be_graded_by' in assessment_dict:
            assessment.set('must_be_graded_by',
                           str(assessment_dict['must_be_graded_by']))

        if 'enable_flexible_grading' in assessment_dict:
            assessment.set('enable_flexible_grading',
                           str(assessment_dict['enable_flexible_grading']))

        if assessment_dict.get('start') is not None:
            assessment.set('start', str(assessment_dict['start']))

        if assessment_dict.get('due') is not None:
            assessment.set('due', str(assessment_dict['due']))

        if assessment_dict.get('required') is not None:
            assessment.set('required', str(assessment_dict['required']))

        # Training examples
        examples = assessment_dict.get('examples', [])
        if not isinstance(examples, list):
            examples = []
        serialize_training_examples(examples, assessment)
コード例 #5
0
ファイル: xml.py プロジェクト: sendr/edx-ora2
def serialize_examples_to_xml_str(assessment):
    """
    Serializes the OpenAssessment XBlock's training examples into an XML unicode
    string.

    Args:
        assessment (dict): Dictionary representation of an Assessment Module's
            configuration. If this contains a list of examples, the examples
            will be returned serialized.

    Returns:
        A unicode string of the XML serialized examples.

    """
    examples = update_assessments_format([assessment])[0].get('examples', [])
    if not isinstance(examples, list):
        examples = []
    examples_root = etree.Element('examples')
    serialize_training_examples(examples, examples_root)
    return etree.tostring(examples_root, pretty_print=True, encoding='unicode')
コード例 #6
0
ファイル: xml.py プロジェクト: edx/edx-ora2
def serialize_examples_to_xml_str(assessment):
    """
    Serializes the OpenAssessment XBlock's training examples into an XML unicode
    string.

    Args:
        assessment (dict): Dictionary representation of an Assessment Module's
            configuration. If this contains a list of examples, the examples
            will be returned serialized.

    Returns:
        A unicode string of the XML serialized examples.

    """
    examples = update_assessments_format([assessment])[0].get('examples', [])
    if not isinstance(examples, list):
        examples = []
    examples_root = etree.Element('examples')
    serialize_training_examples(examples, examples_root)
    return etree.tostring(examples_root, pretty_print=True, encoding='unicode')
コード例 #7
0
ファイル: xml.py プロジェクト: edx/edx-ora2
def serialize_assessments(assessments_root, oa_block):
    """
    Serialize the assessment modules for an OpenAssessment XBlock.

    Args:
        assessments_root (lxml.etree.Element): The <assessments> XML element.
        oa_block (OpenAssessmentXBlock): The XBlock with configuration to
            serialize.

    Returns:
        None

    """
    for assessment_dict in update_assessments_format(oa_block.rubric_assessments):

        assessment = etree.SubElement(assessments_root, 'assessment')

        # Set assessment attributes, defaulting to empty values
        assessment.set('name', unicode(assessment_dict.get('name', '')))

        if 'must_grade' in assessment_dict:
            assessment.set('must_grade', unicode(assessment_dict['must_grade']))

        if 'must_be_graded_by' in assessment_dict:
            assessment.set('must_be_graded_by', unicode(assessment_dict['must_be_graded_by']))

        if assessment_dict.get('start') is not None:
            assessment.set('start', unicode(assessment_dict['start']))

        if assessment_dict.get('due') is not None:
            assessment.set('due', unicode(assessment_dict['due']))

        if assessment_dict.get('required') is not None:
            assessment.set('required', unicode(assessment_dict['required']))

        # Training examples
        examples = assessment_dict.get('examples', [])
        if not isinstance(examples, list):
            examples = []
        serialize_training_examples(examples, assessment)
コード例 #8
0
ファイル: studio_mixin.py プロジェクト: OPI-PIB/Navoica-ORA2
    def _assessments_editor_context(self, assessment_dates):
        """
        Transform the rubric assessments list into the context
        we will pass to the Django template.

        Args:
            assessment_dates: List of assessment date ranges (tuples of start/end datetimes).

        Returns:
            dict

        """
        assessments = {}
        for asmnt, date_range in zip(self.rubric_assessments,
                                     assessment_dates):
            # Django Templates cannot handle dict keys with dashes, so we'll convert
            # the dashes to underscores.
            template_name = make_django_template_key(asmnt['name'])
            assessments[template_name] = copy.deepcopy(asmnt)
            assessments[template_name]['start'] = date_range[0]
            assessments[template_name]['due'] = date_range[1]

        # In addition to the data in the student training assessment, we need to include two additional
        # pieces of information: a blank context to render the empty template with, and the criteria
        # for each example (so we don't have any complicated logic within the template). Though this
        # could be accomplished within the template, we are opting to remove logic from the template.
        student_training_module = self.get_assessment_module(
            'student-training')

        student_training_template = {
            'answer': {
                'parts': [{
                    'text': ''
                } for prompt in self.prompts]
            }
        }
        criteria_list = copy.deepcopy(self.rubric_criteria_with_labels)
        for criterion in criteria_list:
            criterion['option_selected'] = ""
        student_training_template['criteria'] = criteria_list

        if student_training_module:
            student_training_module = update_assessments_format(
                [student_training_module])[0]
            example_list = []
            # Adds each example to a modified version of the student training module dictionary.
            for example in student_training_module['examples']:
                criteria_list = copy.deepcopy(self.rubric_criteria_with_labels)
                # Equivalent to a Join Query, this adds the selected option to the Criterion's dictionary, so that
                # it can be easily referenced in the template without searching through the selected options.
                for criterion in criteria_list:
                    for option_selected in example['options_selected']:
                        if option_selected['criterion'] == criterion['name']:
                            criterion['option_selected'] = option_selected[
                                'option']
                example_list.append({
                    'answer': example['answer'],
                    'criteria': criteria_list,
                })
            assessments['training'] = {
                'examples': example_list,
                'template': student_training_template
            }
        # If we don't have student training enabled, we still need to render a single (empty, or default) example
        else:
            assessments['training'] = {
                'examples': [student_training_template],
                'template': student_training_template
            }

        return assessments
コード例 #9
0
 def test_update_assessments_format(self, input, output):
     self.assertEqual(update_assessments_format([{
         'examples': input,
     }]), [{
         'examples': output,
     }])
コード例 #10
0
ファイル: studio_mixin.py プロジェクト: edx/edx-ora2
    def _assessments_editor_context(self, assessment_dates):
        """
        Transform the rubric assessments list into the context
        we will pass to the Django template.

        Args:
            assessment_dates: List of assessment date ranges (tuples of start/end datetimes).

        Returns:
            dict

        """
        assessments = {}
        for asmnt, date_range in zip(self.rubric_assessments, assessment_dates):
            # Django Templates cannot handle dict keys with dashes, so we'll convert
            # the dashes to underscores.
            template_name = make_django_template_key(asmnt['name'])
            assessments[template_name] = copy.deepcopy(asmnt)
            assessments[template_name]['start'] = date_range[0]
            assessments[template_name]['due'] = date_range[1]

        # In addition to the data in the student training assessment, we need to include two additional
        # pieces of information: a blank context to render the empty template with, and the criteria
        # for each example (so we don't have any complicated logic within the template). Though this
        # could be accomplished within the template, we are opting to remove logic from the template.
        student_training_module = self.get_assessment_module('student-training')

        student_training_template = {
            'answer': {
                'parts': [
                    {'text': ''} for prompt in self.prompts
                ]
            }
        }
        criteria_list = copy.deepcopy(self.rubric_criteria_with_labels)
        for criterion in criteria_list:
            criterion['option_selected'] = ""
        student_training_template['criteria'] = criteria_list

        if student_training_module:
            student_training_module = update_assessments_format([student_training_module])[0]
            example_list = []
            # Adds each example to a modified version of the student training module dictionary.
            for example in student_training_module['examples']:
                criteria_list = copy.deepcopy(self.rubric_criteria_with_labels)
                # Equivalent to a Join Query, this adds the selected option to the Criterion's dictionary, so that
                # it can be easily referenced in the template without searching through the selected options.
                for criterion in criteria_list:
                    for option_selected in example['options_selected']:
                        if option_selected['criterion'] == criterion['name']:
                            criterion['option_selected'] = option_selected['option']
                example_list.append({
                    'answer': example['answer'],
                    'criteria': criteria_list,
                })
            assessments['training'] = {'examples': example_list, 'template': student_training_template}
        # If we don't have student training enabled, we still need to render a single (empty, or default) example
        else:
            assessments['training'] = {'examples': [student_training_template], 'template': student_training_template}

        return assessments