Commit f88cb685 by Victor Shnayder

split out the assess and reflect states. Still need matching js

parent fb3b52b9
""" """
A Self Assessment module that allows students to write open-ended responses, A Self Assessment module that allows students to write open-ended responses,
submit, then see a rubric and rate themselves. Persists student supplied submit, then see a rubric and rate themselves. Persists student supplied
hints, answers, and correctness judgment (currently only correct/incorrect). hints, answers, and assessment judgment (currently only correct/incorrect).
Parses xml definition file--see below for exact format. Parses xml definition file--see below for exact format.
""" """
...@@ -33,7 +33,7 @@ log = logging.getLogger("mitx.courseware") ...@@ -33,7 +33,7 @@ log = logging.getLogger("mitx.courseware")
# attempts specified in xml definition overrides this. # attempts specified in xml definition overrides this.
MAX_ATTEMPTS = 1 MAX_ATTEMPTS = 1
# Set maximum available number of points. Should be set to 1 for now due to correctness handling, # Set maximum available number of points. Should be set to 1 for now due to assessment handling,
# which only allows for correct/incorrect. # which only allows for correct/incorrect.
MAX_SCORE = 1 MAX_SCORE = 1
...@@ -73,7 +73,7 @@ class SelfAssessmentModule(XModule): ...@@ -73,7 +73,7 @@ class SelfAssessmentModule(XModule):
""" """
Definition file should have 4 blocks -- prompt, rubric, submitmessage, hintprompt, Definition file should have 4 blocks -- prompt, rubric, submitmessage, hintprompt,
and one optional attribute, attempts, which should be an integer that defaults to 1. and one optional attribute, attempts, which should be an integer that defaults to 1.
If it's >1, the student will be able to re-submit after they see If it's > 1, the student will be able to re-submit after they see
the rubric. Note: all the submissions are stored. the rubric. Note: all the submissions are stored.
Sample file: Sample file:
...@@ -100,41 +100,28 @@ class SelfAssessmentModule(XModule): ...@@ -100,41 +100,28 @@ class SelfAssessmentModule(XModule):
else: else:
instance_state = {} instance_state = {}
log.debug('Instance state of self-assessment module {0}: {1}'.format(location.url(), instance_state))
# Pull out state, or initialize variables
# lists of student answers, correctness responses
# ('incorrect'/'correct'), and suggested hints
self.student_answers = instance_state.get('student_answers', []) self.student_answers = instance_state.get('student_answers', [])
self.correctness = instance_state.get('correctness', [])
# assessment responses are 'incorrect'/'correct'
self.assessment = instance_state.get('assessment', [])
self.hints = instance_state.get('hints', []) self.hints = instance_state.get('hints', [])
# Used to keep track of a submitted answer for which we don't have a
# self-assessment and hint yet: this means that the answers,
# correctness, hints always stay in sync, and have the same number of
# elements.
self.state = instance_state.get('state', 'initial') self.state = instance_state.get('state', 'initial')
# Used for progress / grading. Currently get credit just for # Used for progress / grading. Currently get credit just for
# completion (doesn't matter if you self-assessed correct/incorrect). # completion (doesn't matter if you self-assessed correct/incorrect).
self.score = instance_state.get('score', 0) self.score = instance_state.get('score', 0)
self.top_score = instance_state.get('top_score', MAX_SCORE) self.max_score = instance_state.get('max_score', MAX_SCORE)
#Get number of attempts student has used from instance state
self.attempts = instance_state.get('attempts', 0) self.attempts = instance_state.get('attempts', 0)
#Try setting maxattempts, use default if not available in metadata
self.max_attempts = int(self.metadata.get('attempts', MAX_ATTEMPTS)) self.max_attempts = int(self.metadata.get('attempts', MAX_ATTEMPTS))
#Extract prompt, submission message, hint prompt, and rubric from definition file
self.rubric = definition['rubric'] self.rubric = definition['rubric']
self.prompt = definition['prompt'] self.prompt = definition['prompt']
self.submit_message = definition['submitmessage'] self.submit_message = definition['submitmessage']
self.hint_prompt = definition['hintprompt'] self.hint_prompt = definition['hintprompt']
#Determine if student has answered the question before. This is used to display
#a "previous answer" message to the student if they have.
previous_answer = self.student_answers[-1] if self.student_answers else '' previous_answer = self.student_answers[-1] if self.student_answers else ''
#set context variables and render template #set context variables and render template
...@@ -149,19 +136,24 @@ class SelfAssessmentModule(XModule): ...@@ -149,19 +136,24 @@ class SelfAssessmentModule(XModule):
self.html = self.system.render_template('self_assessment_prompt.html', context) self.html = self.system.render_template('self_assessment_prompt.html', context)
def get_score(self): def get_score(self):
"""
Returns dict with 'score' key
"""
return {'score': self.score} return {'score': self.score}
def max_score(self): def max_score(self):
return self.top_score """
Return max_score
"""
return self.max_score
def get_progress(self): def get_progress(self):
''' For now, just return score / max_score
''' '''
score = self.score For now, just return score / max_score
total = self.top_score '''
if total > 0: if self.max_score > 0:
try: try:
return Progress(score, total) return Progress(self.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
...@@ -180,8 +172,10 @@ class SelfAssessmentModule(XModule): ...@@ -180,8 +172,10 @@ class SelfAssessmentModule(XModule):
""" """
handlers = { handlers = {
'show': self.show_rubric, 'save_answer': self.save_answer,
'save': self.save_problem, 'save_assessment': self.save_assessment,
'save_hint': self.save_hint,
'reset': self.reset,
} }
if dispatch not in handlers: if dispatch not in handlers:
...@@ -196,6 +190,15 @@ class SelfAssessmentModule(XModule): ...@@ -196,6 +190,15 @@ class SelfAssessmentModule(XModule):
}) })
return json.dumps(d, cls=ComplexEncoder) return json.dumps(d, cls=ComplexEncoder)
def out_of_sync_error(self, get):
"""
return dict out-of-sync error message, and also log.
"""
log.warning("Assessment module state out sync. state: %r, get: %r",
self.state, get)
return {'success': False,
'error': 'The problem state got out-of-sync'}
def get_rubric_html(self): def get_rubric_html(self):
""" """
Return the appropriate version of the rubric, based on the state. Return the appropriate version of the rubric, based on the state.
...@@ -245,77 +248,116 @@ class SelfAssessmentModule(XModule): ...@@ -245,77 +248,116 @@ class SelfAssessmentModule(XModule):
return """<div class="save_message">{0}</div>""".format(self.message) return """<div class="save_message">{0}</div>""".format(self.message)
def show_rubric(self, get): def save_answer(self, get):
""" """
After the answer is submitted, show the rubric. After the answer is submitted, show the rubric.
""" """
# Check to see if attempts are less than max # Check to see if attempts are less than max
if(self.attempts < self.max_attempts): if self.attempts < self.max_attempts:
# Dump to temp_answer to keep answer in sync with correctness and hint # If too many attempts, prevent student from saving answer and
self.temp_answer = get['student_answer'] # seeing rubric. In normal use, students shouldn't see this because
# they won't see the reset button once they're out of attempts.
return {
'success': True,
'rubric': self.get_rubric_html()
}
else:
# If too many attempts, prevent student from saving answer and seeing rubric.
return { return {
'success': False, 'success': False,
'message': 'Too many attempts.' 'message': 'Too many attempts.'
} }
def save_problem(self, get): if self.state != self.INITIAL:
return self.out_of_sync_error(get)
self.student_answers.append = get['student_answer']
self.state = self.ASSESSING
return {
'success': True,
'rubric': self.get_rubric_html()
}
def save_assessment(self, get):
"""
Save the assessment.
Returns a dict { 'success' : bool, 'hint_html': hint_html 'error' : error-msg},
with 'error' only present if 'success' is False, and 'hint_html' only if success is true
"""
if (self.state != self.ASSESSMENT or
len(self.student_answers) != len(self.assessment) + 1):
return self.out_of_sync_error(get)
self.assessment.append(get['assessment'].lower())
self.state = self.REQUEST_HINT
# TODO: return different hint based on assessment value...
return {'success': True, 'hint_html': self.get_hint_html()}
def save_hint(self, get):
''' '''
Save the passed in answers. Save the hint.
Returns a dict { 'success' : bool, ['error' : error-msg]}, Returns a dict { 'success' : bool,
with the error key only present if success is False. 'message_html': message_html,
'error' : error-msg},
with the error key only present if success is False and message_html
only if True.
''' '''
if self.state != self.REQUEST_HINT or len(self.assessment) != len(self.hints) + 1:
return self.out_of_sync_error(get)
#Temp answer check is to keep hints, correctness, and answer in sync self.hints.append(get['hint'].lower())
if self.temp_answer is not "": self.state = self.DONE
#Extract correctness and hint from ajax, and add temp answer to student answers
self.hints.append(get['hint'])
self.correctness.append(get['assessment'].lower())
self.student_answers.append(self.temp_answer)
# Points are assigned for completion, so always set to 1
points = 1
# increment attempts # increment attempts
self.attempts = self.attempts + 1 self.attempts = self.attempts + 1
#Create and store event info dict # To the tracking logs!
#Currently points are assigned for completion, so set to 1 instead of depending on correctness. event_info = {
points = 1 'selfassessment_id' : self.location.url(),
event_info = dict() 'state': {
event_info['state'] = { 'student_answers': self.student_answers,
'student_answers': self.student_answers, 'assessment': self.assessment,
'hints' : self.hints, 'hints' : self.hints,
'correctness': self.correctness, 'score': points,
'score': points, 'done': self.done,}}
'done': self.done self.system.track_function('save_hint', event_info)
}
return {'success': True,
'message_html': self.get_message_html()}
# TODO: figure out how to identify self assessment. May not want to confuse with problems.
event_info['selfassessment_id'] = self.location.url()
self.system.track_function('save_problem_succeed', event_info) def reset(self, get):
"""
If resetting is allowed, reset the state.
Returns {'success': bool, 'error': msg}
(error only present if not success)
"""
if self.state != DONE:
return self.out_of_sync_error(get)
if self.attempts < self.max_attempts:
return {
'success': False,
'error': 'Too many attempts.'
}
self.state = self.INITIAL
return {'success': True}
#Return the submitmessage specified in xml defintion on success
return {'success': True, 'message': self.submit_message}
def get_instance_state(self): def get_instance_state(self):
""" """
Get the current correctness, points, and state Get the current assessment, points, and state
""" """
#Assign points based on completion. May want to change to correctness-based down the road. #Assign points based on completion. May want to change to assessment-based down the road.
points = 1 points = 1
state = { state = {
'student_answers': self.student_answers, 'student_answers': self.student_answers,
'temp_answer': self.temp_answer, 'temp_answer': self.temp_answer,
'hints' : self.hints, 'hints' : self.hints,
'correctness': self.correctness, 'assessment': self.assessment,
'score': points, 'score': points,
'top_score' : MAX_SCORE, 'max_score' : MAX_SCORE,
'attempts' : self.attempts 'attempts' : self.attempts
} }
return json.dumps(state) return json.dumps(state)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment