Esempio n. 1
0
    def to_html(self):

        # not good to have imports here...
        from queries import get_question, get_last_question_response, get_peer_tasks_for_grader, get_self_tasks_for_student 
        from auth import validate_user
        self.set_metadata()
        user = validate_user()
        if user.type == "guest":
            return "Sorry, but only students can view peer assessment questions."

        vars = {"question": get_question(self.question_id)}

        # if peer assessment was assigned
        if len(self.peer_pts):
            peer_tasks = get_peer_tasks_for_grader(self.question_id, user.stuid)
            vars['peer_responses'] = [get_last_question_response(self.question_id, task.student) for task in peer_tasks]

        # if self assessment was assigned
        if self.self_pts is not None:
            # add the task if it hasn't been already
            response = get_last_question_response(self.question_id, user.stuid)
            if response and not get_self_tasks_for_student(self.question_id, user.stuid):
                session.add(GradingTask(grader=user.stuid, 
                                        student=user.stuid, 
                                        question_id=self.question_id))
                session.commit()
            vars['self_response'] = response

        # jinja2 to get template for peer review questions
        from jinja2 import Environment, PackageLoader
        env = Environment(autoescape=True, loader=PackageLoader("ohms", "templates"))
        template = env.get_template("peer_review_question.html")

        return template.render(**vars)
Esempio n. 2
0
    def submit_response(self, stuid, responses):

        from queries import get_peer_tasks_for_grader, get_self_tasks_for_student
        self.set_metadata()

        if pdt_now() <= self.homework.due_date:

            # helper function that validates and then updates a task
            def check_and_update_task(task):
                if task.grader != stuid:
                    raise Exception("You are not authorized to grade this response.")
                try:
                    assert(0 <= float(responses[2*i]) <= task.question.points)
                except:
                    raise Exception("Please enter a score between %f and %f." % (0, task.question.points))
                if not responses[2*i+1].strip():
                    raise Exception("Please enter comments for all responses.")

                task.time = pdt_now()
                task.score = responses[2*i]
                task.comments = responses[2*i+1]

                return task

            i = 0
            score = 0.

            # peer tasks should be first
            while i < len(self.peer_pts):
                tasks = get_peer_tasks_for_grader(self.question_id, stuid)
                task = check_and_update_task(tasks[i])
                if task.comments is not None: score += self.peer_pts[i]
                i += 1

            # then we have self tasks
            if self.self_pts is not None:
                tasks = get_self_tasks_for_student(self.question_id, stuid)
                if tasks:
                    task = check_and_update_task(tasks[0])
                    if task.comments is not None: score += self.self_pts

            comments = "Watch this space for your peers' judgment of your feedback. "
            if self.rate_pts:
                comments += "Your peers' judgment is worth %f points, so you cannot earn all %s points yet." % (self.rate_pts, self.points)

            session.commit()
            
            return {
                'locked': (pdt_now() > self.homework.due_date),
                'submission': QuestionResponse(
                    time=pdt_now(),
                    score=score,
                    comments=comments
                    )
            }

        else:
            raise Exception("The deadline for submitting this homework has passed.")
Esempio n. 3
0
    def load_response(self, user):

        from queries import get_peer_tasks_for_grader, get_self_tasks_for_student
        self.set_metadata()

        item_responses = []
        score = 0.
        time = None
        comment = ""

        # get peer tasks
        if len(self.peer_pts):
            tasks = get_peer_tasks_for_grader(self.question_id, user.stuid)
            ratings = []
            for i, task in enumerate(tasks):
                # each review is a score + response; we represent each review as two items
                item_responses.extend([ItemResponse(response=task.score), ItemResponse(response=task.comments)])
                if task.rating is not None: ratings.append(task.rating)
                if task.comments is not None: score += self.peer_pts[i]
                time = task.time
            if len(ratings) > 1:
                median = sorted(ratings)[len(ratings) // 2] - 1.
                score += self.rate_pts * median / 3.
                comment = "%d peers have responded to your feedback. " % len(ratings)
                if median == 3:
                    comment += "They were satisfied overall with the quality of your feedback."
                elif median == 2:
                    comment += "Your feedback was good, but some felt that it could have been better."
                elif median <= 1:
                    comment += "Your peers found your feedback unsatisfactory. Please see a member of the course staff to discuss strategies to improve."
            elif score:
                comment = "Watch this space for your peers' rating of your feedback. "
                if self.rate_pts:
                    comment += "Your peers' ratings count for %s points, so you cannot earn all %s points yet." % (self.rate_pts, self.points)

        # get self tasks
        if self.self_pts is not None:
            # there should really only be one task, but....
            tasks = get_self_tasks_for_student(self.question_id, user.stuid)
            if tasks:
                item_responses.extend([ItemResponse(response=tasks[0].score), ItemResponse(response=tasks[0].comments)])
                if tasks[0].comments is not None: score += self.self_pts
                time = tasks[0].time

        return {
            "locked": (pdt_now() > self.homework.due_date),
            "submission": QuestionResponse(
                item_responses=item_responses,
                score=score,
                comments=comment,
                time=time
            )
        }