Last active
July 28, 2020 00:14
-
-
Save austintraver/df4eeddb7e2fb4ba553730e5a2f28ebe to your computer and use it in GitHub Desktop.
Grading script for CSCI 201 HW #2
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
from sys import argv | |
from subprocess import run | |
import datetime | |
import re | |
origin = None | |
index = 0 | |
easy=[ | |
0, | |
1.2, | |
3, | |
4, | |
5.2, | |
8, | |
9.6, | |
10, | |
13.4, | |
16, | |
16.6, | |
18, | |
22.6, | |
24.4, | |
24.4, | |
30.8 | |
] | |
sametime=[ | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
1.2, | |
1.2, | |
5.4, | |
6.4, | |
6.4, | |
6.6, | |
6.6, | |
6.6, | |
12.8 | |
] | |
hard=[ | |
0, | |
1, | |
1.2, | |
2, | |
3, | |
3.2, | |
4, | |
5, | |
6, | |
7.6, | |
8.4, | |
10.6, | |
11.6, | |
12.4, | |
60, | |
66.4 | |
] | |
# User input in the form of a command line argument | |
# determines which array should be used | |
offset = None | |
if argv[1] == 'easy': | |
offset = easy | |
elif argv[1] == 'hard': | |
offset = hard | |
elif argv[1] == 'sametime': | |
offset = sametime | |
else: | |
raise Exception("invalid test case") | |
# Compile a regular expression pattern to capture the timestamps | |
pattern = re.compile(r'([0-9:]+)') | |
# Take the contents of the clipboard, save it into "log" | |
# Note to CPs, this is where input is (currently) being | |
# captured from, copy student timestamp log data to your clipboard | |
program = run(args=['pbpaste'], capture_output=True) | |
log = program.stdout.decode().split('\n') | |
# Parse through each line with a timestamp from the student's output file | |
for line in log: | |
# Skip blank lines | |
if len(line.strip()) == 0: | |
continue | |
# Get the current line from stdin | |
match = pattern.search(line) | |
# Convert it into a timestamp | |
t = match.group(1).split(':') | |
logged_time = datetime.datetime(2020, 3, 29, int(t[0]), int(t[1]), int(t[2])) | |
delta = datetime.timedelta(milliseconds=int(offset[index]*1000)) | |
# Set the start-time if currently unset | |
if origin == None: | |
origin = logged_time | |
correct_time = origin + delta | |
threshold = datetime.timedelta(seconds=1) | |
if not (correct_time - threshold < logged_time < correct_time + threshold): | |
print('---') | |
print(f'index: {index}') | |
print(f"Deduction: logged_time is {logged_time}") | |
print(f" logged_time should be{correct_time}") | |
print('---') | |
# Increment the index |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment