Commit 777a9a4c by Tim Krones

Make contents of CSV file match results displayed on page.

parent a199b820
......@@ -90,18 +90,14 @@ function StudentAnswersDashboardBlock(runtime, element) {
var $resultTable = $('.data-export-results table tbody');
_.each(status.last_export_result.display_data, function(row) {
$resultTable.append($('<tr>').html(
_.template(
'<td><%= section %></td>' +
'<td><%= subsection %></td>' +
'<td><%= unit %></td>' +
'<td><%= type %></td>' +
'<td><%= question %></td>' +
'<td><%= answer %></td>' +
'<td><%= username %></td>',
row
)
));
var tr = $('<tr>');
_.each(row, function(cell) {
tr.append($('<td>').text(cell));
});
$resultTable.append(tr);
});
} else {
......
......@@ -50,7 +50,7 @@ def export_data(course_id, source_block_id_str, block_types, user_id, get_root=T
else:
block_types = tuple(type_map[class_name] for class_name in block_types)
# Build an ordered list of blocks to include in the export - each block is a column in the CSV file
# Build an ordered list of blocks to include in the export
blocks_to_include = []
def scan_for_blocks(block):
......@@ -69,15 +69,10 @@ def export_data(course_id, source_block_id_str, block_types, user_id, get_root=T
# Define the header rows of our CSV:
rows = []
rows.append(["Student"] + [block.display_name_with_default for block in blocks_to_include])
rows.append([""] + [block.scope_ids.block_type for block in blocks_to_include])
rows.append([""] + [block.scope_ids.usage_id for block in blocks_to_include])
table = []
rows.append(["Section", "Subsection", "Unit", "Type", "Question", "Answer", "Username"])
# Load the actual student submissions for each block in blocks_to_include.
# Note this requires one giant query per block (all student submissions for each block, one block at a time)
student_submissions = {} # Key is student ID, value is a list with same length as blocks_to_include
for idx, block in enumerate(blocks_to_include, start=1): # start=1 since first column is student ID
# Get all of the most recent student submissions for this block:
block_id = unicode(block.scope_ids.usage_id.replace(branch=None, version_guid=None))
......@@ -97,18 +92,9 @@ def export_data(course_id, source_block_id_str, block_types, user_id, get_root=T
# If the student ID key doesn't exist, we're dealing with a single student and know the ID already.
student_id = submission.get('student_id', user_id)
if student_id not in student_submissions:
student_submissions[student_id] = [student_id] + [""] * len(blocks_to_include)
student_submissions[student_id][idx] = submission['answer']
# Extract data for display
table_row = _extract_data_for_display(submission, student_id, block_type)
table.append(table_row)
# Now change from a dict to an array ordered by student ID as we generate the remaining rows:
for student_id in sorted(student_submissions.iterkeys()):
rows.append(student_submissions[student_id])
del student_submissions[student_id]
row = _extract_data_for_display(submission, student_id, block_type)
rows.append(row)
# Generate the CSV:
filename = u"pb-data-export-{}.csv".format(time.strftime("%Y-%m-%d-%H%M%S", time.gmtime(start_timestamp)))
......@@ -123,7 +109,7 @@ def export_data(course_id, source_block_id_str, block_types, user_id, get_root=T
"report_filename": filename,
"start_timestamp": start_timestamp,
"generation_time_s": generation_time_s,
"display_data": table,
"display_data": [] if len(rows) == 1 else rows[1:]
}
......@@ -167,12 +153,12 @@ def _extract_data_for_display(submission, student_id, block_type):
# Section
section = modulestore().get_item(subsection.parent)
return {
'section': section.display_name,
'subsection': subsection.display_name,
'unit': unit.display_name,
'type': block_type,
'question': block.question,
'answer': answer,
'username': username
}
return [
section.display_name,
subsection.display_name,
unit.display_name,
block_type,
block.question,
answer,
username
]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment