From 112fb4539bbb39579bcc47caa77fd8cfc56758fa Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Tue, 9 Apr 2013 14:43:41 -0400 Subject: [PATCH] Correctly calculate score for combinedopenended and peer assessment --- .../xmodule/combined_open_ended_module.py | 2 +- .../combined_open_ended_modulev1.py | 15 ++++++++----- .../xmodule/xmodule/peer_grading_module.py | 21 ++++++++++++++----- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/common/lib/xmodule/xmodule/combined_open_ended_module.py b/common/lib/xmodule/xmodule/combined_open_ended_module.py index 29d1270893..8337beab5a 100644 --- a/common/lib/xmodule/xmodule/combined_open_ended_module.py +++ b/common/lib/xmodule/xmodule/combined_open_ended_module.py @@ -14,7 +14,7 @@ from xmodule.open_ended_grading_classes.xblock_field_types import StringyFloat log = logging.getLogger("mitx.courseware") V1_SETTINGS_ATTRIBUTES = ["display_name", "attempts", "is_graded", "accept_file_upload", - "skip_spelling_checks", "due", "graceperiod"] + "skip_spelling_checks", "due", "graceperiod", "weight"] V1_STUDENT_ATTRIBUTES = ["current_task_number", "task_states", "state", "student_attempts", "ready_to_reset"] 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 5fa6e737d2..4d064824df 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 @@ -131,6 +131,7 @@ class CombinedOpenEndedV1Module(): self.state = instance_state.get('state', self.INITIAL) self.student_attempts = instance_state.get('student_attempts', 0) + self.weight = instance_state.get('weight', 1) #Allow reset is true if student has failed the criteria to move to the next child task self.ready_to_reset = instance_state.get('ready_to_reset', False) @@ -736,13 +737,17 @@ class CombinedOpenEndedV1Module(): max_score = None score = None if self.check_if_done_and_scored(): - last_response = self.get_last_response(self.current_task_number) - max_score = last_response['max_score'] - score = last_response['score'] + scores = [] + for i in xrange(0,self.current_task_number): + last_response = self.get_last_response(i) + max_score = last_response['max_score'] * float(self.weight) + score = last_response['score'] * float(self.weight) + scores.append(score) + score = max(scores) score_dict = { - 'score': score, - 'total': max_score, + 'score': score , + 'total': max_score , } return score_dict diff --git a/common/lib/xmodule/xmodule/peer_grading_module.py b/common/lib/xmodule/xmodule/peer_grading_module.py index 5075507bce..007446d57e 100644 --- a/common/lib/xmodule/xmodule/peer_grading_module.py +++ b/common/lib/xmodule/xmodule/peer_grading_module.py @@ -178,8 +178,16 @@ class PeerGradingModule(PeerGradingFields, XModule): pass def get_score(self): + max_score = None + score = None + score_dict = { + 'score': score, + 'total': max_score, + } if self.use_for_single_location not in TRUE_DICT or self.is_graded not in TRUE_DICT: - return None + return score_dict + + try: count_graded = self.student_data_for_location['count_graded'] @@ -198,10 +206,13 @@ class PeerGradingModule(PeerGradingFields, XModule): #Ensures that once a student receives a final score for peer grading, that it does not change. self.student_data_for_location = response - score_dict = { - 'score': int(count_graded >= count_required and count_graded>0) * int(self.weight), - 'total': self.max_grade * int(self.weight), - } + try: + score = int(count_graded >= count_required and count_graded>0) * float(self.weight) + total = self.max_grade * float(self.weight) + score_dict['score'] = score + score_dict['total'] = total + except: + pass return score_dict