Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
crowdsourcehinter
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
crowdsourcehinter
Commits
e7160547
Commit
e7160547
authored
Mar 23, 2015
by
solashirai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes to listening for events, errors exist with dict key/values being unicode
parent
0b5fa0cb
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
20 deletions
+25
-20
crowdsourcehinter/crowdsourcehinter.py
+20
-6
crowdsourcehinter/static/js/src/crowdsourcehinter.js
+5
-14
No files found.
crowdsourcehinter/crowdsourcehinter.py
View file @
e7160547
...
...
@@ -108,12 +108,19 @@ class CrowdsourceHinter(XBlock):
"""
return
self
.
xmodule_runtime
.
user_is_staff
def
convert_keys_to_string
(
dictionary
):
"""Recursively converts dictionary keys to strings."""
if
not
isinstance
(
dictionary
,
dict
):
return
dictionary
return
dict
((
str
(
k
),
convert_keys_to_string
(
v
))
for
k
,
v
in
dictionary
.
items
())
@XBlock.json_handler
def
get_element
(
self
,
data
,
suffix
=
''
):
"""
Returns the self.element so that the javascript Logger.listen will be using the correct element.
"""
return
str
(
self
.
Element
);
return
unicode
(
self
.
Element
);
@XBlock.json_handler
def
is_user_staff
(
self
,
_data
,
_suffix
=
''
):
...
...
@@ -145,8 +152,6 @@ class CrowdsourceHinter(XBlock):
# populate hint_database with hints from initial_hints if there are no hints in hint_database.
# this probably will occur only on the very first run of a unit containing this block.
if
not
bool
(
self
.
hint_database
):
#TODO: Figure out why temporarydict = self.initial_hints doesn't work.
self
.
hint_database
=
copy
.
copy
(
self
.
initial_hints
)
answer
=
str
(
data
[
"submittedanswer"
])
answer
=
answer
.
lower
()
# for analyzing the student input string I make it lower case.
...
...
@@ -164,6 +169,7 @@ class CrowdsourceHinter(XBlock):
answer
=
answer
[
eqplace
:]
remaining_hints
=
str
(
self
.
find_hints
(
answer
))
if
remaining_hints
!=
str
(
0
):
print
(
self
.
hint_database
)
best_hint
=
max
(
self
.
hint_database
[
str
(
answer
)]
.
iteritems
(),
key
=
operator
.
itemgetter
(
1
))[
0
]
if
self
.
show_best
:
# if set to show best, only the best hint will be shown. Different hitns will not be shown
...
...
@@ -385,6 +391,13 @@ class CrowdsourceHinter(XBlock):
self
.
hint_database
[
str
(
answer
)][
str
(
submission
)]
+=
1
return
def
convert_keys_to_string
(
dictionary
):
"""Recursively converts dictionary keys to strings."""
if
not
isinstance
(
dictionary
,
dict
):
return
dictionary
return
dict
((
str
(
k
),
convert_keys_to_string
(
v
))
for
k
,
v
in
dictionary
.
items
())
@XBlock.json_handler
def
studiodata
(
self
,
data
,
suffix
=
''
):
"""
...
...
@@ -414,8 +427,9 @@ class CrowdsourceHinter(XBlock):
A minimal working test for parse_xml
"""
block
=
runtime
.
construct_xblock_from_class
(
cls
,
keys
)
xmlText
=
ast
.
literal_eval
(
(
node
.
text
)
.
encode
(
'utf-8'
))
block
.
generic_hints
.
append
(
xmlText
[
"generic_hints"
]
)
xmlText
=
ast
.
literal_eval
(
str
(
node
.
text
))
block
.
generic_hints
.
append
(
str
(
xmlText
[
"generic_hints"
])
)
block
.
initial_hints
=
copy
.
copy
(
xmlText
[
"initial_hints"
])
block
.
Element
=
xmlText
[
"hinting_element"
]
block
.
Element
=
str
(
xmlText
[
"hinting_element"
])
print
block
.
Element
,
block
.
initial_hints
return
block
crowdsourcehinter/static/js/src/crowdsourcehinter.js
View file @
e7160547
...
...
@@ -16,8 +16,9 @@ function CrowdsourceHinter(runtime, element){
url
:
runtime
.
handlerUrl
(
element
,
'get_element'
),
data
:
JSON
.
stringify
(
"helloworld"
),
success
:
function
(
result
){
console
.
log
(
"hinting_element being set"
,
result
);
hinting_element
=
result
;
console
.
log
(
"hinting_element being set"
,
String
(
result
));
hinting_element
=
String
(
result
);
Logger
.
listen
(
'problem_graded'
,
result
,
get_event_data
);
}
});
...
...
@@ -25,7 +26,6 @@ function CrowdsourceHinter(runtime, element){
//This function is used to prevent a particular instance of the hinter from acting after
//switching between edX course's units.
executeHinter
=
false
;
console
.
log
(
"executeHinter set to false"
);
}
Logger
.
listen
(
'seq_next'
,
null
,
stopScript
);
Logger
.
listen
(
'seq_prev'
,
null
,
stopScript
);
...
...
@@ -34,18 +34,8 @@ function CrowdsourceHinter(runtime, element){
//data about the problem obtained from Logger.listen('problem_graded') is passed on to the onStudentSubmission.
//directly passing data to onStudentSubmission does not appear to work
function
get_event_data
(
event_type
,
data
,
element
){
//onStudentSubmission(data);
console
.
log
(
"gradedevent listen"
);
onStudentSubmission
(
data
);
}
Logger
.
listen
(
'problem_graded'
,
hinting_element
,
function
(){
console
.
log
(
"test"
)});
Logger
.
listen
(
'problem_graded'
,
'i4x://edX/DemoX/problem/Text_Input'
,
function
(){
console
.
log
(
"test2"
)});
function
get_event_data_temp
(
event_type
,
data
,
element
){
console
.
log
(
"checkevent listen"
);
console
.
log
(
hinting_element
);
console
.
log
(
typeof
(
'i4x://edX/DemoX/problem/Text_Input'
));
}
Logger
.
listen
(
'problem_check'
,
null
,
get_event_data_temp
);
function
onStudentSubmission
(
problem_graded_event_data
){
//This function will determine whether or not the student correctly answered the question.
...
...
@@ -217,6 +207,7 @@ function CrowdsourceHinter(runtime, element){
var
answerdata
=
unescape
(
$
(
this
).
attr
(
'answer'
));
var
newhint
=
unescape
(
$
(
'.csh_student_text_input'
).
val
());
Logger
.
log
(
'crowd_hinter.submit_new.click.event'
,
{
"student_answer"
:
answerdata
,
"new_hint_submission"
:
newhint
});
console
.
log
(
answerdata
,
newhint
);
$
(
'.csh_submitbutton'
).
show
();
$
.
ajax
({
type
:
"POST"
,
...
...
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