Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-analytics-pipeline
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
edx
edx-analytics-pipeline
Commits
c4917a60
Commit
c4917a60
authored
Aug 05, 2015
by
Gabe Mulley
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #139 from edx/gabe/fix-answer-dist
Fix answer distribution handling of malformed event data
parents
35e5861a
26f1a389
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
1 deletions
+28
-1
edx/analytics/tasks/answer_dist.py
+18
-1
edx/analytics/tasks/tests/test_answer_dist.py
+10
-0
No files found.
edx/analytics/tasks/answer_dist.py
View file @
c4917a60
...
@@ -983,7 +983,16 @@ def get_problem_check_event(line):
...
@@ -983,7 +983,16 @@ def get_problem_check_event(line):
log
.
error
(
"encountered explicit problem_check event with bogus problem_id:
%
s"
,
event
)
log
.
error
(
"encountered explicit problem_check event with bogus problem_id:
%
s"
,
event
)
return
None
return
None
if
len
(
event
.
get
(
'event'
,
{})
.
get
(
'answers'
,
[]))
==
0
:
event
=
event
.
get
(
'event'
,
{})
answers
=
event
.
get
(
'answers'
,
{})
if
len
(
answers
)
==
0
:
return
None
try
:
_check_answer_ids
(
answers
)
_check_answer_ids
(
event
.
get
(
'submission'
,
{}))
except
(
TypeError
,
ValueError
):
log
.
error
(
"encountered explicit problem_check event with invalid answers:
%
s"
,
event
)
return
None
return
None
problem_data_json
=
json
.
dumps
(
problem_data
)
problem_data_json
=
json
.
dumps
(
problem_data
)
...
@@ -991,3 +1000,11 @@ def get_problem_check_event(line):
...
@@ -991,3 +1000,11 @@ def get_problem_check_event(line):
value
=
(
problem_data
.
get
(
'timestamp'
),
problem_data_json
)
value
=
(
problem_data
.
get
(
'timestamp'
),
problem_data_json
)
return
key
,
value
return
key
,
value
def
_check_answer_ids
(
answer_dict
):
if
not
isinstance
(
answer_dict
,
dict
):
raise
TypeError
(
'Expected dictionaries for answers'
)
for
answer_id
in
answer_dict
:
if
'
\n
'
in
answer_id
or
'
\t
'
in
answer_id
:
raise
ValueError
(
'Malformed answer_id'
)
edx/analytics/tasks/tests/test_answer_dist.py
View file @
c4917a60
...
@@ -179,6 +179,16 @@ class ProblemCheckEventMapTest(InitializeOpaqueKeysMixin, ProblemCheckEventBaseT
...
@@ -179,6 +179,16 @@ class ProblemCheckEventMapTest(InitializeOpaqueKeysMixin, ProblemCheckEventBaseT
line
=
self
.
create_event_log_line
(
context
=
None
)
line
=
self
.
create_event_log_line
(
context
=
None
)
self
.
assert_no_map_output_for
(
line
)
self
.
assert_no_map_output_for
(
line
)
def
test_invalid_answer_id
(
self
):
self
.
answer_id
=
'foo
\n
bar'
line
=
self
.
create_event_log_line
()
self
.
assert_no_map_output_for
(
line
)
def
test_invalid_answer_id_with_tab
(
self
):
self
.
answer_id
=
'foo
\t
bar'
line
=
self
.
create_event_log_line
()
self
.
assert_no_map_output_for
(
line
)
def
test_good_problem_check_event
(
self
):
def
test_good_problem_check_event
(
self
):
# Here, we make the event as a dictionary since we're comparing based on dictionaries anyway.
# Here, we make the event as a dictionary since we're comparing based on dictionaries anyway.
event
=
self
.
create_event_dict
()
event
=
self
.
create_event_dict
()
...
...
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