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

more useful user feedback for errors #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
52 changes: 31 additions & 21 deletions gofer_nb.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,30 +138,31 @@ async def post(self):
"""Accept notebook submissions, saves, then grades them"""
user = self.get_current_user()
req_data = tornado.escape.json_decode(self.request.body)
timestamp = str(time.time())
# in the future, assignment should be metadata in notebook
notebook = req_data['nb']
section = notebook['metadata']['section']
try:
assignment = notebook['metadata']['assignment']
except:
assignment = notebook['metadata']['lab']

try:
course = notebook['metadata']['course']
notebook = req_data['nb']
section = notebook['metadata']['section']
try:
assignment = notebook['metadata']['assignment']
except:
assignment = notebook['metadata']['lab']

try:
course = notebook['metadata']['course']
except:
course = "8x"

# save notebook submission with user id and time stamp
submission_file = "/home/vipasu/gofer_service/submissions/{}_{}_{}_{}.ipynb".format(user['name'], section, assignment, timestamp)
except:
course = "8x"

logErrorCSV(timestamp, user['name'], section, assignment, traceback.format_exc())
self.write("Error in notebook metadata. Please redownload your notebook.")
self.finish()

timestamp = str(time.time())
# save notebook submission with user id and time stamp
submission_file = "/home/vipasu/gofer_service/submissions/{}_{}_{}_{}.ipynb".format(user['name'], section, assignment, timestamp)
with open(submission_file, 'w') as outfile:
json.dump(notebook, outfile)

# Let user know their submission was received
self.write("User submission has been received. Grade will be posted to the gradebook once it's finished running!")
self.finish()

try:
# Grade assignment
grade = await grade_assignment(submission_file, section, assignment)
Expand All @@ -171,6 +172,9 @@ async def post(self):
write_grade(grade_info)
except:
logErrorCSV(timestamp, user['name'], section, assignment, traceback.format_exc())
self.write("Error in grading assignment. Please wait a minute and resubmit. If the problem \
persists, please contact support.")
self.finish()

# post grade to EdX
with open('/home/vipasu/x19_config.json', 'r') as fname:
Expand All @@ -185,10 +189,16 @@ async def post(self):
await post_grade(user['name'], grade,
course_config[course]["sourcedid"][section][assignment],
course_config[course]["outcomes_url"][section][assignment])
except GradePostException as e:
logErrorCSV(timestamp, user['name'], section, assignment, str(e.response) + "\n" + traceback.format_exc())
except:
logErrorCSV(timestamp, user['name'], section, assignment, traceback.format_exc())
except Exception as e:
errmsg = str(e.response) if type(e) is GradePostException else '' + "\n" + traceback.format_exc()
logErrorCSV(timestamp, user['name'], section, assignment, errmsg)
self.write("Error in posting grade. Please wait a minute and resubmit. If the problem \
persists, please contact support.")
self.finish()

# Let user know their submission was received
self.write("User submission has been received and graded. Grade will be posted to the gradebook!")
self.finish()

def logErrorCSV(timestamp, username, section, assignment, msg):
try:
Expand Down