Skip to content

Commit fa94b23

Browse files
authored
Merge pull request #131 from eduNEXT/mgs/grade-api-docs
Add documentation for the Grades API.
2 parents 60c0c76 + b77584c commit fa94b23

File tree

4 files changed

+97
-9
lines changed

4 files changed

+97
-9
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Change Log
1111
.. There should always be an "Unreleased" section for changes pending release.
1212
Unreleased
1313
----------
14+
Added
15+
~~~~~
16+
* New Grades API to retrieve grades from a single user on a course.
1417

1518
[4.0.0] - 2021-1-20
1619
--------------------

eox_core/api/v1/serializers.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ class EdxappGradingPolicySerializer(serializers.Serializer):
257257
"""
258258
Serializes the course grading policy
259259
"""
260-
grader = EdxappGradingRawPolicySerializer(many=True, required=False, source="GRADER")
260+
grader = EdxappGradingRawPolicySerializer(many=True, source="GRADER")
261261
grade_cutoffs = serializers.DictField(child=serializers.FloatField(), source="GRADE_CUTOFFS")
262262

263263

@@ -268,3 +268,37 @@ class EdxappGradeSerializer(serializers.Serializer):
268268
earned_grade = serializers.FloatField()
269269
grading_policy = EdxappGradingPolicySerializer(required=False)
270270
section_breakdown = EdxappSectionBreakdownSerializer(many=True, required=False)
271+
272+
class Meta:
273+
"""
274+
Add extra details for swagger
275+
"""
276+
swagger_schema_fields = {
277+
"example":
278+
{
279+
"earned_grade": 0.5,
280+
"grading_policy": {
281+
"grader": [
282+
{
283+
"assignment_type": "Homework",
284+
"count": 1,
285+
"dropped": 0,
286+
"weight": 1.0
287+
}
288+
],
289+
"grade_cutoffs": {
290+
"Pass": 0.5
291+
}
292+
},
293+
"section_breakdown": [
294+
{
295+
"attempted": True,
296+
"assignment_type": "Homework",
297+
"percent": 0.5,
298+
"score_earned": 5,
299+
"score_possible": 10,
300+
"subsection_name": "Homework - Questions"
301+
}
302+
]
303+
}
304+
}

eox_core/api/v1/tests/test_grades.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ def test_get_grade_no_detail_no_policy( # pylint: disable=too-many-arguments
4646
get_edxapp_user.return_value.username = "test"
4747
get_enrollment.return_value = None, None
4848
grade_factory.return_value.return_value.read.return_value.percent = 0.5
49-
grade_factory.return_value.return_value.read.return_value.subsection_grades = []
50-
get_courseware_courses.return_value.get_course_by_id.return_value.grading_policy = (
51-
{}
52-
)
5349
params = {
5450
"course_id": "course-v1:org+course+run",
5551
"username": "test",
@@ -116,7 +112,8 @@ def test_get_grade_detail_policy( # pylint: disable=too-many-arguments
116112
grade_factory.return_value.return_value.read.return_value.percent = 0.5
117113
grade_factory.return_value.return_value.read.return_value.subsection_grades = {}
118114
get_courseware_courses.return_value.get_course_by_id.return_value.grading_policy = {
119-
"GRADE_CUTOFFS": {}
115+
"GRADE_CUTOFFS": {},
116+
"GRADER": [],
120117
}
121118
params = {
122119
"username": "test",
@@ -126,7 +123,7 @@ def test_get_grade_detail_policy( # pylint: disable=too-many-arguments
126123
}
127124
expected_response = {
128125
"earned_grade": 0.5,
129-
"grading_policy": {"grade_cutoffs": {}},
126+
"grading_policy": {"grade_cutoffs": {}, "grader": []},
130127
"section_breakdown": [],
131128
}
132129

eox_core/api/v1/views.py

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,20 +695,74 @@ class EdxappGrade(UserQueryMixin, APIView):
695695
permission_classes = (EoxCoreAPIPermission,)
696696
renderer_classes = (JSONRenderer, BrowsableAPIRenderer)
697697

698+
@apidocs.schema(
699+
parameters=[
700+
apidocs.query_parameter(
701+
name="username",
702+
param_type=str,
703+
description="**required**, The username used to identify a user enrolled on the course. Use either username or email.",
704+
),
705+
apidocs.query_parameter(
706+
name="email",
707+
param_type=str,
708+
description="**required**, The email used to identify a user enrolled on the course. Use either username or email.",
709+
),
710+
apidocs.query_parameter(
711+
name="course_id",
712+
param_type=str,
713+
description="**required**, The course id for the enrollment you want to check.",
714+
),
715+
apidocs.query_parameter(
716+
name="detailed",
717+
param_type=bool,
718+
description="**optional**, If true include detailed data for each graded subsection",
719+
),
720+
apidocs.query_parameter(
721+
name="grading_policy",
722+
param_type=bool,
723+
description="**optional**, If true include course grading policy.",
724+
),
725+
],
726+
responses={
727+
200: EdxappGradeSerializer,
728+
400: "Bad request, missing course_id or either email or username",
729+
404: "User, course or enrollment not found",
730+
},
731+
)
698732
def get(self, request):
699733
"""
700734
Retrieves Grades information for given a user and course_id
701735
702736
**Example Requests**
703737
704-
GET /eox-core/api/v1/grade/?username=johndoe&
705-
course_id=course-v1:edX+DemoX+Demo_Course
738+
GET /eox-core/api/v1/grade/?username=johndoe&course_id=course-v1:edX+DemoX+Demo_Course
706739
707740
Request data: {
708741
"username": "johndoe",
709742
"course_id": "course-v1:edX+DemoX+Demo_Course",
710743
}
711744
745+
**Response details**
746+
747+
- `earned_grade`: Final user score for the course.
748+
- `section_breakdown` (**optional**): Details of each grade subsection.
749+
- `attempted`: Whether the learner attempted the assignment.
750+
- `assignment_type`: General category of the assignment.
751+
- `percent`: Grade obtained by the user on this subsection.
752+
- `score_earned`: The score a user earned on this subsection.
753+
- `score_possible`: Highest possible score a user can earn on this subsection.
754+
- `subsection_name`: Name of the subsection.
755+
- `grading_policy` (**optional**): Course grading policy.
756+
- `grade_cutoff`: Score needed to reach each grade.
757+
- `grader`: Details of each assignment type used by the Grader.
758+
- `assignment_type`: General category of the assignment.
759+
- `count`: Number of assignments of this type.
760+
- `dropped`: The number of assignments of this type that the grader will drop. The grader will drop the lowest-scored assignments first.
761+
- `weight`: Weight of this type of assignment towards the final grade.
762+
763+
More information about grading can be found in the
764+
[edX documentation](https://edx.readthedocs.io/projects/open-edx-building-and-running-a-course/en/latest/student_progress/course_grades.html).
765+
712766
**Returns**
713767
714768
- 200: Success.

0 commit comments

Comments
 (0)