Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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-platform
Commits
5333e5e1
Commit
5333e5e1
authored
Jan 07, 2013
by
Vik Paruchuri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring to open ended child
parent
d8f6e1fe
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
156 deletions
+92
-156
common/lib/xmodule/xmodule/open_ended_module.py
+8
-72
common/lib/xmodule/xmodule/openendedchild.py
+81
-2
common/lib/xmodule/xmodule/self_assessment_module.py
+3
-82
No files found.
common/lib/xmodule/xmodule/open_ended_module.py
View file @
5333e5e1
...
@@ -69,7 +69,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
...
@@ -69,7 +69,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
if
self
.
created
==
"True"
and
self
.
state
==
self
.
ASSESSING
:
if
self
.
created
==
"True"
and
self
.
state
==
self
.
ASSESSING
:
self
.
created
=
"False"
self
.
created
=
"False"
self
.
get_score
(
self
.
latest_answer
(),
system
)
self
.
send_to_grader
(
self
.
latest_answer
(),
system
)
self
.
created
=
"False"
self
.
created
=
"False"
def
_parse
(
self
,
oeparam
,
prompt
,
rubric
,
system
):
def
_parse
(
self
,
oeparam
,
prompt
,
rubric
,
system
):
...
@@ -180,7 +180,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
...
@@ -180,7 +180,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
return
{
'success'
:
success
,
'msg'
:
"Successfully submitted your feedback."
}
return
{
'success'
:
success
,
'msg'
:
"Successfully submitted your feedback."
}
def
get_score
(
self
,
submission
,
system
):
def
send_to_grader
(
self
,
submission
,
system
):
# Prepare xqueue request
# Prepare xqueue request
#------------------------------------------------------------
#------------------------------------------------------------
...
@@ -228,7 +228,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
...
@@ -228,7 +228,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
score_msg
[
'feedback'
]
=
'Invalid grader reply. Please contact the course staff.'
score_msg
[
'feedback'
]
=
'Invalid grader reply. Please contact the course staff.'
self
.
record_latest_score
(
score_msg
[
'score'
])
self
.
record_latest_score
(
score_msg
[
'score'
])
self
.
record_latest_
feedback
(
score_msg
[
'feedback'
])
self
.
record_latest_
post_assessment
(
score_msg
[
'feedback'
])
self
.
state
=
self
.
POST_ASSESSMENT
self
.
state
=
self
.
POST_ASSESSMENT
return
True
return
True
...
@@ -461,7 +461,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
...
@@ -461,7 +461,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
# add new history element with answer and empty score and hint.
# add new history element with answer and empty score and hint.
self
.
new_history_entry
(
get
[
'student_answer'
])
self
.
new_history_entry
(
get
[
'student_answer'
])
self
.
get_score
(
get
[
'student_answer'
],
system
)
self
.
send_to_grader
(
get
[
'student_answer'
],
system
)
self
.
change_state
(
self
.
ASSESSING
)
self
.
change_state
(
self
.
ASSESSING
)
return
{
'success'
:
True
,}
return
{
'success'
:
True
,}
...
@@ -496,66 +496,16 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
...
@@ -496,66 +496,16 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
if
self
.
state
==
self
.
DONE
:
if
self
.
state
==
self
.
DONE
:
self
.
attempts
+=
1
self
.
attempts
+=
1
def
get_instance_state
(
self
):
"""
Get the current score and state
"""
state
=
{
'version'
:
self
.
STATE_VERSION
,
'history'
:
self
.
history
,
'state'
:
self
.
state
,
'max_score'
:
self
.
_max_score
,
'attempts'
:
self
.
attempts
,
'created'
:
"False"
,
}
return
json
.
dumps
(
state
)
def
latest_answer
(
self
):
"""None if not available"""
if
not
self
.
history
:
return
""
return
self
.
history
[
-
1
]
.
get
(
'answer'
,
""
)
def
latest_score
(
self
):
"""None if not available"""
if
not
self
.
history
:
return
""
return
self
.
history
[
-
1
]
.
get
(
'score'
,
""
)
def
latest_feedback
(
self
):
"""None if not available"""
if
not
self
.
history
:
return
""
return
self
.
history
[
-
1
]
.
get
(
'feedback'
,
""
)
def
new_history_entry
(
self
,
answer
):
self
.
history
.
append
({
'answer'
:
answer
})
def
record_latest_score
(
self
,
score
):
"""Assumes that state is right, so we're adding a score to the latest
history element"""
self
.
history
[
-
1
][
'score'
]
=
score
def
record_latest_feedback
(
self
,
feedback
):
"""Assumes that state is right, so we're adding a score to the latest
history element"""
self
.
history
[
-
1
][
'feedback'
]
=
feedback
def
_allow_reset
(
self
):
"""Can the module be reset?"""
return
self
.
state
==
self
.
DONE
and
self
.
attempts
<
self
.
max_attempts
def
get_html
(
self
,
system
):
def
get_html
(
self
,
system
):
#set context variables and render template
#set context variables and render template
if
self
.
state
!=
self
.
INITIAL
:
if
self
.
state
!=
self
.
INITIAL
:
latest
=
self
.
latest_answer
()
latest
=
self
.
latest_answer
()
previous_answer
=
latest
if
latest
is
not
None
else
self
.
initial_display
previous_answer
=
latest
if
latest
is
not
None
else
self
.
initial_display
feedback
=
self
.
latest_feedback
()
post_assessment
=
self
.
latest_post_assessment
()
score
=
self
.
latest_score
()
score
=
self
.
latest_score
()
correct
=
'correct'
if
self
.
is_submission_correct
(
score
)
else
'incorrect'
correct
=
'correct'
if
self
.
is_submission_correct
(
score
)
else
'incorrect'
else
:
else
:
feedback
=
""
post_assessment
=
""
correct
=
""
correct
=
""
previous_answer
=
self
.
initial_display
previous_answer
=
self
.
initial_display
...
@@ -567,7 +517,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
...
@@ -567,7 +517,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
'rows'
:
30
,
'rows'
:
30
,
'cols'
:
80
,
'cols'
:
80
,
'id'
:
'open_ended'
,
'id'
:
'open_ended'
,
'msg'
:
feedback
,
'msg'
:
post_assessment
,
'child_type'
:
'openended'
,
'child_type'
:
'openended'
,
'correct'
:
correct
,
'correct'
:
correct
,
}
}
...
@@ -575,27 +525,13 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
...
@@ -575,27 +525,13 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
html
=
system
.
render_template
(
'open_ended.html'
,
context
)
html
=
system
.
render_template
(
'open_ended.html'
,
context
)
return
html
return
html
def
max_score
(
self
):
"""
Return max_score
"""
return
self
.
_max_score
def
get_score_value
(
self
):
"""
Returns the last score in the list
"""
score
=
self
.
latest_score
()
return
{
'score'
:
score
if
score
is
not
None
else
0
,
'total'
:
self
.
_max_score
}
def
get_progress
(
self
):
def
get_progress
(
self
):
'''
'''
For now, just return last score / max_score
For now, just return last score / max_score
'''
'''
if
self
.
_max_score
>
0
:
if
self
.
_max_score
>
0
:
try
:
try
:
return
Progress
(
self
.
get_score
_value
()[
'score'
],
self
.
_max_score
)
return
Progress
(
self
.
get_score
()[
'score'
],
self
.
_max_score
)
except
Exception
as
err
:
except
Exception
as
err
:
log
.
exception
(
"Got bad progress"
)
log
.
exception
(
"Got bad progress"
)
return
None
return
None
...
...
common/lib/xmodule/xmodule/openendedchild.py
View file @
5333e5e1
...
@@ -127,4 +127,84 @@ class OpenEndedChild():
...
@@ -127,4 +127,84 @@ class OpenEndedChild():
self
.
setup_response
(
system
,
location
,
definition
,
descriptor
)
self
.
setup_response
(
system
,
location
,
definition
,
descriptor
)
def
setup_response
(
self
,
system
,
location
,
definition
,
descriptor
):
def
setup_response
(
self
,
system
,
location
,
definition
,
descriptor
):
pass
pass
\ No newline at end of file
def
latest_answer
(
self
):
"""None if not available"""
if
not
self
.
history
:
return
""
return
self
.
history
[
-
1
]
.
get
(
'answer'
,
""
)
def
latest_score
(
self
):
"""None if not available"""
if
not
self
.
history
:
return
None
return
self
.
history
[
-
1
]
.
get
(
'score'
)
def
latest_post_assessment
(
self
):
"""None if not available"""
if
not
self
.
history
:
return
""
return
self
.
history
[
-
1
]
.
get
(
'post_assessment'
,
""
)
def
new_history_entry
(
self
,
answer
):
self
.
history
.
append
({
'answer'
:
answer
})
def
record_latest_score
(
self
,
score
):
"""Assumes that state is right, so we're adding a score to the latest
history element"""
self
.
history
[
-
1
][
'score'
]
=
score
def
record_latest_post_assessment
(
self
,
post_assessment
):
"""Assumes that state is right, so we're adding a score to the latest
history element"""
self
.
history
[
-
1
][
'post_assessment'
]
=
post_assessment
def
change_state
(
self
,
new_state
):
"""
A centralized place for state changes--allows for hooks. If the
current state matches the old state, don't run any hooks.
"""
if
self
.
state
==
new_state
:
return
self
.
state
=
new_state
if
self
.
state
==
self
.
DONE
:
self
.
attempts
+=
1
def
get_instance_state
(
self
):
"""
Get the current score and state
"""
state
=
{
'version'
:
self
.
STATE_VERSION
,
'history'
:
self
.
history
,
'state'
:
self
.
state
,
'max_score'
:
self
.
_max_score
,
'attempts'
:
self
.
attempts
,
'created'
:
"False"
,
}
return
json
.
dumps
(
state
)
def
_allow_reset
(
self
):
"""Can the module be reset?"""
return
self
.
state
==
self
.
DONE
and
self
.
attempts
<
self
.
max_attempts
def
max_score
(
self
):
"""
Return max_score
"""
return
self
.
_max_score
def
get_score
(
self
):
"""
Returns the last score in the list
"""
score
=
self
.
latest_score
()
return
{
'score'
:
score
if
score
is
not
None
else
0
,
'total'
:
self
.
_max_score
}
common/lib/xmodule/xmodule/self_assessment_module.py
View file @
5333e5e1
...
@@ -47,51 +47,6 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
...
@@ -47,51 +47,6 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
self
.
submit_message
=
definition
[
'submitmessage'
]
self
.
submit_message
=
definition
[
'submitmessage'
]
self
.
hint_prompt
=
definition
[
'hintprompt'
]
self
.
hint_prompt
=
definition
[
'hintprompt'
]
def
latest_answer
(
self
):
"""None if not available"""
if
not
self
.
history
:
return
None
return
self
.
history
[
-
1
]
.
get
(
'answer'
)
def
latest_score
(
self
):
"""None if not available"""
if
not
self
.
history
:
return
None
return
self
.
history
[
-
1
]
.
get
(
'score'
)
def
latest_hint
(
self
):
"""None if not available"""
if
not
self
.
history
:
return
None
return
self
.
history
[
-
1
]
.
get
(
'hint'
)
def
new_history_entry
(
self
,
answer
):
self
.
history
.
append
({
'answer'
:
answer
})
def
record_latest_score
(
self
,
score
):
"""Assumes that state is right, so we're adding a score to the latest
history element"""
self
.
history
[
-
1
][
'score'
]
=
score
def
record_latest_hint
(
self
,
hint
):
"""Assumes that state is right, so we're adding a score to the latest
history element"""
self
.
history
[
-
1
][
'hint'
]
=
hint
def
change_state
(
self
,
new_state
):
"""
A centralized place for state changes--allows for hooks. If the
current state matches the old state, don't run any hooks.
"""
if
self
.
state
==
new_state
:
return
self
.
state
=
new_state
if
self
.
state
==
self
.
DONE
:
self
.
attempts
+=
1
@staticmethod
@staticmethod
def
convert_state_to_current_format
(
old_state
):
def
convert_state_to_current_format
(
old_state
):
"""
"""
...
@@ -138,11 +93,6 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
...
@@ -138,11 +93,6 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
student_answers
,
scores
,
hints
)]
student_answers
,
scores
,
hints
)]
return
new_state
return
new_state
def
_allow_reset
(
self
):
"""Can the module be reset?"""
return
self
.
state
==
self
.
DONE
and
self
.
attempts
<
self
.
max_attempts
def
get_html
(
self
,
system
):
def
get_html
(
self
,
system
):
#set context variables and render template
#set context variables and render template
if
self
.
state
!=
self
.
INITIAL
:
if
self
.
state
!=
self
.
INITIAL
:
...
@@ -166,20 +116,6 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
...
@@ -166,20 +116,6 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
html
=
system
.
render_template
(
'self_assessment_prompt.html'
,
context
)
html
=
system
.
render_template
(
'self_assessment_prompt.html'
,
context
)
return
html
return
html
def
max_score
(
self
):
"""
Return max_score
"""
return
self
.
_max_score
def
get_score
(
self
):
"""
Returns the last score in the list
"""
score
=
self
.
latest_score
()
return
{
'score'
:
score
if
score
is
not
None
else
0
,
'total'
:
self
.
_max_score
}
def
get_progress
(
self
):
def
get_progress
(
self
):
'''
'''
For now, just return last score / max_score
For now, just return last score / max_score
...
@@ -207,7 +143,7 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
...
@@ -207,7 +143,7 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
handlers
=
{
handlers
=
{
'save_answer'
:
self
.
save_answer
,
'save_answer'
:
self
.
save_answer
,
'save_assessment'
:
self
.
save_assessment
,
'save_assessment'
:
self
.
save_assessment
,
'save_post_assessment'
:
self
.
save_
hi
nt
,
'save_post_assessment'
:
self
.
save_
post_assessme
nt
,
}
}
if
dispatch
not
in
handlers
:
if
dispatch
not
in
handlers
:
...
@@ -261,7 +197,7 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
...
@@ -261,7 +197,7 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
if
self
.
state
==
self
.
DONE
:
if
self
.
state
==
self
.
DONE
:
# display the previous hint
# display the previous hint
latest
=
self
.
latest_
hi
nt
()
latest
=
self
.
latest_
post_assessme
nt
()
hint
=
latest
if
latest
is
not
None
else
''
hint
=
latest
if
latest
is
not
None
else
''
else
:
else
:
hint
=
''
hint
=
''
...
@@ -376,7 +312,7 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
...
@@ -376,7 +312,7 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
# the same number of hints and answers.
# the same number of hints and answers.
return
self
.
out_of_sync_error
(
get
)
return
self
.
out_of_sync_error
(
get
)
self
.
record_latest_
hi
nt
(
get
[
'hint'
])
self
.
record_latest_
post_assessme
nt
(
get
[
'hint'
])
self
.
change_state
(
self
.
DONE
)
self
.
change_state
(
self
.
DONE
)
return
{
'success'
:
True
,
return
{
'success'
:
True
,
...
@@ -403,21 +339,6 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
...
@@ -403,21 +339,6 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
return
{
'success'
:
True
}
return
{
'success'
:
True
}
def
get_instance_state
(
self
):
"""
Get the current score and state
"""
state
=
{
'version'
:
self
.
STATE_VERSION
,
'history'
:
self
.
history
,
'state'
:
self
.
state
,
'max_score'
:
self
.
_max_score
,
'attempts'
:
self
.
attempts
,
'created'
:
"False"
,
}
return
json
.
dumps
(
state
)
class
SelfAssessmentDescriptor
(
XmlDescriptor
,
EditingDescriptor
):
class
SelfAssessmentDescriptor
(
XmlDescriptor
,
EditingDescriptor
):
"""
"""
...
...
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