-
Notifications
You must be signed in to change notification settings - Fork 4.3k
[BB-753] Fix issue with multiple responses for a single user returned by generate_report_data #19507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ormsbee
merged 1 commit into
openedx:master
from
open-craft:kshitij/fix-problem-response-report
Mar 15, 2019
Merged
[BB-753] Fix issue with multiple responses for a single user returned by generate_report_data #19507
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| """ | ||
| import logging | ||
| import re | ||
| from collections import OrderedDict | ||
| from collections import defaultdict, OrderedDict | ||
| from datetime import datetime | ||
| from itertools import chain, izip, izip_longest | ||
| from time import time | ||
|
|
@@ -615,15 +615,15 @@ def _build_problem_list(cls, course_blocks, root, path=None): | |
| Tuple[str, List[str], UsageKey]: tuple of a block's display name, path, and | ||
| usage key | ||
| """ | ||
| display_name = course_blocks.get_xblock_field(root, 'display_name') | ||
| name = course_blocks.get_xblock_field(root, 'display_name') or root.category | ||
| if path is None: | ||
| path = [display_name] | ||
| path = [name] | ||
|
|
||
| yield display_name, path, root | ||
| yield name, path, root | ||
|
|
||
| for block in course_blocks.get_children(root): | ||
| display_name = course_blocks.get_xblock_field(block, 'display_name') | ||
| for result in cls._build_problem_list(course_blocks, block, path + [display_name]): | ||
| name = course_blocks.get_xblock_field(block, 'display_name') or block.category | ||
| for result in cls._build_problem_list(course_blocks, block, path + [name]): | ||
| yield result | ||
|
|
||
| @classmethod | ||
|
|
@@ -664,33 +664,42 @@ def _build_student_data(cls, user_id, course_key, usage_key_str): | |
| continue | ||
|
|
||
| block = store.get_item(block_key) | ||
| generated_report_data = {} | ||
| generated_report_data = defaultdict(list) | ||
|
|
||
| # Blocks can implement the generate_report_data method to provide their own | ||
| # human-readable formatting for user state. | ||
| if hasattr(block, 'generate_report_data'): | ||
| try: | ||
| user_state_iterator = user_state_client.iter_all_for_block(block_key) | ||
| generated_report_data = { | ||
| username: state | ||
| for username, state in | ||
| block.generate_report_data(user_state_iterator, max_count) | ||
| } | ||
| for username, state in block.generate_report_data(user_state_iterator, max_count): | ||
| generated_report_data[username].append(state) | ||
| except NotImplementedError: | ||
| pass | ||
|
|
||
| responses = list_problem_responses(course_key, block_key, max_count) | ||
| responses = [] | ||
|
|
||
| student_data += responses | ||
| for response in responses: | ||
| for response in list_problem_responses(course_key, block_key, max_count): | ||
| response['title'] = title | ||
| # A human-readable location for the current block | ||
| response['location'] = ' > '.join(path) | ||
| # A machine-friendly location for the current block | ||
| response['block_key'] = str(block_key) | ||
| user_data = generated_report_data.get(response['username'], {}) | ||
| response.update(user_data) | ||
| student_data_keys = student_data_keys.union(user_data.keys()) | ||
| # A block that has a single state per user can contain multiple responses | ||
| # within the same state. | ||
| user_states = generated_report_data.get(response['username'], []) | ||
| if user_states: | ||
| # For each response in the block, copy over the basic data like the | ||
| # title, location, block_key and state, and add in the responses | ||
| for user_state in user_states: | ||
| user_response = response.copy() | ||
| user_response.update(user_state) | ||
| student_data_keys = student_data_keys.union(user_state.keys()) | ||
| responses.append(user_response) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please insert a comment explaining what is going on in this block? |
||
| else: | ||
| responses.append(response) | ||
|
|
||
| student_data += responses | ||
|
|
||
| if max_count is not None: | ||
| max_count -= len(responses) | ||
| if max_count <= 0: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ormsbee I'm making it fall back to the 'category' in case there is no display name. I hope that works.