Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
problem-builder
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
problem-builder
Commits
1a6a5cd9
Commit
1a6a5cd9
authored
Jan 13, 2014
by
Xavier Antoviaque
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify CSV export processing by using `itertools.groupby()`
parent
6fc5aa7c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
15 deletions
+18
-15
mentoring/dataexport.py
+18
-15
No files found.
mentoring/dataexport.py
View file @
1a6a5cd9
...
...
@@ -25,6 +25,7 @@
import
logging
from
itertools
import
groupby
from
webob
import
Response
from
xblock.core
import
XBlock
from
xblock.fragment
import
Fragment
...
...
@@ -75,20 +76,22 @@ class MentoringDataExportBlock(XBlock):
# Header line
yield
list2csv
([
u'student_id'
]
+
list
(
answers_names
))
row
=
[]
cur_student_id
=
None
cur_col
=
None
for
answer
in
answers
:
if
answer
.
student_id
!=
cur_student_id
:
if
answers_names
:
for
k
,
student_answers
in
groupby
(
answers
,
lambda
x
:
x
.
student_id
):
row
=
[]
next_answer_idx
=
0
for
answer
in
student_answers
:
if
not
row
:
row
=
[
answer
.
student_id
]
while
answer
.
name
!=
answers_names
[
next_answer_idx
]:
# Still add answer row to CSV when they don't exist in DB
row
.
append
(
''
)
next_answer_idx
+=
1
row
.
append
(
answer
.
student_input
)
next_answer_idx
+=
1
if
row
:
yield
list2csv
(
row
)
row
=
[
answer
.
student_id
]
cur_student_id
=
answer
.
student_id
cur_col
=
0
while
answer
.
name
!=
answers_names
[
cur_col
]:
row
.
append
(
''
)
cur_col
+=
1
row
.
append
(
answer
.
student_input
)
cur_col
+=
1
if
row
:
yield
list2csv
(
row
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment