示例#1
0
文件: __init__.py 项目: octobear2/ob2
def builds(page):
    page_size = 50
    page = max(1, page)
    with DbCursor() as c:
        student = _get_student(c)
        user_id, _, _, login, _, _ = student
        group_repos = get_groups(c, user_id)
        repos = [login] + group_repos
        c.execute('''SELECT build_name, source, status, score, `commit`, message, job, started
                     FROM builds WHERE source in (%s)
                     ORDER BY started DESC LIMIT ? OFFSET ?''' % (",".join(["?"] * len(repos))),
                  repos + [page_size + 1, (page - 1) * page_size])
        builds = c.fetchall()
        if not builds and page > 1:
            abort(404)
        more_pages = len(builds) == page_size + 1
        if more_pages:
            builds = builds[:-1]
        full_scores = {assignment.name: assignment.full_score
                       for assignment in config.assignments}
        builds_info = (build + (full_scores.get(build[6]),) for build in builds)
        template_common = _template_common(c)
    return render_template("dashboard/builds.html",
                           builds_info=builds_info,
                           page=page,
                           more_pages=more_pages,
                           **template_common)
示例#2
0
文件: __init__.py 项目: samkumar/ob2
def builds(page):
    page_size = 50
    page = max(1, page)
    with DbCursor() as c:
        student = _get_student(c)
        user_id, _, _, login, _, _ = student
        group_repos = get_groups(c, user_id)
        repos = [login] + group_repos
        c.execute(
            '''SELECT build_name, source, status, score, `commit`, message, job, started
                     FROM builds WHERE source in (%s)
                     ORDER BY started DESC LIMIT ? OFFSET ?''' %
            (",".join(["?"] * len(repos))),
            repos + [page_size + 1, (page - 1) * page_size])
        builds = c.fetchall()
        if not builds and page > 1:
            abort(404)
        more_pages = len(builds) == page_size + 1
        if more_pages:
            builds = builds[:-1]
        full_scores = {
            assignment.name: assignment.full_score
            for assignment in config.assignments
        }
        builds_info = (build + (full_scores.get(build[6]), )
                       for build in builds)
        template_common = _template_common(c)
    return render_template("dashboard/builds.html",
                           builds_info=builds_info,
                           page=page,
                           more_pages=more_pages,
                           **template_common)
示例#3
0
def build_now():
    job_name = request.form.get("f_job_name")
    repo = request.form.get("f_repo")
    assignment = get_assignment_by_name(job_name)
    if not assignment:
        abort(400)
    assignment = assignment.student_view(repo)
    if assignment.manual_grading:
        abort(400)

    with DbCursor() as c:
        student = _get_student(c)
        user_id, _, _, login, _, _ = student
        super_value = get_super(c, user_id)
        dropped = super_value is not None and super_value < 0
        if assignment.is_group:
            repos = get_groups(c, user_id)
        else:
            repos = [login]

        if repo not in repos:
            abort(403)

    if now_compare(assignment.not_visible_before,
                   add_grace_period(
                       assignment.cannot_build_after)) != 0 or dropped:
        abort(400)

    branch_hash = get_branch_hash(repo, "master")
    message = None
    if branch_hash:
        message = get_commit_message(repo, branch_hash)

    # This section doesn't absolutely NEED to be consistent with the previous transaction,
    # since we have not specified any actual data constraints. The only possible logical error
    # would be to fulfill a request when the current user's permissions have been revoked
    # between these two transactions.
    with DbCursor() as c:
        build_name = create_build(c, job_name, repo, branch_hash, message)

    if should_limit_source(repo, job_name):
        rate_limit_fail_build(build_name)
    else:
        job = Job(build_name, repo, "Web interface")
        dockergrader_queue.enqueue(job)

    return redirect(url_for("dashboard.builds_one", name=build_name))
示例#4
0
文件: __init__.py 项目: octobear2/ob2
def builds_one(name):
    with DbCursor() as c:
        student = _get_student(c)
        user_id, _, _, login, _, _ = student
        group_repos = get_groups(c, user_id)
        repos = [login] + group_repos
        c.execute('''SELECT build_name, status, score, source, `commit`, message, job, started,
                     log FROM builds WHERE build_name = ? AND source in (%s)
                     LIMIT 1''' % (",".join(["?"] * len(repos))),
                  [name] + repos)
        build = c.fetchone()
        if not build:
            abort(404)
        build_info = build + (get_assignment_by_name(build[6]).full_score,)
        template_common = _template_common(c)
    return render_template("dashboard/builds_one.html",
                           build_info=build_info,
                           **template_common)
示例#5
0
文件: __init__.py 项目: samkumar/ob2
def builds_one(name):
    with DbCursor() as c:
        student = _get_student(c)
        user_id, _, _, login, _, _ = student
        group_repos = get_groups(c, user_id)
        repos = [login] + group_repos
        c.execute(
            '''SELECT build_name, status, score, source, `commit`, message, job, started,
                     log FROM builds WHERE build_name = ? AND source in (%s)
                     LIMIT 1''' % (",".join(["?"] * len(repos))),
            [name] + repos)
        build = c.fetchone()
        if not build:
            abort(404)
        build_info = build + (get_assignment_by_name(build[6]).full_score, )
        template_common = _template_common(c)
    return render_template("dashboard/builds_one.html",
                           build_info=build_info,
                           **template_common)
示例#6
0
文件: __init__.py 项目: octobear2/ob2
def build_now():
    job_name = request.form.get("f_job_name")
    repo = request.form.get("f_repo")
    assignment = get_assignment_by_name(job_name)
    if not assignment:
        abort(400)
    if assignment.manual_grading:
        abort(400)
    if now_compare(assignment.not_visible_before, assignment.cannot_build_after) != 0:
        abort(400)

    with DbCursor() as c:
        student = _get_student(c)
        user_id, _, _, login, _, _ = student
        if assignment.is_group:
            repos = get_groups(c, user_id)
        else:
            repos = [login]

        if repo not in repos:
            abort(403)

    branch_hash = get_branch_hash(repo, "master")
    message = None
    if branch_hash:
        message = get_commit_message(repo, branch_hash)

    # This section doesn't absolutely NEED to be consistent with the previous transaction,
    # since we have not specified any actual data constraints. The only possible logical error
    # would be to fulfill a request when the current user's permissions have been revoked
    # between these two transactions.
    with DbCursor() as c:
        build_name = create_build(c, job_name, repo, branch_hash, message)

    job = Job(build_name, repo, "Web interface")
    dockergrader_queue.enqueue(job)

    return redirect(url_for("dashboard.builds_one", name=build_name))
示例#7
0
文件: __init__.py 项目: octobear2/ob2
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)
示例#8
0
文件: __init__.py 项目: samkumar/ob2
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)