def reputation_pipeline( **kwargs): if kwargs['is_new']: github_token = kwargs['social_user'].extra_data['access_token'] reputation_points = generate_reputation_points(github_token) r = Reputation(reputation = reputation_points, user = kwargs['user']) r.save()
def evaluate_reputation(self, criterion=None): """ Calculates the reputation for the student on all criteria or on a specific criterion, creating the Reputation for them if it doesn't already exist. Parameters ---------- criterion : Optional[str] (default : none) Criterion on which to evaluate Returns ------- float Evaluated reputation Raises ------ ValueError If the given criterion isn't part of the list for this reputation type """ if self.reputation is None: self.reputation = Reputation.create("student") self.save() return self.reputation.evaluate(criterion)[0]
def get_teacher_information(req): args = get_query_string_params(req, args=["id"]) if isinstance(args, HttpResponse): return args (id_, ), _ = args try: teacher = Teacher.objects.get(pk=id_) except Teacher.DoesNotExist: return response_400( req, msg=translate("There is no teacher with that id"), logger_msg=("Teacher with pk {} couldn't be found.".format(id_)), log=logger.warning, ) if teacher.reputation is None: teacher.reputation = Reputation.create(teacher) _, reputations = teacher.reputation.evaluate() data = { "username": teacher.user.username, "last_login": teacher.user.last_login.strftime("%Y-%m-%d %H:%M:%S") if teacher.user.last_login is not None else None, "reputations": [{ "name": reputation["name"], "reputation": reputation["reputation"], } for reputation in reputations], } return JsonResponse(data)
def test_create__object_passed(question, assignment, teacher): for cls in (question, assignment, teacher): reputation = Reputation.create(cls) assert isinstance(reputation, Reputation) assert ( reputation.reputation_type.type == cls.__class__.__name__.lower() )
def convincing_rationale_reputation(self): if self.reputation is None: self.reputation = Reputation.create("student") self.save() return self.reputation.evaluate("convincing_rationales")[0]
def test_create__wrong_type(): with pytest.raises(ReputationType.DoesNotExist): reputation = Reputation.create("StudentAssignment")
def test_create__str_passed(): for cls in ("Question", "Assignment", "Teacher"): reputation = Reputation.create(cls) assert isinstance(reputation, Reputation) assert reputation.reputation_type.type == cls.lower()