Commit 4221a98f by Eric Fischer

Merge pull request #43 from edx/efischer/score_summary

Use score summaries in data download
parents feb2ae3d 8d14bab0
......@@ -447,27 +447,27 @@ def get_all_course_submission_information(course_id, item_type, read_replica=Tru
if read_replica:
submission_qs = _use_read_replica(submission_qs)
query = submission_qs.select_related('student_item').prefetch_related('score_set').filter(
query = submission_qs.select_related('student_item__scoresummary__latest__submission').filter(
student_item__course_id=course_id,
student_item__item_type=item_type,
).iterator()
for submission in query:
student_item = submission.student_item
if submission.score_set.count() > 0:
for score in submission.score_set.all():
yield (
StudentItemSerializer(student_item).data,
SubmissionSerializer(submission).data,
ScoreSerializer(score).data
)
else:
# Make sure we return submission information even if there isn't a score associated with it.
yield (
StudentItemSerializer(student_item).data,
SubmissionSerializer(submission).data,
{}
)
serialized_score = {}
if hasattr(student_item, 'scoresummary'):
latest_score = student_item.scoresummary.latest
# We only include the score for a given submission if it is not a reset score and it "counts", that is,
# if it is the latest score on the score summary tracking the submission's student_item. This matches the
# behavior of the API's get_score method.
if (not latest_score.is_hidden()) and latest_score.submission.uuid == submission.uuid:
serialized_score = ScoreSerializer(latest_score).data
yield (
StudentItemSerializer(student_item).data,
SubmissionSerializer(submission).data,
serialized_score
)
def get_top_submissions(course_id, item_id, item_type, number_of_top_scores, use_cache=True, read_replica=True):
......
......@@ -127,7 +127,8 @@ class TestSubmissionsApi(TestCase):
self.assertDictEqual(SECOND_STUDENT_ITEM, submissions_and_scores[1][0])
self._assert_submission(submissions_and_scores[1][1], submission3['answer'], student_item2.pk, 1)
self._assert_score(submissions_and_scores[1][2], 3, 4)
# submission4 also pertains to this student item and got its score later, so no score will be reported here
self.assertEqual(submissions_and_scores[1][2], {})
self.assertDictEqual(STUDENT_ITEM, submissions_and_scores[2][0])
self._assert_submission(submissions_and_scores[2][1], submission2['answer'], student_item1.pk, 2)
......@@ -135,7 +136,8 @@ class TestSubmissionsApi(TestCase):
self.assertDictEqual(STUDENT_ITEM, submissions_and_scores[3][0])
self._assert_submission(submissions_and_scores[3][1], submission1['answer'], student_item1.pk, 1)
self._assert_score(submissions_and_scores[3][2], 1, 4)
# submission2 also pertains to this student item and got its score later, so no score will be reported here
self.assertEqual(submissions_and_scores[3][2], {})
def test_get_submission(self):
# Test base case that we can create a submission and get it back
......
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