Skip to content

Commit

Permalink
ADD Functions for regrading by student
Browse files Browse the repository at this point in the history
  • Loading branch information
dolf321 committed May 22, 2023
1 parent b6ae400 commit 15a8cd6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
47 changes: 47 additions & 0 deletions api/anubis/lms/regrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,53 @@
from anubis.models import Submission, Assignment
from anubis.utils.data import with_context, split_chunks

# Regrade all assignment based of a student with a user id
@with_context
def bulk_regrade_assignment_of_student(
user_id: str,
hours: int = -1,
not_processed: int = -1,
processed: int = -1,
reaped: int = -1,
latest_only: int = -1,
):
# Check if the user is a student

# Fetch all submisions of a user
from anubis.lms.submissions import get_latest_user_submissions_by_user

# Build a list of filters based on the options
filters = []
if latest_only <= 1:

# Number of hours back to regrade
if hours > 0:
filters.append(Submission.created > datetime.now() - timedelta(hours=hours))

# Only regrade submissions that have been processed
if processed == 1:
filters.append(Submission.processed == True)

# Only regrade submissions that have not been processed
if not_processed == 1:
filters.append(Submission.processed == False)

# Only regrade submissions that have been reaped
if reaped == 1:
filters.append(Submission.state == "Reaped after timeout")

submissions = get_latest_user_submissions_by_user(user_id, filter=filters)

# Split the submissions into bite sized chunks
submission_ids = [s.id for s in submissions]
submission_chunks = split_chunks(submission_ids, 100)

from anubis.rpc.enqueue import enqueue_bulk_regrade_submissions

# Enqueue each chunk as a job for the rpc workers
for chunk in submission_chunks:
enqueue_bulk_regrade_submissions(chunk)


@with_context
def bulk_regrade_assignment(
Expand Down
7 changes: 7 additions & 0 deletions api/anubis/lms/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,13 @@ def get_latest_user_submissions(assignment: Assignment, user: User, limit: int =
*filter
).order_by(Submission.created.desc()).limit(limit).all()

def get_latest_user_submissions_by_user(user: User, limit: int = 3, filter: list = None) -> list[Submission]:
filter = filter or []
return Submission.query.filter(
Submission.owner_id == user.id,
*filter
).order_by(Submission.created.desc()).limit(limit).all()


def fix_submissions_for_autograde_disabled_assignment(assignment: Assignment):
if assignment.autograde_enabled or assignment.shell_autograde_enabled:
Expand Down

0 comments on commit 15a8cd6

Please sign in to comment.