From d8906faaf205490722525a6f5b7a190a519f590d Mon Sep 17 00:00:00 2001 From: Michael Roytman Date: Wed, 4 Sep 2019 11:15:48 -0400 Subject: [PATCH] add additional logging --- lms/djangoapps/grades/scores.py | 20 ++++++++++++++++++++ lms/djangoapps/grades/subsection_grade.py | 20 +++++++++++++++++++- lms/djangoapps/grades/tests/test_scores.py | 9 ++++++--- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/lms/djangoapps/grades/scores.py b/lms/djangoapps/grades/scores.py index 3304638753..8a30e5f14a 100644 --- a/lms/djangoapps/grades/scores.py +++ b/lms/djangoapps/grades/scores.py @@ -103,6 +103,10 @@ def get_score(submissions_scores, csm_scores, persisted_block, block): weight, graded - retrieved from the latest block content """ weight = _get_weight_from_block(persisted_block, block) + # TODO: Remove as part of EDUCATOR-4602. + if str(block.location.course_key) == 'course-v1:UQx+BUSLEAD5x+2T2019': + log.info(u'Weight for block: ***{}*** is {}' + .format(str(block.location), weight)) # Priority order for retrieving the scores: # submissions API -> CSM -> grades persisted block -> latest block content @@ -112,6 +116,13 @@ def get_score(submissions_scores, csm_scores, persisted_block, block): _get_score_from_persisted_or_latest_block(persisted_block, block, weight) ) + # TODO: Remove as part of EDUCATOR-4602. + if str(block.location.course_key) == 'course-v1:UQx+BUSLEAD5x+2T2019': + log.info(u'Calculated raw-earned: {}, raw_possible: {}, weighted_earned: ' + u'{}, weighted_possible: {}, first_attempted: {} for block: ***{}***.' + .format(raw_earned, raw_possible, weighted_earned, + weighted_possible, first_attempted, str(block.location))) + if weighted_possible is None or weighted_earned is None: return None @@ -209,6 +220,11 @@ def _get_score_from_persisted_or_latest_block(persisted_block, block, weight): Uses the raw_possible value from the persisted_block if found, else from the latest block content. """ + # TODO: Remove as part of EDUCATOR-4602. + if str(block.location.course_key) == 'course-v1:UQx+BUSLEAD5x+2T2019': + log.info(u'Using _get_score_from_persisted_or_latest_block to calculate score for block: ***{}***.'.format( + str(block.location) + )) raw_earned = 0.0 first_attempted = None @@ -216,6 +232,10 @@ def _get_score_from_persisted_or_latest_block(persisted_block, block, weight): raw_possible = persisted_block.raw_possible else: raw_possible = block.transformer_data[GradesTransformer].max_score + # TODO: Remove as part of EDUCATOR-4602. + if str(block.location.course_key) == 'course-v1:UQx+BUSLEAD5x+2T2019': + log.info(u'Using latest block content to calculate score for block: ***{}***.') + log.info(u'weight for block: ***{}*** is {}.'.format(str(block.location), raw_possible)) # TODO TNL-5982 remove defensive code for scorables without max_score if raw_possible is None: diff --git a/lms/djangoapps/grades/subsection_grade.py b/lms/djangoapps/grades/subsection_grade.py index e1c5de9a91..31412e3c1c 100644 --- a/lms/djangoapps/grades/subsection_grade.py +++ b/lms/djangoapps/grades/subsection_grade.py @@ -167,21 +167,39 @@ class NonZeroSubsectionGrade(six.with_metaclass(ABCMeta, SubsectionGradeBase)): csm_scores, persisted_block=None, ): + # TODO: Remove as part of EDUCATOR-4602. + if str(block_key.course_key) == 'course-v1:UQx+BUSLEAD5x+2T2019': + log.info(u'Computing block score for block: ***{}*** in course: ***{}***.'.format( + str(block_key), + str(block_key.course_key), + )) try: block = course_structure[block_key] except KeyError: + # TODO: Remove as part of EDUCATOR-4602. + if str(block_key.course_key) == 'course-v1:UQx+BUSLEAD5x+2T2019': + log.info(u'User\'s access to block: ***{}*** in course: ***{}*** has changed. ' + u'No block score calculated.'.format(str(block_key), str(block_key.course_key))) # It's possible that the user's access to that # block has changed since the subsection grade # was last persisted. - pass else: if getattr(block, 'has_score', False): + # TODO: Remove as part of EDUCATOR-4602. + if str(block_key.course_key) == 'course-v1:UQx+BUSLEAD5x+2T2019': + log.info(u'Block: ***{}*** in course: ***{}*** HAS has_score attribute. Continuing.' + .format(str(block_key), str(block_key.course_key))) return get_score( submissions_scores, csm_scores, persisted_block, block, ) + # TODO: Remove as part of EDUCATOR-4602. + if str(block_key.course_key) == 'course-v1:UQx+BUSLEAD5x+2T2019': + log.info(u'Block: ***{}*** in course: ***{}*** DOES NOT HAVE has_score attribute. ' + u'No block score calculated.' + .format(str(block_key), str(block_key.course_key))) @staticmethod def _aggregated_score_from_model(grade_model, is_graded): diff --git a/lms/djangoapps/grades/tests/test_scores.py b/lms/djangoapps/grades/tests/test_scores.py index c067ca0cf6..8dc43d4cc2 100644 --- a/lms/djangoapps/grades/tests/test_scores.py +++ b/lms/djangoapps/grades/tests/test_scores.py @@ -77,7 +77,8 @@ class TestGetScore(TestCase): Tests for get_score """ display_name = 'test_name' - location = 'test_location' + course_key = CourseLocator(u'org', u'course', u'run') + location = BlockUsageLocator(course_key, 'problem', 'mock_block_id') SubmissionValue = namedtuple('SubmissionValue', 'exists, points_earned, points_possible, created_at') SubmissionValue.__repr__ = submission_value_repr @@ -96,7 +97,7 @@ class TestGetScore(TestCase): Creates a stub result from the submissions API for the given values. """ if submission_value.exists: - return {self.location: submission_value._asdict()} + return {str(self.location): submission_value._asdict()} else: return {} @@ -309,13 +310,15 @@ class TestInternalGetScoreFromBlock(TestCase): """ Tests the internal helper method: _get_score_from_persisted_or_latest_block """ + course_key = CourseLocator(u'org', u'course', u'run') + location = BlockUsageLocator(course_key, 'problem', 'mock_block_id') def _create_block(self, raw_possible): """ Creates and returns a minimal BlockData object with the give value for raw_possible. """ - block = BlockData('any_key') + block = BlockData(self.location) block.transformer_data.get_or_create(GradesTransformer).max_score = raw_possible return block