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
a541d654
Commit
a541d654
authored
Sep 28, 2015
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleans up decoding of student submissions
parent
47e2a75f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
22 deletions
+26
-22
crowdsourcehinter/crowdsourcehinter.py
+25
-21
crowdsourcehinter/static/js/src/crowdsourcehinter.js
+1
-1
No files found.
crowdsourcehinter/crowdsourcehinter.py
View file @
a541d654
...
...
@@ -6,12 +6,14 @@ import random
import
json
import
copy
import
HTMLParser
from
xblock.core
import
XBlock
from
xblock.fields
import
Scope
,
Dict
,
List
,
Boolean
,
String
from
xblock.fragment
import
Fragment
log
=
logging
.
getLogger
(
__name__
)
html_parser
=
HTMLParser
.
HTMLParser
()
class
CrowdsourceHinter
(
XBlock
):
"""
...
...
@@ -139,6 +141,19 @@ class CrowdsourceHinter(XBlock):
frag
.
initialize_js
(
'CrowdsourceHinter'
,
{
'hinting_element'
:
self
.
Element
,
'isStaff'
:
self
.
xmodule_runtime
.
user_is_staff
})
return
frag
def
extract_student_answers
(
self
,
answers
):
"""
We find out what the student submitted by listening to a
client-side event. This event is a little bit messy. This
function cleans up the event into a dictionary mapping
input IDs to answers submitted.
"""
# First, we split this into the submission
answers
=
[
a
.
split
(
'='
)
for
a
in
answers
.
split
(
"&"
)]
# Next, we decode the HTML escapes
answers
=
[(
a
[
0
],
html_parser
.
unescape
(
a
[
1
]))
for
a
in
answers
]
return
dict
(
answers
)
@XBlock.json_handler
def
get_hint
(
self
,
data
,
suffix
=
''
):
"""
...
...
@@ -168,31 +183,20 @@ class CrowdsourceHinter(XBlock):
self
.
hint_database
[
answers
]
=
{}
if
self
.
initial_hints
[
answers
]
not
in
self
.
hint_database
[
answers
]:
self
.
hint_database
[
answers
]
.
update
({
self
.
initial_hints
[
answers
]:
0
})
answer
=
str
(
data
[
"submittedanswer"
])
answer
=
self
.
extract_student_answers
(
data
[
"submittedanswer"
])
# HACK: For now, we assume just one submission, a string, and
# case insensitive
#
# TODO: We should replace this with a generic canonicalization
# function
answer
=
answer
.
values
()[
0
]
.
lower
()
# Put the student's answer to lower case so that differences
# in capitalization don't make different groups of
# hints. TODO: We should replace this with a generic
# canonicalization function.
answer
=
answer
.
lower
()
found_equal_sign
=
0
# TODO: What is this? This should move below the comment below, so it is clear.
# hints. TODO: We should replace this with a .
remaining_hints
=
int
(
0
)
# TODO: This is confused
best_hint
=
""
# TODO: What is this?
# The string returned by the event problem_graded is very
# messy and is different for each problem, but after all of
# the numbers/letters there is an equal sign, after which the
# student's input is shown. I use the function below to remove
# everything before the first equal sign and only take the
# student's actual input.
# TODO: figure out better way to directly get text of student's answer
# TODO: Break this out into a function
if
"="
in
answer
:
if
found_equal_sign
==
0
:
found_equal_sign
=
1
eqplace
=
answer
.
index
(
"="
)
+
1
answer
=
answer
[
eqplace
:]
remaining_hints
=
str
(
self
.
find_hints
(
answer
))
if
remaining_hints
!=
str
(
0
):
for
hint
in
self
.
hint_database
[
str
(
answer
)]:
...
...
crowdsourcehinter/static/js/src/crowdsourcehinter.js
View file @
a541d654
...
...
@@ -31,7 +31,7 @@ function CrowdsourceHinter(runtime, element, data){
$
.
ajax
({
type
:
"POST"
,
url
:
runtime
.
handlerUrl
(
element
,
'get_hint'
),
data
:
JSON
.
stringify
({
"submittedanswer"
:
unescape
(
problemGradedEvent
[
0
])
}),
data
:
JSON
.
stringify
({
"submittedanswer"
:
problemGradedEvent
[
0
]
}),
success
:
showHint
});
}
...
...
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