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
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
11 deletions
+14
-11
mentoring/dataexport.py
+14
-11
No files found.
mentoring/dataexport.py
View file @
1a6a5cd9
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
import
logging
import
logging
from
itertools
import
groupby
from
webob
import
Response
from
webob
import
Response
from
xblock.core
import
XBlock
from
xblock.core
import
XBlock
from
xblock.fragment
import
Fragment
from
xblock.fragment
import
Fragment
...
@@ -75,20 +76,22 @@ class MentoringDataExportBlock(XBlock):
...
@@ -75,20 +76,22 @@ class MentoringDataExportBlock(XBlock):
# Header line
# Header line
yield
list2csv
([
u'student_id'
]
+
list
(
answers_names
))
yield
list2csv
([
u'student_id'
]
+
list
(
answers_names
))
if
answers_names
:
for
k
,
student_answers
in
groupby
(
answers
,
lambda
x
:
x
.
student_id
):
row
=
[]
row
=
[]
cur_student_id
=
None
next_answer_idx
=
0
cur_col
=
None
for
answer
in
student_answers
:
for
answer
in
answers
:
if
not
row
:
if
answer
.
student_id
!=
cur_student_id
:
if
row
:
yield
list2csv
(
row
)
row
=
[
answer
.
student_id
]
row
=
[
answer
.
student_id
]
cur_student_id
=
answer
.
student_id
cur_col
=
0
while
answer
.
name
!=
answers_names
[
next_answer_idx
]:
while
answer
.
name
!=
answers_names
[
cur_col
]:
# Still add answer row to CSV when they don't exist in DB
row
.
append
(
''
)
row
.
append
(
''
)
cur_col
+=
1
next_answer_idx
+=
1
row
.
append
(
answer
.
student_input
)
row
.
append
(
answer
.
student_input
)
cur_col
+=
1
next_answer_idx
+=
1
if
row
:
if
row
:
yield
list2csv
(
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