Ejemplo n.º 1
0
    def student_view(self, context):
        if self.question is None:
            return Fragment(messages.COMPONENT_MISCONFIGURED)

        raw_feedback = self.get_feedback()

        feedback = []
        for item in raw_feedback:
            feedback.append(html.escape(item['answer']))

        fragment = Fragment()
        title = self.question.assessment_title if self.question.assessment_title else self.question.title
        render_context = {
            'assessment': self,
            'question_title': title,
            'feedback': feedback
        }
        if self.show_mean:
            try:
                render_context['mean'] = "{0:.1f}".format(mean(feedback))
            except ValueError as exc:
                log.warn(exc)
                render_context['mean'] = _(u"N/A")

        render_context.update(context)
        fragment.add_content(
            loader.render_template(
                "templates/html/components/review_assessment.html",
                render_context))
        return fragment
    def student_view(self, context):
        if self.question is None:
            return Fragment(self._(messages.COMPONENT_MISCONFIGURED))

        raw_feedback = self.get_feedback()

        feedback = []
        for item in raw_feedback:
            feedback.append(html.escape(item['answer']))

        fragment = Fragment()
        title = self.question.assessment_title if self.question.assessment_title else self.question.title
        render_context = {
            'assessment': self,
            'question_title': title,
            'feedback': feedback
        }
        if self.show_mean:
            try:
                if feedback:
                    render_context['mean'] = round_half_up(mean(feedback))
                else:
                    render_context['mean'] = _(u"N/A")
            except ValueError as exc:
                log.warn(exc)  # pylint: disable=deprecated-method
                render_context['mean'] = _(u"N/A")

        render_context.update(context)
        fragment.add_content(
            loader.render_django_template(
                "templates/html/components/review_assessment.html",
                render_context,
                i18n_service=self.i18n_service,
            ))
        return fragment
    def student_view(self, context):
        if self.question is None:
            return Fragment(messages.COMPONENT_MISCONFIGURED)

        raw_feedback = self.get_feedback()

        feedback = []
        for item in raw_feedback:
            feedback.append(html.escape(item['answer']))

        fragment = Fragment()
        title = self.question.assessment_title if self.question.assessment_title else self.question.title
        render_context = {'assessment': self, 'question_title': title, 'feedback': feedback}
        if self.show_mean:
            try:
                render_context['mean'] = "{0:.1f}".format(mean(feedback))
            except ValueError as exc:
                log.warn(exc)
                render_context['mean'] = _(u"N/A")

        render_context.update(context)
        fragment.add_content(loader.render_template("templates/html/components/review_assessment.html", render_context))
        return fragment
Ejemplo n.º 4
0
    def calculate_grade(self, group_id):  # pylint:disable=too-many-locals,too-many-branches
        review_item_data = self.project_api.get_workgroup_review_items_for_group(
            group_id, self.content_id)
        review_item_map = {
            make_key(review_item['question'],
                     self.real_user_id(review_item['reviewer'])):
            review_item['answer']
            for review_item in review_item_data
        }
        all_reviewer_ids = set([
            self.real_user_id(review_item['reviewer'])
            for review_item in review_item_data
        ])
        group_reviewer_ids = [
            user["id"] for user in self.project_api.get_workgroup_reviewers(
                group_id, self.content_id)
        ]
        admin_reviewer_ids = [
            reviewer_id for reviewer_id in all_reviewer_ids
            if reviewer_id not in group_reviewer_ids
        ]

        def get_user_grade_value_list(user_id):
            user_grades = []
            for question in self.grade_questions:
                user_value = review_item_map.get(
                    make_key(question.question_id, user_id), None)
                if user_value is None:
                    # if any are incomplete, we consider the whole set to be unusable
                    return None
                else:
                    user_grades.append(user_value)

            return user_grades

        admin_provided_grades = None
        if len(admin_reviewer_ids) > 0:
            admin_provided_grades = []
            # Only include complete admin gradesets
            admin_reviewer_grades = [
                arg for arg in [
                    get_user_grade_value_list(admin_id)
                    for admin_id in admin_reviewer_ids
                ] if arg
            ]
            admin_grader_count = len(admin_reviewer_grades)
            if admin_grader_count > 1:
                for idx in range(len(self.grade_questions)):
                    admin_provided_grades.append(
                        mean([adm[idx] for adm in admin_reviewer_grades]))
            elif admin_grader_count > 0:  # which actually means admin_grader_count == 1
                admin_provided_grades = admin_reviewer_grades[0]

        user_grades = {}
        if len(group_reviewer_ids) > 0:
            for reviewer_id in group_reviewer_ids:
                this_reviewers_grades = get_user_grade_value_list(reviewer_id)
                if this_reviewers_grades is None:
                    if admin_provided_grades:
                        this_reviewers_grades = admin_provided_grades
                    else:
                        return None
                user_grades[reviewer_id] = this_reviewers_grades
        elif admin_provided_grades:
            group_reviewer_ids = [self.user_id]
            user_grades[self.user_id] = admin_provided_grades
        else:
            return None

        # Okay, if we've got here we have a complete set of marks to calculate the grade
        reviewer_grades = [
            mean(user_grades[reviewer_id])
            for reviewer_id in group_reviewer_ids
            if len(user_grades[reviewer_id]) > 0
        ]
        group_grade = round(
            mean(reviewer_grades)) if len(reviewer_grades) > 0 else None

        return group_grade
    def calculate_grade(self, group_id):  # pylint:disable=too-many-locals,too-many-branches
        review_item_data = self.project_api.get_workgroup_review_items_for_group(group_id, self.content_id)
        review_item_map = {
            make_key(review_item['question'], self.real_user_id(review_item['reviewer'])): review_item['answer']
            for review_item in review_item_data
        }
        all_reviewer_ids = set([self.real_user_id(review_item['reviewer']) for review_item in review_item_data])
        group_reviewer_ids = [
            user["id"] for user in self.project_api.get_workgroup_reviewers(group_id, self.content_id)
        ]
        admin_reviewer_ids = [reviewer_id for reviewer_id in all_reviewer_ids if reviewer_id not in group_reviewer_ids]

        def get_user_grade_value_list(user_id):
            user_grades = []
            for question in self.grade_questions:
                user_value = review_item_map.get(make_key(question.question_id, user_id), None)
                if user_value is None:
                    # if any are incomplete, we consider the whole set to be unusable
                    return None
                else:
                    user_grades.append(user_value)

            return user_grades

        admin_provided_grades = None
        if len(admin_reviewer_ids) > 0:
            admin_provided_grades = []
            # Only include complete admin gradesets
            admin_reviewer_grades = [
                arg
                for arg in [get_user_grade_value_list(admin_id) for admin_id in admin_reviewer_ids]
                if arg
            ]
            admin_grader_count = len(admin_reviewer_grades)
            if admin_grader_count > 1:
                for idx in range(len(self.grade_questions)):
                    admin_provided_grades.append(mean([adm[idx] for adm in admin_reviewer_grades]))
            elif admin_grader_count > 0:  # which actually means admin_grader_count == 1
                admin_provided_grades = admin_reviewer_grades[0]

        user_grades = {}
        if len(group_reviewer_ids) > 0:
            for reviewer_id in group_reviewer_ids:
                this_reviewers_grades = get_user_grade_value_list(reviewer_id)
                if this_reviewers_grades is None:
                    if admin_provided_grades:
                        this_reviewers_grades = admin_provided_grades
                    else:
                        return None
                user_grades[reviewer_id] = this_reviewers_grades
        elif admin_provided_grades:
            group_reviewer_ids = [self.user_id]
            user_grades[self.user_id] = admin_provided_grades
        else:
            return None

        # Okay, if we've got here we have a complete set of marks to calculate the grade
        reviewer_grades = [
            mean(user_grades[reviewer_id])
            for reviewer_id in group_reviewer_ids
            if len(user_grades[reviewer_id]) > 0
        ]
        group_grade = round(mean(reviewer_grades)) if len(reviewer_grades) > 0 else None

        return group_grade