Пример #1
0
    def evaluate(self, instance):
        """
        Evaluates the `questions` using the number of answers to it.

        Parameters
        ----------
        instance : Question | Student
            Question or Student to evaluate

        Returns
        -------
        float
            Reputation as evaluated by the criterion
        Dict[str, Any]
            Details about the calculation

        Raises
        ------
        TypeError
            If `instance` isn't of type Question or Student
        """
        super(NAnswersCriterion, self).evaluate(instance)
        if instance.__class__.__name__ == "Question":
            return instance.answer_set.count(), {}
        elif instance.__class__.__name__ == "Student":
            return instance.answers.count(), {}
        else:
            msg = "`question` has to be of type Question."
            logger.error("TypeError: {}".format(msg))
            raise TypeError(msg)
Пример #2
0
    def evaluate(self, instance):
        """
        Evaluates the how how often a students rationales are chosen by others.

        Parameters
        ----------
        instance : student
            student whose rationales are evaluated

        Returns
        -------
        float
            Reputation as evaluated by the criterion

        Raises
        ------
        TypeError
            If `instance` isn't of type Student
        """
        super(ConvincingRationalesCriterion, self).evaluate(instance)
        if instance.__class__.__name__ == "Student":
            return (
                instance.answers_chosen_by_others.count(),
                {
                    "times_shown": instance.answers_shown_to_others.count()
                },
            )
        else:
            msg = "`instance` has to be of type Student."
            logger.error("TypeError: {}".format(msg))
            raise TypeError(msg)
Пример #3
0
    def evaluate(self, teacher):
        """
        Evaluates the `teacher` using the number of rationale evaluations done.

        Parameters
        ----------
        teacher : Teacher
            Teacher to evaluate

        Returns
        -------
        float
            Reputation as evaluated by the criterion
        Dict[str, Any]
            Details about the calculation

        Raises
        ------
        TypeError
            If `instance` isn't of type Teacher
        """
        super(RationaleEvaluationCriterion, self).evaluate(teacher)
        if teacher.__class__.__name__ == "Teacher":
            return (
                teacher.user.answerannotation_set.filter(
                    score__isnull=False).count(),
                {},
            )
        else:
            msg = "`question` has to be of type Teacher."
            logger.error("TypeError: {}".format(msg))
            raise TypeError(msg)
Пример #4
0
    def evaluate(self, model):
        """
        Evaluates the reputation score of the given `model`. Classes inheriting
        must call the super method.

        Parameters
        ----------
        model : Model
            Model being evaluated. Must be in `for_reputation_types`

        Returns
        -------
        float
            Reputation as evaluated by the criterion

        Raises
        ------
        TypeError
            If the `model` isn't in the for_reputation_types
        """
        if not self.for_reputation_types.filter(
                type=model.__class__.__name__.lower()):
            msg = "The criterion {} isn't available ".format(
                str(self)) + "for reputation type {}.".format(
                    model.__class__.__name__.lower())
            logger.error(msg)
            raise TypeError(msg)
Пример #5
0
    def evaluate(self, teacher):
        """
        Evaluates the `teacher` using the number of questions composed.

        Parameters
        ----------
        teacher : Teacher
            Teacher to evaluate

        Returns
        -------
        float
            Reputation as evaluated by the criterion
        Dict[str, Any]
            Details about the calculation

        Raises
        ------
        TypeError
            If `teacher` isn't of type Teacher
        """
        super(NQuestionsCriterion, self).evaluate(teacher)
        if teacher.__class__.__name__ != "Teacher":
            msg = "`teacher` has to be of type Teacher."
            logger.error("TypeError: {}".format(msg))
            raise TypeError(msg)

        return teacher.user.question_set.count(), {}
Пример #6
0
    def evaluate(self, instance):
        """
        Evaluates the `question` using the number of teachers having liked it
        and using it. If `instance` is a teacher, sums over all their
        questions.

        Parameters
        ----------
        instance : Question | Teacher
            Question or Teacher to evaluate

        Returns
        -------
        float
            Reputation as evaluated by the criterion
        Dict[str, Any]
            Details about the calculation

        Raises
        ------
        TypeError
            If `instance` isn't of type Question or Teacher
        """
        super(QuestionLikedCriterion, self).evaluate(instance)
        if instance.__class__.__name__ == "Question":
            return self._evaluate_question(instance)
        elif instance.__class__.__name__ == "Teacher":
            question_evaluations = [
                self._evaluate_question(question, instance)
                for question in instance.user.question_set.all()
            ]
            if not question_evaluations:
                return 0, {}
            return (
                sum(evaluation[0] for evaluation in question_evaluations),
                {
                    key: [
                        evaluation[1][key]
                        for evaluation in question_evaluations
                    ]
                    for key in list(question_evaluations[0][1].keys())
                },
            )
        else:
            msg = "`question` has to be of type Question."
            logger.error("TypeError: {}".format(msg))
            raise TypeError(msg)
    def evaluate(self, student):
        """
        Evaluates the `student` using the evaluations given by teachers for
        their rationales. Score is calculated using the different scores in
        the model fields.

        Parameters
        ----------
        student : Student
            Student to evaluate

        Returns
        -------
        float
            Reputation as evaluated by the criterion
        Dict[str, Any]
            Details about the calculation

        Raises
        ------
        TypeError
            If `instance` isn't of type Question or Student
        """
        super(StudentRationaleEvaluationCriterion, self).evaluate(student)

        if student.__class__.__name__ == "Student":
            return (
                sum(
                    getattr(self, "points_score_{}".format(evaluation.score))
                    for answer in student.answers.all()
                    for evaluation in answer.answerannotation_set.filter(
                        score__isnull=False).all()),
                {},
            )
        else:
            msg = "`question` has to be of type Student."
            logger.error("TypeError: {}".format(msg))
            raise TypeError(msg)