Commit b7c6f7ca by Vik Paruchuri

Mostly working state

parent 0d777a7a
...@@ -195,6 +195,7 @@ class CombinedOpenEndedV1Module(): ...@@ -195,6 +195,7 @@ class CombinedOpenEndedV1Module():
last_response = last_response_data['response'] last_response = last_response_data['response']
loaded_task_state = json.loads(current_task_state) loaded_task_state = json.loads(current_task_state)
log.debug(loaded_task_state)
if loaded_task_state['child_state'] == self.INITIAL: if loaded_task_state['child_state'] == self.INITIAL:
loaded_task_state['child_state'] = self.ASSESSING loaded_task_state['child_state'] = self.ASSESSING
loaded_task_state['child_created'] = True loaded_task_state['child_created'] = True
...@@ -253,7 +254,6 @@ class CombinedOpenEndedV1Module(): ...@@ -253,7 +254,6 @@ class CombinedOpenEndedV1Module():
#This sends the etree_xml object through the descriptor module of the current task, and #This sends the etree_xml object through the descriptor module of the current task, and
#returns the xml parsed by the descriptor #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) 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: if current_task_state is None and self.current_task_number == 0:
self.current_task = child_task_module(self.system, self.location, self.current_task = child_task_module(self.system, self.location,
...@@ -264,7 +264,7 @@ class CombinedOpenEndedV1Module(): ...@@ -264,7 +264,7 @@ class CombinedOpenEndedV1Module():
last_response_data = self.get_last_response(self.current_task_number - 1) last_response_data = self.get_last_response(self.current_task_number - 1)
last_response = last_response_data['response'] last_response = last_response_data['response']
current_task_state = json.dumps({ current_task_state = json.dumps({
'state': self.ASSESSING, 'child_state': self.ASSESSING,
'version': self.STATE_VERSION, 'version': self.STATE_VERSION,
'max_score': self._max_score, 'max_score': self._max_score,
'child_attempts': 0, 'child_attempts': 0,
...@@ -276,6 +276,7 @@ class CombinedOpenEndedV1Module(): ...@@ -276,6 +276,7 @@ class CombinedOpenEndedV1Module():
instance_state=current_task_state) instance_state=current_task_state)
self.task_states.append(self.current_task.get_instance_state()) self.task_states.append(self.current_task.get_instance_state())
self.state = self.ASSESSING self.state = self.ASSESSING
log.debug(self.task_states)
else: else:
if self.current_task_number > 0 and not reset: if self.current_task_number > 0 and not reset:
current_task_state = self.overwrite_state(current_task_state) current_task_state = self.overwrite_state(current_task_state)
...@@ -394,7 +395,7 @@ class CombinedOpenEndedV1Module(): ...@@ -394,7 +395,7 @@ class CombinedOpenEndedV1Module():
task_parsed_xml = task_descriptor.definition_from_xml(etree_xml, self.system) 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, 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_response = task.latest_answer()
last_score = task.latest_score() last_score = task.latest_score()
last_post_assessment = task.latest_post_assessment(self.system) last_post_assessment = task.latest_post_assessment(self.system)
...@@ -479,7 +480,7 @@ class CombinedOpenEndedV1Module(): ...@@ -479,7 +480,7 @@ class CombinedOpenEndedV1Module():
if not self.allow_reset: if not self.allow_reset:
self.task_states[self.current_task_number] = self.current_task.get_instance_state() 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]) 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 self.current_task_number += 1
if self.current_task_number >= (len(self.task_xml)): if self.current_task_number >= (len(self.task_xml)):
self.state = self.DONE self.state = self.DONE
......
...@@ -65,7 +65,7 @@ class OpenEndedChild(object): ...@@ -65,7 +65,7 @@ class OpenEndedChild(object):
} }
def __init__(self, system, location, definition, descriptor, static_data, 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 # Load instance state
if instance_state is not None: if instance_state is not None:
...@@ -80,27 +80,11 @@ class OpenEndedChild(object): ...@@ -80,27 +80,11 @@ class OpenEndedChild(object):
# None for any element, and score and hint can be None for the last (current) # None for any element, and score and hint can be None for the last (current)
# element. # element.
# Scores are on scale from 0 to max_score # Scores are on scale from 0 to max_score
self._model_data = model_data
task_state = {}
try: self.child_history=instance_state.get('child_history',[])
self.child_history=instance_state['task_states'][task_number]['history'] self.child_state=instance_state.get('child_state', self.INITIAL)
except: self.child_created = instance_state.get('child_created', False)
self.child_history = [] self.child_attempts = instance_state.get('child_attempts', 0)
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.max_attempts = static_data['max_attempts'] self.max_attempts = static_data['max_attempts']
self.child_prompt = static_data['prompt'] self.child_prompt = static_data['prompt']
...@@ -233,11 +217,11 @@ class OpenEndedChild(object): ...@@ -233,11 +217,11 @@ class OpenEndedChild(object):
state = { state = {
'version': self.STATE_VERSION, 'version': self.STATE_VERSION,
'history': self.child_history, 'child_history': self.child_history,
'state': self.child_state, 'child_state': self.child_state,
'max_score': self._max_score, 'max_score': self._max_score,
'attempts': self.child_attempts, 'child_attempts': self.child_attempts,
'created': False, 'child_created': False,
} }
return json.dumps(state) return json.dumps(state)
...@@ -275,7 +259,7 @@ class OpenEndedChild(object): ...@@ -275,7 +259,7 @@ class OpenEndedChild(object):
''' '''
if self._max_score > 0: if self._max_score > 0:
try: 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: except Exception as err:
#This is a dev_facing_error #This is a dev_facing_error
log.exception("Got bad progress from open ended child module. Max Score: {0}".format(self._max_score)) log.exception("Got bad progress from open ended child module. Max Score: {0}".format(self._max_score))
......
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