Commit 61c0a01b by Nimisha Asthagiri

Rename location_to_scores -> problem_scores

parent 70e13407
...@@ -313,7 +313,7 @@ class TestSubmittingProblems(ModuleStoreTestCase, LoginEnrollmentTestCase, Probl ...@@ -313,7 +313,7 @@ class TestSubmittingProblems(ModuleStoreTestCase, LoginEnrollmentTestCase, Probl
Returns list of scores for the given homework: Returns list of scores for the given homework:
[<points on problem_1>, <points on problem_2>, ..., <points on problem_n>] [<points on problem_1>, <points on problem_2>, ..., <points on problem_n>]
""" """
return [s.earned for s in self.hw_grade(hw_url_name).scores] return [s.earned for s in self.hw_grade(hw_url_name).problem_scores.values()]
class TestCourseGrades(TestSubmittingProblems): class TestCourseGrades(TestSubmittingProblems):
...@@ -337,7 +337,7 @@ class TestCourseGrades(TestSubmittingProblems): ...@@ -337,7 +337,7 @@ class TestCourseGrades(TestSubmittingProblems):
Verifies the problem score and the homework grade are as expected. Verifies the problem score and the homework grade are as expected.
""" """
hw_grade = self.hw_grade('homework') hw_grade = self.hw_grade('homework')
problem_score = hw_grade.scores[0] problem_score = hw_grade.problem_scores.values()[0]
self.assertEquals((problem_score.earned, problem_score.possible), expected_problem_score) self.assertEquals((problem_score.earned, problem_score.possible), expected_problem_score)
self.assertEquals((hw_grade.graded_total.earned, hw_grade.graded_total.possible), expected_hw_grade) self.assertEquals((hw_grade.graded_total.earned, hw_grade.graded_total.possible), expected_hw_grade)
......
...@@ -151,7 +151,7 @@ class TestGatedContent(MilestonesTestCaseMixin, SharedModuleStoreTestCase): ...@@ -151,7 +151,7 @@ class TestGatedContent(MilestonesTestCaseMixin, SharedModuleStoreTestCase):
""" """
course_grade = CourseGradeFactory().create(user, self.course) course_grade = CourseGradeFactory().create(user, self.course)
for prob in [self.gating_prob1, self.gated_prob2, self.prob3]: for prob in [self.gating_prob1, self.gated_prob2, self.prob3]:
self.assertIn(prob.location, course_grade.locations_to_scores) self.assertIn(prob.location, course_grade.problem_scores)
self.assertEquals(course_grade.percent, expected_percent) self.assertEquals(course_grade.percent, expected_percent)
......
...@@ -80,15 +80,15 @@ class CourseGradeBase(object): ...@@ -80,15 +80,15 @@ class CourseGradeBase(object):
return subsection_grades return subsection_grades
@lazy @lazy
def locations_to_scores(self): def problem_scores(self):
""" """
Returns a dict of problem scores keyed by their locations. Returns a dict of problem scores keyed by their locations.
""" """
locations_to_scores = {} problem_scores = {}
for chapter in self.chapter_grades.itervalues(): for chapter in self.chapter_grades.itervalues():
for subsection_grade in chapter['sections']: for subsection_grade in chapter['sections']:
locations_to_scores.update(subsection_grade.locations_to_scores) problem_scores.update(subsection_grade.problem_scores)
return locations_to_scores return problem_scores
def score_for_chapter(self, chapter_key): def score_for_chapter(self, chapter_key):
""" """
...@@ -112,8 +112,8 @@ class CourseGradeBase(object): ...@@ -112,8 +112,8 @@ class CourseGradeBase(object):
composite module (a vertical or section ) the scores will be the sums of composite module (a vertical or section ) the scores will be the sums of
all scored problems that are children of the chosen location. all scored problems that are children of the chosen location.
""" """
if location in self.locations_to_scores: if location in self.problem_scores:
score = self.locations_to_scores[location] score = self.problem_scores[location]
return score.earned, score.possible return score.earned, score.possible
children = self.course_data.structure.get_children(location) children = self.course_data.structure.get_children(location)
earned, possible = 0.0, 0.0 earned, possible = 0.0, 0.0
......
...@@ -35,11 +35,17 @@ class SubsectionGradeBase(object): ...@@ -35,11 +35,17 @@ class SubsectionGradeBase(object):
self.all_total = None # aggregated grade for all problems, regardless of whether they are graded self.all_total = None # aggregated grade for all problems, regardless of whether they are graded
@property @property
def scores(self): def attempted(self):
""" """
List of all problem scores in the subsection. Returns whether any problem in this subsection
was attempted by the student.
""" """
return self.locations_to_scores.values()
assert self.all_total is not None, (
"SubsectionGrade not fully populated yet. Call init_from_structure or init_from_model "
"before use."
)
return self.all_total.attempted
class ZeroSubsectionGrade(SubsectionGradeBase): class ZeroSubsectionGrade(SubsectionGradeBase):
...@@ -54,9 +60,9 @@ class ZeroSubsectionGrade(SubsectionGradeBase): ...@@ -54,9 +60,9 @@ class ZeroSubsectionGrade(SubsectionGradeBase):
self.course_data = course_data self.course_data = course_data
@lazy @lazy
def locations_to_scores(self): def problem_scores(self):
""" """
Overrides the locations_to_scores member variable in order Overrides the problem_scores member variable in order
to return empty scores for all scorable problems in the to return empty scores for all scorable problems in the
course. course.
""" """
...@@ -79,7 +85,7 @@ class SubsectionGrade(SubsectionGradeBase): ...@@ -79,7 +85,7 @@ class SubsectionGrade(SubsectionGradeBase):
""" """
def __init__(self, subsection): def __init__(self, subsection):
super(SubsectionGrade, self).__init__(subsection) super(SubsectionGrade, self).__init__(subsection)
self.locations_to_scores = OrderedDict() # dict of problem locations to ProblemScore self.problem_scores = OrderedDict() # dict of problem locations to ProblemScore
def init_from_structure(self, student, course_structure, submissions_scores, csm_scores): def init_from_structure(self, student, course_structure, submissions_scores, csm_scores):
""" """
...@@ -91,7 +97,7 @@ class SubsectionGrade(SubsectionGradeBase): ...@@ -91,7 +97,7 @@ class SubsectionGrade(SubsectionGradeBase):
): ):
self._compute_block_score(descendant_key, course_structure, submissions_scores, csm_scores) self._compute_block_score(descendant_key, course_structure, submissions_scores, csm_scores)
self.all_total, self.graded_total = graders.aggregate_scores(self.scores) self.all_total, self.graded_total = graders.aggregate_scores(self.problem_scores.values())
self._log_event(log.debug, u"init_from_structure", student) self._log_event(log.debug, u"init_from_structure", student)
return self return self
...@@ -180,7 +186,7 @@ class SubsectionGrade(SubsectionGradeBase): ...@@ -180,7 +186,7 @@ class SubsectionGrade(SubsectionGradeBase):
block, block,
) )
if problem_score: if problem_score:
self.locations_to_scores[block_key] = problem_score self.problem_scores[block_key] = problem_score
def _persisted_model_params(self, student): def _persisted_model_params(self, student):
""" """
...@@ -208,7 +214,7 @@ class SubsectionGrade(SubsectionGradeBase): ...@@ -208,7 +214,7 @@ class SubsectionGrade(SubsectionGradeBase):
return [ return [
BlockRecord(location, score.weight, score.raw_possible, score.graded) BlockRecord(location, score.weight, score.raw_possible, score.graded)
for location, score in for location, score in
self.locations_to_scores.iteritems() self.problem_scores.iteritems()
] ]
def _log_event(self, log_func, log_statement, student): def _log_event(self, log_func, log_statement, student):
......
...@@ -203,7 +203,7 @@ class TestWeightedProblems(SharedModuleStoreTestCase): ...@@ -203,7 +203,7 @@ class TestWeightedProblems(SharedModuleStoreTestCase):
# verify all problem grades # verify all problem grades
for problem in self.problems: for problem in self.problems:
problem_score = subsection_grade.locations_to_scores[problem.location] problem_score = subsection_grade.problem_scores[problem.location]
self.assertEqual(type(expected_score.first_attempted), type(problem_score.first_attempted)) self.assertEqual(type(expected_score.first_attempted), type(problem_score.first_attempted))
expected_score.first_attempted = problem_score.first_attempted expected_score.first_attempted = problem_score.first_attempted
self.assertEquals(problem_score, expected_score) self.assertEquals(problem_score, expected_score)
......
...@@ -358,7 +358,7 @@ class ZeroGradeTest(GradeTestBase): ...@@ -358,7 +358,7 @@ class ZeroGradeTest(GradeTestBase):
chapter_grades = ZeroCourseGrade(self.request.user, course_data).chapter_grades chapter_grades = ZeroCourseGrade(self.request.user, course_data).chapter_grades
for chapter in chapter_grades: for chapter in chapter_grades:
for section in chapter_grades[chapter]['sections']: for section in chapter_grades[chapter]['sections']:
for score in section.locations_to_scores.itervalues(): for score in section.problem_scores.itervalues():
self.assertEqual(score.earned, 0) self.assertEqual(score.earned, 0)
self.assertEqual(score.first_attempted, None) self.assertEqual(score.first_attempted, None)
self.assertEqual(section.all_total.earned, 0) self.assertEqual(section.all_total.earned, 0)
......
...@@ -1027,7 +1027,7 @@ def upload_problem_grade_report(_xmodule_instance_args, _entry_id, course_id, _t ...@@ -1027,7 +1027,7 @@ def upload_problem_grade_report(_xmodule_instance_args, _entry_id, course_id, _t
earned_possible_values = [] earned_possible_values = []
for block_location in graded_scorable_blocks: for block_location in graded_scorable_blocks:
try: try:
problem_score = course_grade.locations_to_scores[block_location] problem_score = course_grade.problem_scores[block_location]
except KeyError: except KeyError:
earned_possible_values.append([u'Not Available', u'Not Available']) earned_possible_values.append([u'Not Available', u'Not Available'])
else: else:
......
...@@ -179,10 +179,10 @@ from django.utils.http import urlquote_plus ...@@ -179,10 +179,10 @@ from django.utils.http import urlquote_plus
<em class="localized-datetime" data-datetime="${section.due}" data-string="${_('due {date}')}" data-timezone="${user_timezone}" data-language="${user_language}"></em> <em class="localized-datetime" data-datetime="${section.due}" data-string="${_('due {date}')}" data-timezone="${user_timezone}" data-language="${user_language}"></em>
%endif %endif
</p> </p>
%if len(section.scores) > 0: %if len(section.problem_scores.values()) > 0:
<dl class="scores"> <dl class="scores">
<dt class="hd hd-6">${ _("Problem Scores: ") if section.graded else _("Practice Scores: ")}</dt> <dt class="hd hd-6">${ _("Problem Scores: ") if section.graded else _("Practice Scores: ")}</dt>
%for score in section.scores: %for score in section.problem_scores.values():
<dd>${"{0:.3n}/{1:.3n}".format(float(score.earned),float(score.possible))}</dd> <dd>${"{0:.3n}/{1:.3n}".format(float(score.earned),float(score.possible))}</dd>
%endfor %endfor
</dl> </dl>
......
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