Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
zesje
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Réouven ASSOULY
zesje
Commits
98e85030
Commit
98e85030
authored
7 years ago
by
Anton Akhmerov
Browse files
Options
Downloads
Patches
Plain Diff
implement dataframe export
parent
fe18d043
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
zesje/api.py
+8
-0
8 additions, 0 deletions
zesje/api.py
zesje/helpers/db_helper.py
+4
-1
4 additions, 1 deletion
zesje/helpers/db_helper.py
zesje/resources/export.py
+23
-0
23 additions, 0 deletions
zesje/resources/export.py
with
35 additions
and
1 deletion
zesje/api.py
+
8
−
0
View file @
98e85030
...
...
@@ -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
,
)
This diff is collapsed.
Click to expand it.
zesje/helpers/db_helper.py
+
4
−
1
View file @
98e85030
...
...
@@ -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
]
...
...
This diff is collapsed.
Click to expand it.
zesje/resources/export.py
+
23
−
0
View file @
98e85030
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment