Example #1
0
def assignments_one(name):
    with DbCursor() as c:
        student = _get_student(c)
        user_id, _, _, login, _, _ = student
        assignment = get_assignment_by_name(name)

        if not assignment:
            abort(404)

        slipunits_now = slip_units_now(assignment.due_date)
        is_visible = now_compare(assignment.not_visible_before) >= 0
        if assignment.manual_grading:
            can_build = False
        else:
            can_build = now_compare(assignment.cannot_build_after) <= 0

        if not is_visible:
            abort(404)

        c.execute("SELECT score, slipunits, updated FROM grades WHERE user = ? AND assignment = ?",
                  [user_id, name])
        grade = c.fetchone()
        if not grade:
            grade = (None, None, None)
        if assignment.is_group:
            repos = get_groups(c, user_id)
        else:
            repos = [login]
        c.execute('''SELECT build_name, source, status, score, `commit`, message, started
                     FROM builds WHERE job = ? AND source IN (%s)
                     ORDER BY started DESC''' % (",".join(["?"] * len(repos))),
                  [name] + repos)
        builds = c.fetchall()
        if builds:
            most_recent_repo = builds[0][1]
        else:
            most_recent_repo = None
        if grade[0] is not None:
            c.execute('''SELECT COUNT(*) + 1 FROM grades WHERE assignment = ? AND score > ?''',
                      [name, grade[0]])
            rank, = c.fetchone()
        else:
            rank = None
        c.execute('''SELECT COUNT(*), AVG(score) FROM grades
                     WHERE assignment = ? AND score IS NOT NULL''', [name])
        stats = c.fetchone()
        if stats[0] == 0:
            variance = None
            stddev = None
        else:
            c.execute("SELECT AVG((score - ?) * (score - ?)) FROM grades WHERE assignment = ?",
                      [stats[1], stats[1], name])
            variance, = c.fetchone()
            stddev = sqrt(variance)

        assignment_info = ((assignment.name, assignment.full_score, assignment.weight,
                            assignment.due_date, assignment.category, assignment.is_group,
                            assignment.manual_grading) + grade + (rank,) + stats + (stddev,))
        template_common = _template_common(c)
    return render_template("dashboard/assignments_one.html",
                           assignment_info=assignment_info,
                           builds=builds,
                           repos=repos,
                           most_recent_repo=most_recent_repo,
                           slipunits_now=slipunits_now,
                           can_build=can_build,
                           **template_common)
Example #2
0
def assignments_one(name):
    with DbCursor() as c:
        student = _get_student(c)
        user_id, _, _, login, _, _ = student
        assignment = get_assignment_by_name(name)

        if not assignment:
            abort(404)

        slipunits_now = slip_units_now(assignment.due_date)
        is_visible = now_compare(assignment.not_visible_before) >= 0
        if assignment.manual_grading:
            can_build = False
        else:
            can_build = now_compare(assignment.cannot_build_after) <= 0

        if not is_visible:
            abort(404)

        c.execute(
            "SELECT score, slipunits, updated FROM grades WHERE user = ? AND assignment = ?",
            [user_id, name])
        grade = c.fetchone()
        if not grade:
            grade = (None, None, None)
        if assignment.is_group:
            repos = get_groups(c, user_id)
        else:
            repos = [login]
        c.execute(
            '''SELECT build_name, source, status, score, `commit`, message, started
                     FROM builds WHERE job = ? AND source IN (%s)
                     ORDER BY started DESC''' % (",".join(["?"] * len(repos))),
            [name] + repos)
        builds = c.fetchall()
        if builds:
            most_recent_repo = builds[0][1]
        else:
            most_recent_repo = None
        if grade[0] is not None:
            c.execute(
                '''SELECT COUNT(*) + 1 FROM grades WHERE assignment = ? AND score > ?''',
                [name, grade[0]])
            rank, = c.fetchone()
        else:
            rank = None
        c.execute(
            '''SELECT COUNT(*), AVG(score) FROM grades
                     WHERE assignment = ? AND score IS NOT NULL''', [name])
        stats = c.fetchone()
        if stats[0] == 0:
            variance = None
            stddev = None
        else:
            c.execute(
                "SELECT AVG((score - ?) * (score - ?)) FROM grades WHERE assignment = ?",
                [stats[1], stats[1], name])
            variance, = c.fetchone()
            stddev = sqrt(variance)

        assignment_info = (
            (assignment.name, assignment.full_score, assignment.weight,
             assignment.due_date, assignment.category, assignment.is_group,
             assignment.manual_grading) + grade + (rank, ) + stats +
            (stddev, ))
        template_common = _template_common(c)
    return render_template("dashboard/assignments_one.html",
                           assignment_info=assignment_info,
                           builds=builds,
                           repos=repos,
                           most_recent_repo=most_recent_repo,
                           slipunits_now=slipunits_now,
                           can_build=can_build,
                           **template_common)