Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add runallcheckers command #351

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,18 @@ detection program [jPlag](https://jplag.ipd.kit.edu/). Do enable this support, y
* Copy the resulting `.jar` file somewhere on the Praktomat server.
* In the settings, set `JPLAGJAR = /full/path/to/jplag.jar`

Automating the execution of checkers
=================

To automatically run all checkers for expired tasks where not all checkers are finished yet,
there is a command called `runallcheckers`:
```bash
./Praktomat/src/manage-local.py runallcheckers
```

Use Cron (or something similar) to automate the execution of this command.
Tutors can then automatically start attesting solutions without the need of
an admin or trainer to manually run all checkers after a task expired.

PhpBB integration
=================
Expand Down
15 changes: 15 additions & 0 deletions src/checker/management/commands/runallcheckers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.core.management.base import BaseCommand
from tasks.models import Task

class Command(BaseCommand):
help = 'Run all checkers for expired tasks where not all checkers are finished.'

def handle(self, *args, **options):
for task in Task.objects.filter(all_checker_finished = False):
if not task.expired():
continue

self.stdout.write('Running all checkers for "%s"\n' % task.title)
task.check_all_final_solutions()
task.check_all_latest_only_failed_solutions()
self.stdout.write('Done')
17 changes: 1 addition & 16 deletions src/tasks/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,10 @@ def run_all_checkers_on_finals(self, request, queryset):

def run_all_checkers_on_latest_only_failed(self,request, queryset):
""" Rerun all checker on latest of only failed solutions including "not always" action """
from checker.basemodels import check_solution
from accounts.models import User
start = timer()
count = 0
for task in queryset:
solution_queryset = task.solution_set
final_solutions_queryset = solution_queryset.filter(final=True)
finalusers = list(set(final_solutions_queryset.values('author').values_list('author', flat=True)))
only_failed_solution_set = solution_queryset.exclude(author__in=finalusers)

nonfinalusers = list( set(User.objects.all().values('id').values_list('id',flat=True)) - set(finalusers))

for user in User.objects.filter(id__in=nonfinalusers) :
users_only_failed_solution = only_failed_solution_set.filter(author=user).order_by('author','number')
ucount = int(users_only_failed_solution.count())
if ucount :
latest_only_failed_solution=users_only_failed_solution.latest('number')
check_solution(latest_only_failed_solution,True)
count += 1
count += task.check_all_latest_only_failed_solutions()
end = timer()
self.message_user(request, "%d users with only failed solutions were checked (%d seconds elapsed)." % (count, end-start))
run_all_checkers_on_latest_only_failed.short_description = "recheck only latest failed (Admin)"
Expand Down
21 changes: 21 additions & 0 deletions src/tasks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,27 @@ def check_all_final_solutions(self):
self.save()
return final_solutions.count()

def check_all_latest_only_failed_solutions(self):
from checker.basemodels import check_solution
from accounts.models import User
solution_queryset = self.solution_set
final_solutions_queryset = solution_queryset.filter(final=True)
final_users = set(final_solutions_queryset.values_list('author', flat=True))

# All solutions from users without a final solution
only_failed_solution_set = solution_queryset.exclude(author__in=final_users)
# Users without a final solution (maybe without an upload at all)
non_final_users = set(User.objects.all().values_list('id', flat=True)) - final_users

count = 0
for user in non_final_users:
users_only_failed_solutions = only_failed_solution_set.filter(author=user)
if users_only_failed_solutions.count() > 0:
latest_only_failed_solution = users_only_failed_solutions.latest('number')
check_solution(latest_only_failed_solution, True)
count += 1
return count

def get_checkers(self):
from checker.basemodels import Checker
checker_app = apps.get_app_config('checker')
Expand Down