Exemplo n.º 1
0
Arquivo: app.py Projeto: dlsun/ohms
def rate():
    user = validate_user()
    question_id = request.args.get("id")
    tasks = get_peer_tasks_for_student(question_id, user.stuid)
    tasks = [t for t in tasks if t.score is not None]
    return render_template("rate.html",
                           grading_tasks=tasks,
                           options=options)
Exemplo n.º 2
0
Arquivo: app.py Projeto: flywind2/ohms
def update_hw_grades(user, homeworks):
    """ 
    helper function that computes user's grades on homeworks, 
    returns a list of uncompleted peer reviews
    """

    # keep track of to-do list for peer reviews
    to_do = defaultdict(int)
    # keep track of the peer review corresponding to each question
    prq_map = {}
    for prq in get_peer_review_questions():
        prq.set_metadata()
        prq_map[prq.question_id] = prq

    for hw in homeworks:

        # skip if homework not due yet
        if hw.due_date > pdt_now():
            continue

        # iterate over questions
        for q in hw.questions:

            # check if q is a question that is peer-reviewed
            if q.id in prq_map:

                # if grading tasks haven't been assigned
                if not get_all_peer_tasks(q.id):

                    # get corresponding Peer Review object, instantiate with data from XML
                    prq = prq_map[q.id]

                    # get list of all students who responded, then shuffle
                    responders = [
                        r.stuid for r in get_all_responses_to_question(q.id)
                    ]
                    import random
                    random.seed(q.id)
                    random.shuffle(responders)

                    # import engine
                    from base import engine

                    # assign peer grading tasks, if applicable
                    # (self grading tasks are assigned individually, on the fly)
                    tasks = []
                    m, n = len(prq.peer_pts), len(responders)
                    for i, stuid in enumerate(responders):
                        for offset in [
                                k * (k + 1) / 2 for k in range(1, m + 1)
                        ]:
                            j = (i + offset) % n
                            tasks.append({
                                "grader": stuid,
                                "student": responders[j],
                                "question_id": q.id
                            })
                    engine.execute(GradingTask.__table__.insert(), tasks)

            # if question itself is a peer review question
            elif isinstance(q, PeerReview):
                # compute updated score for student
                response = get_last_question_response(q.question_id,
                                                      user.stuid)
                if response:
                    tasks = get_peer_tasks_for_student(q.question_id,
                                                       user.stuid)
                    scores = [t.score for t in tasks if t.score is not None]
                    new_score = sorted(scores)[len(scores) //
                                               2] if scores else None
                    if response.score is None:
                        response.score = new_score
                        response.comments = "Click <a href='rate?id=%d' target='_blank'>here</a> to view comments." % q.question_id
                    # check that student has rated all the peer reviews
                    for task in tasks:
                        if task.score is not None and task.rating is None:
                            to_do[response.question.homework] += 1

        # update student's grade on the homework
        calculate_grade(user, hw)

    return to_do
Exemplo n.º 3
0
Arquivo: app.py Projeto: flywind2/ohms
def rate():
    user = validate_user()
    question_id = request.args.get("id")
    tasks = get_peer_tasks_for_student(question_id, user.stuid)
    tasks = [t for t in tasks if t.score is not None]
    return render_template("rate.html", grading_tasks=tasks, options=options)
Exemplo n.º 4
0
Arquivo: app.py Projeto: dlsun/ohms
def update_hw_grades(user, homeworks):
    """ 
    helper function that computes user's grades on homeworks, 
    returns a list of uncompleted peer reviews
    """

    # keep track of to-do list for peer reviews
    to_do = defaultdict(int)
    # keep track of the peer review corresponding to each question
    prq_map = {}
    for prq in get_peer_review_questions():
        prq.set_metadata()
        prq_map[prq.question_id] = prq

    for hw in homeworks:

        # skip if homework not due yet
        if hw.due_date > pdt_now():
            continue

        # iterate over questions
        for q in hw.questions:

            # check if q is a question that is peer-reviewed
            if q.id in prq_map:

                # if grading tasks haven't been assigned
                if not get_all_peer_tasks(q.id):
                
                    # get corresponding Peer Review object, instantiate with data from XML
                    prq = prq_map[q.id]

                    # get list of all students who responded, then shuffle
                    responders = [r.stuid for r in get_all_responses_to_question(q.id)]
                    import random
                    random.seed(q.id)
                    random.shuffle(responders)

                    # import engine
                    from base import engine

                    # assign peer grading tasks, if applicable
                    # (self grading tasks are assigned individually, on the fly)
                    tasks = []
                    m, n = len(prq.peer_pts), len(responders)
                    for i, stuid in enumerate(responders):
                        for offset in [k*(k+1)/2 for k in range(1, m+1)]:
                            j = (i + offset) % n
                            tasks.append({"grader": stuid, "student": responders[j], "question_id": q.id})
                    engine.execute(GradingTask.__table__.insert(), tasks)

            # if question itself is a peer review question
            elif isinstance(q, PeerReview):
                # compute updated score for student
                response = get_last_question_response(q.question_id, user.stuid)
                if response:
                    tasks = get_peer_tasks_for_student(q.question_id, user.stuid)
                    scores = [t.score for t in tasks if t.score is not None]
                    new_score = sorted(scores)[len(scores) // 2] if scores else None
                    if response.score is None:
                        response.score = new_score
                        response.comments = "Click <a href='rate?id=%d' target='_blank'>here</a> to view comments." % q.question_id
                    # check that student has rated all the peer reviews
                    for task in tasks:
                        if task.score is not None and task.rating is None:
                            to_do[response.question.homework] += 1

        # update student's grade on the homework
        calculate_grade(user, hw)

    return to_do