From d754951cf8fd2ab5bc8e4f05587ff50cdf13e9d4 Mon Sep 17 00:00:00 2001 From: Carla Duarte Date: Mon, 12 Jul 2021 18:31:33 -0400 Subject: [PATCH] feat: add problem scores to progress tab api (AA-875) --- .../course_home_api/progress/v1/serializers.py | 11 +++++++++++ lms/djangoapps/course_home_api/progress/v1/views.py | 3 +++ 2 files changed, 14 insertions(+) diff --git a/lms/djangoapps/course_home_api/progress/v1/serializers.py b/lms/djangoapps/course_home_api/progress/v1/serializers.py index 12f9a947d5..977a6b34dd 100644 --- a/lms/djangoapps/course_home_api/progress/v1/serializers.py +++ b/lms/djangoapps/course_home_api/progress/v1/serializers.py @@ -27,6 +27,7 @@ class SubsectionScoresSerializer(serializers.Serializer): num_points_earned = serializers.FloatField(source='graded_total.earned') num_points_possible = serializers.FloatField(source='graded_total.possible') percent_graded = serializers.FloatField() + problem_scores = serializers.SerializerMethodField() show_correctness = serializers.CharField() show_grades = serializers.SerializerMethodField() url = serializers.SerializerMethodField() @@ -34,6 +35,16 @@ class SubsectionScoresSerializer(serializers.Serializer): def get_block_key(self, subsection): return str(subsection.location) + def get_problem_scores(self, subsection): + problem_scores = [ + { + 'earned': score.earned, + 'possible': score.possible, + } + for score in subsection.problem_scores.values() + ] + return problem_scores + def get_url(self, subsection): relative_path = reverse('jump_to', args=[self.context['course_key'], subsection.location]) request = self.context['request'] diff --git a/lms/djangoapps/course_home_api/progress/v1/views.py b/lms/djangoapps/course_home_api/progress/v1/views.py index 4b99578f25..a1b6985d7c 100644 --- a/lms/djangoapps/course_home_api/progress/v1/views.py +++ b/lms/djangoapps/course_home_api/progress/v1/views.py @@ -79,6 +79,9 @@ class ProgressTabView(RetrieveAPIView): num_points_earned: (int) the amount of points the user has earned for the given subsection num_points_possible: (int) the total amount of points possible for the given subsection percent_graded: (float) the percentage of total points the user has received a grade for in a given subsection + problem_scores: List of objects that represent individual problem scores with the following fields: + earned: (float) number of earned points + possible: (float) number of possible points show_correctness: (str) a str representing whether to show the problem/practice scores based on due date ('always', 'never', 'past_due', values defined in common/lib/xmodule/xmodule/modulestore/inheritance.py)