-
Notifications
You must be signed in to change notification settings - Fork 83
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
epai
wants to merge
11
commits into
master
Choose a base branch
from
enhancement/epai/slipdays
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b7d01a5
add slipcalc form
epai 9f0fe75
add link to calculate slips
epai d6cbe8c
setup basic job scaffold
epai 5d5e6a9
logic for slip calculation
epai 82c50fa
output csv string
epai a10376a
save csf file - complete assign route
epai 8ef25c9
Merge branch 'master' of https://github.com/Cal-CS-61A-Staff/ok
epai 28d916d
add course slips form
epai 4073666
fix validation errors
epai ddd9e40
cleaup function names
epai 0fab8ba
finish course slips job
epai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
output csv string
- Loading branch information
commit 82c50fa880b2a263d10f00fe436fff087dacf68a
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,50 @@ | ||
|
||
from datetime import datetime as dt | ||
import math | ||
import io | ||
import csv | ||
|
||
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} | ||
|
||
def timediff(created, deadline, timescale): | ||
secs_over = (created - deadline).total_seconds() | ||
return ceil(secs_over / timescales[timescale.lower()]) | ||
return math.ceil(secs_over / timescales[timescale.lower()]) | ||
|
||
def csv_data(header, rows): | ||
output = io.StringIO() | ||
writer = csv.writer(output, quoting=csv.QUOTE_NONNUMERIC) | ||
writer.writerow(header) | ||
[writer.writerow(row) for row in rows] | ||
return output.getvalue() | ||
|
||
@jobs.background_job | ||
def calculate_slips(assign_id, timescale): | ||
logger = jobs.get_job_logger() | ||
job = jobs.get_current_job() | ||
|
||
logger.info('Calculating slip {}...'.format(timescale)) | ||
|
||
logger.info('Calculating Slip {}...'.format(timescale.title())) | ||
|
||
assignment = Assignment.query.get(assign_id) | ||
subms = assignment.course_submissions(include_empty=False) | ||
deadline = assignment.due_date | ||
for subm in subms: | ||
|
||
def get_row(subm): | ||
email = subm['user']['email'] | ||
created = subm['backup']['created'] | ||
logger.info('{} {}' | ||
.format(email, timediff(created, deadline, timescale))) | ||
slips = min(0, timediff(created, deadline, timescale)) | ||
return [email, slips] | ||
|
||
header = ('User Email', 'Slip {} Used'.format(timescale.title())) | ||
rows = (get_row(subm) for subm in subms) | ||
data = csv_data(header, rows) | ||
|
||
logger.info(repr(data)) | ||
|
||
# upload = ExternalFile.upload(csv_data, user_id=1, course_id=1, | ||
# name='temp.okfile', prefix='jobs/example/') | ||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
asTIMESCALES
, so there's not bothTIMESCALES
andtimescales
that have the same keysThere was a problem hiding this comment.
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.