Skip to content
Snippets Groups Projects
Commit 98e85030 authored by Anton Akhmerov's avatar Anton Akhmerov
Browse files

implement dataframe export

parent fe18d043
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,8 @@ api.add_resource(Feedback, '/feedback/<int:problem_id>')
# Other resources that don't return JSON
# It is possible to get flask_restful to work with these, but not
# very idiomatic.
# Images
api_bp.add_url_rule(
'/images/signature/<int:exam_id>/<int:submission_id>',
'signature',
......@@ -55,8 +57,14 @@ api_bp.add_url_rule(
summary_plot.get,
)
# Exports
api_bp.add_url_rule(
'/export/full',
'full_export',
export.full,
)
api_bp.add_url_rule(
'/export/dataframe/<int:exam_id>',
'dataframe_export',
export.dataframe,
)
......@@ -68,7 +68,10 @@ def solution_data(exam_id, student_id):
def full_exam_data(exam_id):
"""Compute all grades of an exam as a pandas DataFrame."""
with orm.db_session:
students = sorted(Exam[exam_id].submissions.student.id)
exam = Exam[exam_id]
if exam is None:
raise KeyError("No such exam.")
students = sorted(exam.submissions.student.id)
data = [solution_data(exam_id, student_id)
for student_id in students]
......
......@@ -21,3 +21,26 @@ def full():
resp.headers.set('Content-Disposition', 'attachment',
filename='course.sqlite')
return resp
def dataframe(exam_id):
"""Export exam data as a pandas dataframe
Parameters
----------
exam_id : int
Returns
-------
exam.pd : pickled pandas dataframe
"""
try:
data = db_helper.full_exam_data(exam_id)
except KeyError:
abort(404)
serialized = BytesIO()
data.to_pickle(serialized)
resp = Response(serialized.getvalue(), 200)
resp.headers.set('Content-Disposition', 'attachment',
filename='exam.pd')
return resp
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment