Commit 2f6b7d1e by Vik Paruchuri

Better max score handling

parent 338a5776
...@@ -403,6 +403,7 @@ class CombinedOpenEndedV1Module(): ...@@ -403,6 +403,7 @@ class CombinedOpenEndedV1Module():
self.static_data, instance_state=task_state) self.static_data, instance_state=task_state)
last_response = task.latest_answer() last_response = task.latest_answer()
last_score = task.latest_score() last_score = task.latest_score()
all_scores = task.all_scores()
last_post_assessment = task.latest_post_assessment(self.system) last_post_assessment = task.latest_post_assessment(self.system)
last_post_feedback = "" last_post_feedback = ""
feedback_dicts = [{}] feedback_dicts = [{}]
...@@ -460,6 +461,7 @@ class CombinedOpenEndedV1Module(): ...@@ -460,6 +461,7 @@ class CombinedOpenEndedV1Module():
last_response_dict = { last_response_dict = {
'response': last_response, 'response': last_response,
'score': last_score, 'score': last_score,
'all_scores' : all_scores,
'post_assessment': last_post_assessment, 'post_assessment': last_post_assessment,
'type': task_type, 'type': task_type,
'max_score': max_score, 'max_score': max_score,
...@@ -738,21 +740,37 @@ class CombinedOpenEndedV1Module(): ...@@ -738,21 +740,37 @@ class CombinedOpenEndedV1Module():
""" """
max_score = None max_score = None
score = None score = None
if self.check_if_done_and_scored(): if self.is_scored and self.weight is not None:
#Finds the maximum score of all student attempts and keeps it. #Finds the maximum score of all student attempts and keeps it.
scores = [] score_mat = []
for i in xrange(0, self.current_task_number): for i in xrange(0, len(self.task_states)):
#For each task, extract all student scores on that task (each attempt for each task)
last_response = self.get_last_response(i) last_response = self.get_last_response(i)
try: max_score = last_response.get('max_score', None)
#This could fail if weight is not defined (is None), or if the last response does not have the needed data. score = last_response.get('all_scores', None)
#Neither is a critical issue, and that particular task score can be skipped for computation. if score is not None:
max_score = last_response['max_score'] * float(self.weight) #Convert none scores and weight scores properly
score = last_response['score'] * float(self.weight) for z in xrange(0,len(score)):
scores.append(score) if score[z] is None:
except: score[z] = 0
pass score[z] *= float(self.weight)
if len(scores) > 0: score_mat.append(score)
if len(score_mat) > 0:
#Currently, assume that the final step is the correct one, and that those are the final scores.
#This will change in the future, which is why the machinery above exists to extract all scores on all steps
#TODO: better final score handling.
scores = score_mat[-1]
score = max(scores) score = max(scores)
else:
score = 0
if max_score is not None:
#Weight the max score if it is not None
max_score *= float(self.weight)
else:
#Without a max_score, we cannot have a score!
score = None
score_dict = { score_dict = {
'score': score, 'score': score,
......
...@@ -162,6 +162,12 @@ class OpenEndedChild(object): ...@@ -162,6 +162,12 @@ class OpenEndedChild(object):
return None return None
return self.child_history[-1].get('score') return self.child_history[-1].get('score')
def all_scores(self):
"""None if not available"""
if not self.child_history:
return None
return [self.child_history[i].get('score') for i in xrange(0,len(self.child_history))]
def latest_post_assessment(self, system): def latest_post_assessment(self, system):
"""Empty string if not available""" """Empty string if not available"""
if not self.child_history: if not self.child_history:
......
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