Commit 940a337d by Vik Paruchuri

Properly display student progress

parent bfca803b
...@@ -823,6 +823,16 @@ class CombinedOpenEndedV1Module(): ...@@ -823,6 +823,16 @@ class CombinedOpenEndedV1Module():
""" """
return (self.state == self.DONE or self.ready_to_reset) and self.is_scored return (self.state == self.DONE or self.ready_to_reset) and self.is_scored
def get_weight(self):
"""
Return the weight of the problem. The old default weight was None, so set to 1 in that case.
Output - int weight
"""
weight = self.weight
if weight is None:
weight = 1
return weight
def get_score(self): def get_score(self):
""" """
Score the student received on the problem, or None if there is no Score the student received on the problem, or None if there is no
...@@ -837,9 +847,7 @@ class CombinedOpenEndedV1Module(): ...@@ -837,9 +847,7 @@ class CombinedOpenEndedV1Module():
score = None score = None
#The old default was None, so set to 1 if it is the old default weight #The old default was None, so set to 1 if it is the old default weight
weight = self.weight weight = self.get_weight()
if weight is None:
weight = 1
if self.is_scored: if self.is_scored:
# Finds the maximum score of all student attempts and keeps it. # Finds the maximum score of all student attempts and keeps it.
score_mat = [] score_mat = []
...@@ -879,27 +887,41 @@ class CombinedOpenEndedV1Module(): ...@@ -879,27 +887,41 @@ class CombinedOpenEndedV1Module():
return score_dict return score_dict
def max_score(self): def max_score(self):
''' Maximum score. Two notes: """
Maximum score possible in this module. Returns the max score if finished, None if not.
* This is generic; in abstract, a problem could be 3/5 points on one """
randomization, and 5/7 on another
'''
max_score = None max_score = None
if self.check_if_done_and_scored(): if self.check_if_done_and_scored():
max_score = self._max_score max_score = self._max_score
return max_score return max_score
def get_progress(self): def get_progress(self):
''' Return a progress.Progress object that represents how far the """
Generate a progress object. Progress objects represent how far the
student has gone in this module. Must be implemented to get correct student has gone in this module. Must be implemented to get correct
progress tracking behavior in nesting modules like sequence and progress tracking behavior in nested modules like sequence and
vertical. vertical. This behavior is consistent with capa.
If this module has no notion of progress, return None. If the module is unscored, return None (consistent with capa).
''' """
progress_object = Progress(self.current_task_number, len(self.task_xml))
d = self.get_score()
score = d['score']
total = d['total']
if total > 0 and self.is_scored:
if self.weight is not None:
# scale score and total by weight/total:
score = score * self.get_weight() / total
total = self.get_weight()
try:
return Progress(score, total)
except (TypeError, ValueError):
log.exception("Got bad progress")
return None
return progress_object return None
def out_of_sync_error(self, data, msg=''): def out_of_sync_error(self, data, msg=''):
""" """
......
...@@ -22,6 +22,7 @@ from xmodule.open_ended_grading_classes.grading_service_module import GradingSer ...@@ -22,6 +22,7 @@ from xmodule.open_ended_grading_classes.grading_service_module import GradingSer
from xmodule.combined_open_ended_module import CombinedOpenEndedModule from xmodule.combined_open_ended_module import CombinedOpenEndedModule
from xmodule.modulestore import Location from xmodule.modulestore import Location
from xmodule.tests import get_test_system, test_util_open_ended from xmodule.tests import get_test_system, test_util_open_ended
from xmodule.progress import Progress
from xmodule.tests.test_util_open_ended import (MockQueryDict, DummyModulestore, TEST_STATE_SA_IN, from xmodule.tests.test_util_open_ended import (MockQueryDict, DummyModulestore, TEST_STATE_SA_IN,
MOCK_INSTANCE_STATE, TEST_STATE_SA, TEST_STATE_AI, TEST_STATE_AI2, TEST_STATE_AI2_INVALID, MOCK_INSTANCE_STATE, TEST_STATE_SA, TEST_STATE_AI, TEST_STATE_AI2, TEST_STATE_AI2_INVALID,
TEST_STATE_SINGLE, TEST_STATE_PE_SINGLE) TEST_STATE_SINGLE, TEST_STATE_PE_SINGLE)
...@@ -480,6 +481,29 @@ class CombinedOpenEndedModuleTest(unittest.TestCase): ...@@ -480,6 +481,29 @@ class CombinedOpenEndedModuleTest(unittest.TestCase):
max_score = self.combinedoe_container.max_score() max_score = self.combinedoe_container.max_score()
self.assertEqual(max_score, None) self.assertEqual(max_score, None)
def test_container_get_progress(self):
"""
See if we can get the progress from the actual xmodule
"""
progress = self.combinedoe_container.max_score()
self.assertEqual(progress, None)
def test_get_progress(self):
"""
Test if we can get the correct progress from the combined open ended class
"""
self.combinedoe.update_task_states()
self.combinedoe.state = "done"
self.combinedoe.is_scored = True
progress = self.combinedoe.get_progress()
self.assertIsInstance(progress, Progress)
#progress._a is the score of the xmodule, which is 0 right now
self.assertEqual(progress._a, 0)
#progress._b is the max_score (which is 1), divided by the weight (which is 1)
self.assertEqual(progress._b, 1)
def test_container_weight(self): def test_container_weight(self):
""" """
Check the problem weight in the container Check the problem weight in the container
......
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