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

Slip Calculator Jobs for Assignment and Course #1148

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
logic for slip calculation
  • Loading branch information
epai committed May 4, 2017
commit 5d5e6a9b1d003e7210e46c5b631dc24bc584deab
8 changes: 5 additions & 3 deletions server/controllers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,15 +985,17 @@ def calculate_slips(cid, aid):
return abort(404)

form = forms.SlipCalculatorForm()
timescale = form.timescale.data.title()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest keeping the timescale lowercase, so it matches up with the TIMESCALES enum. And you won't need the .lower() on L16 in slips.py

if form.validate_on_submit():
print("submitted!")
job = jobs.enqueue_job(
slips.calculate_slips,
description='Calculate Slips for {}'.format(assign.display_name),
# timeout=600,
description='Calculate Slip {} for {}'.format(timescale, assign.display_name),
timeout=600,
course_id=cid,
# user_id=current_user.id,
# assign_id=assign.id,
assign_id=assign.id,
timescale=timescale,
# score=form.score.data,
# kind=form.kind.data,
# message=form.message.data,
Expand Down
25 changes: 23 additions & 2 deletions server/jobs/slips.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@


from server import jobs
from server.models import Assignment
from server.constants import TIMESCALES
from datetime import datetime as dt
from math import ceil

timescales = {'days':86400, 'hours':3600, 'minutes':60}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go in constants as TIMESCALES, so there's not both TIMESCALES and timescales that have the same keys

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this originally, but realized if I would then have to use the dictionary keys to fill in the form options, which wouldn't have a guaranteed ordering.

Now that I've thought about it, I think I'll just use an OrderedDict to preserve the ordering of the keys for display on the form.


def timediff(created, deadline, timescale):
secs_over = (created - deadline).total_seconds()
return ceil(secs_over / timescales[timescale.lower()])

@jobs.background_job
def calculate_slips():
def calculate_slips(assign_id, timescale):
logger = jobs.get_job_logger()
logger.info('hello world!')
job = jobs.get_current_job()

logger.info('Calculating slip {}...'.format(timescale))
assignment = Assignment.query.get(assign_id)
subms = assignment.course_submissions(include_empty=False)
deadline = assignment.due_date
for subm in subms:
email = subm['user']['email']
created = subm['backup']['created']
logger.info('{} {}'
.format(email, timediff(created, deadline, timescale)))