From b7c6f7ca1a9575f39bdc465dc3178b5483429325 Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Tue, 5 Mar 2013 19:16:02 -0500 Subject: [PATCH] Mostly working state --- .../combined_open_ended_modulev1.py | 9 ++--- .../openendedchild.py | 36 ++++++------------- 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/common/lib/xmodule/xmodule/open_ended_grading_classes/combined_open_ended_modulev1.py b/common/lib/xmodule/xmodule/open_ended_grading_classes/combined_open_ended_modulev1.py index 2149729605..8ad53f3db7 100644 --- a/common/lib/xmodule/xmodule/open_ended_grading_classes/combined_open_ended_modulev1.py +++ b/common/lib/xmodule/xmodule/open_ended_grading_classes/combined_open_ended_modulev1.py @@ -195,6 +195,7 @@ class CombinedOpenEndedV1Module(): last_response = last_response_data['response'] loaded_task_state = json.loads(current_task_state) + log.debug(loaded_task_state) if loaded_task_state['child_state'] == self.INITIAL: loaded_task_state['child_state'] = self.ASSESSING loaded_task_state['child_created'] = True @@ -253,7 +254,6 @@ class CombinedOpenEndedV1Module(): #This sends the etree_xml object through the descriptor module of the current task, and #returns the xml parsed by the descriptor - log.debug(current_task_state) self.current_task_parsed_xml = self.current_task_descriptor.definition_from_xml(etree_xml, self.system) if current_task_state is None and self.current_task_number == 0: self.current_task = child_task_module(self.system, self.location, @@ -264,7 +264,7 @@ class CombinedOpenEndedV1Module(): last_response_data = self.get_last_response(self.current_task_number - 1) last_response = last_response_data['response'] current_task_state = json.dumps({ - 'state': self.ASSESSING, + 'child_state': self.ASSESSING, 'version': self.STATE_VERSION, 'max_score': self._max_score, 'child_attempts': 0, @@ -276,6 +276,7 @@ class CombinedOpenEndedV1Module(): instance_state=current_task_state) self.task_states.append(self.current_task.get_instance_state()) self.state = self.ASSESSING + log.debug(self.task_states) else: if self.current_task_number > 0 and not reset: current_task_state = self.overwrite_state(current_task_state) @@ -394,7 +395,7 @@ class CombinedOpenEndedV1Module(): task_parsed_xml = task_descriptor.definition_from_xml(etree_xml, self.system) task = children['modules'][task_type](self.system, self.location, task_parsed_xml, task_descriptor, - self.static_data, instance_state=self.instance_state, model_data = self._model_data) + self.static_data, instance_state=task_state, model_data = self._model_data) last_response = task.latest_answer() last_score = task.latest_score() last_post_assessment = task.latest_post_assessment(self.system) @@ -479,7 +480,7 @@ class CombinedOpenEndedV1Module(): if not self.allow_reset: self.task_states[self.current_task_number] = self.current_task.get_instance_state() current_task_state = json.loads(self.task_states[self.current_task_number]) - if current_task_state['state'] == self.DONE: + if current_task_state['child_state'] == self.DONE: self.current_task_number += 1 if self.current_task_number >= (len(self.task_xml)): self.state = self.DONE diff --git a/common/lib/xmodule/xmodule/open_ended_grading_classes/openendedchild.py b/common/lib/xmodule/xmodule/open_ended_grading_classes/openendedchild.py index 8cdfc8f322..9a9446b6cf 100644 --- a/common/lib/xmodule/xmodule/open_ended_grading_classes/openendedchild.py +++ b/common/lib/xmodule/xmodule/open_ended_grading_classes/openendedchild.py @@ -65,7 +65,7 @@ class OpenEndedChild(object): } def __init__(self, system, location, definition, descriptor, static_data, - instance_state=None, shared_state=None, model_data=None, task_number = None, **kwargs): + instance_state=None, shared_state=None, **kwargs): # Load instance state if instance_state is not None: @@ -80,27 +80,11 @@ class OpenEndedChild(object): # None for any element, and score and hint can be None for the last (current) # element. # Scores are on scale from 0 to max_score - self._model_data = model_data - task_state = {} - try: - self.child_history=instance_state['task_states'][task_number]['history'] - except: - self.child_history = [] - try: - self.child_state=instance_state['task_states'][task_number]['state'] - except: - self.child_state = self.INITIAL - - try: - self.child_created = instance_state['task_states'][task_number]['created'] - except: - self.child_created = False - - try: - self.child_attempts = instance_state['task_states'][task_number]['attempts'] - except: - self.child_attempts = 0 + self.child_history=instance_state.get('child_history',[]) + self.child_state=instance_state.get('child_state', self.INITIAL) + self.child_created = instance_state.get('child_created', False) + self.child_attempts = instance_state.get('child_attempts', 0) self.max_attempts = static_data['max_attempts'] self.child_prompt = static_data['prompt'] @@ -233,11 +217,11 @@ class OpenEndedChild(object): state = { 'version': self.STATE_VERSION, - 'history': self.child_history, - 'state': self.child_state, + 'child_history': self.child_history, + 'child_state': self.child_state, 'max_score': self._max_score, - 'attempts': self.child_attempts, - 'created': False, + 'child_attempts': self.child_attempts, + 'child_created': False, } return json.dumps(state) @@ -275,7 +259,7 @@ class OpenEndedChild(object): ''' if self._max_score > 0: try: - return Progress(self.get_score()['score'], self._max_score) + return Progress(int(self.get_score()['score']), int(self._max_score)) except Exception as err: #This is a dev_facing_error log.exception("Got bad progress from open ended child module. Max Score: {0}".format(self._max_score))