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) { ...@@ -90,18 +90,14 @@ function StudentAnswersDashboardBlock(runtime, element) {
var $resultTable = $('.data-export-results table tbody'); var $resultTable = $('.data-export-results table tbody');
_.each(status.last_export_result.display_data, function(row) { _.each(status.last_export_result.display_data, function(row) {
$resultTable.append($('<tr>').html(
_.template( var tr = $('<tr>');
'<td><%= section %></td>' +
'<td><%= subsection %></td>' + _.each(row, function(cell) {
'<td><%= unit %></td>' + tr.append($('<td>').text(cell));
'<td><%= type %></td>' + });
'<td><%= question %></td>' +
'<td><%= answer %></td>' + $resultTable.append(tr);
'<td><%= username %></td>',
row
)
));
}); });
} else { } else {
......
...@@ -50,7 +50,7 @@ def export_data(course_id, source_block_id_str, block_types, user_id, get_root=T ...@@ -50,7 +50,7 @@ def export_data(course_id, source_block_id_str, block_types, user_id, get_root=T
else: else:
block_types = tuple(type_map[class_name] for class_name in block_types) 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 = [] blocks_to_include = []
def scan_for_blocks(block): 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 ...@@ -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: # Define the header rows of our CSV:
rows = [] rows = []
rows.append(["Student"] + [block.display_name_with_default for block in blocks_to_include]) rows.append(["Section", "Subsection", "Unit", "Type", "Question", "Answer", "Username"])
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 = []
# Load the actual student submissions for each block in blocks_to_include. # 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) # 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 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: # 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)) 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 ...@@ -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. # 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) 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 # Extract data for display
table_row = _extract_data_for_display(submission, student_id, block_type) row = _extract_data_for_display(submission, student_id, block_type)
table.append(table_row) rows.append(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]
# Generate the CSV: # Generate the CSV:
filename = u"pb-data-export-{}.csv".format(time.strftime("%Y-%m-%d-%H%M%S", time.gmtime(start_timestamp))) 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 ...@@ -123,7 +109,7 @@ def export_data(course_id, source_block_id_str, block_types, user_id, get_root=T
"report_filename": filename, "report_filename": filename,
"start_timestamp": start_timestamp, "start_timestamp": start_timestamp,
"generation_time_s": generation_time_s, "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): ...@@ -167,12 +153,12 @@ def _extract_data_for_display(submission, student_id, block_type):
# Section # Section
section = modulestore().get_item(subsection.parent) section = modulestore().get_item(subsection.parent)
return { return [
'section': section.display_name, section.display_name,
'subsection': subsection.display_name, subsection.display_name,
'unit': unit.display_name, unit.display_name,
'type': block_type, block_type,
'question': block.question, block.question,
'answer': answer, answer,
'username': username 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