Skip to content

Commit

Permalink
Expose roster information on the user metrics endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Nov 26, 2024
1 parent 6d1005a commit 9af7c04
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 48 deletions.
15 changes: 15 additions & 0 deletions lms/js_config_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,21 @@ class APIAssignments(TypedDict):
pagination: NotRequired[Pagination]


class RosterEntry(TypedDict):
student: APIStudent

active: bool
"Whether or not this student is active in the course/assignment or roster."


class APIRoster(TypedDict):
students: list[RosterEntry]

last_updated: datetime | None
"""When was this roster last updated.
None indicates we don't have roster data, we rely on launches to determine the list of students."""


class APIStudents(TypedDict):
students: list[APIStudent]

Expand Down
13 changes: 11 additions & 2 deletions lms/views/dashboard/api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

from lms.js_config_types import (
AnnotationMetrics,
APIRoster,
APIStudent,
APIStudents,
AutoGradingGrade,
RosterEntry,
)
from lms.models import Assignment, Organization, RoleScope, RoleType, User
from lms.security import Permissions
Expand Down Expand Up @@ -108,7 +110,7 @@ def students(self) -> APIStudents:
permission=Permissions.DASHBOARD_VIEW,
schema=UsersMetricsSchema,
)
def students_metrics(self) -> APIStudents:
def students_metrics(self) -> APIRoster:
"""Fetch the stats for one particular assignment."""
assignment = self.dashboard_service.get_request_assignment(
self.request, self.request.parsed_params["assignment_id"]
Expand Down Expand Up @@ -174,7 +176,14 @@ def students_metrics(self) -> APIStudents:
if assignment.auto_grading_config:
students = self._add_auto_grading_data(assignment, students)

return {"students": students}
# We are not expsoging the roster infor here yet, just making the API changes to better coordinate with the frontend
# For now we mark every roster entry as active and we don't include any last_activity.
return APIRoster(
students=[
RosterEntry(student=student, active=True) for student in students
],
last_updated=None,
)

def _add_auto_grading_data(
self, assignment: Assignment, api_students: list[APIStudent]
Expand Down
115 changes: 69 additions & 46 deletions tests/unit/lms/views/dashboard/api/user_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,36 +130,46 @@ def test_students_metrics(
expected = {
"students": [
{
"h_userid": student.h_userid,
"lms_id": student.user_id,
"display_name": student.display_name,
"annotation_metrics": {
"annotations": 4,
"replies": sentinel.replies,
"last_activity": datetime(2024, 1, 1),
"active": True,
"student": {
"h_userid": student.h_userid,
"lms_id": student.user_id,
"display_name": student.display_name,
"annotation_metrics": {
"annotations": 4,
"replies": sentinel.replies,
"last_activity": datetime(2024, 1, 1),
},
},
},
{
"h_userid": student_no_annos.h_userid,
"lms_id": student_no_annos.user_id,
"display_name": student_no_annos.display_name,
"annotation_metrics": {
"annotations": 0,
"replies": 0,
"last_activity": None,
"active": True,
"student": {
"h_userid": student_no_annos.h_userid,
"lms_id": student_no_annos.user_id,
"display_name": student_no_annos.display_name,
"annotation_metrics": {
"annotations": 0,
"replies": 0,
"last_activity": None,
},
},
},
{
"h_userid": student_no_annos_no_name.h_userid,
"lms_id": student_no_annos_no_name.user_id,
"display_name": None,
"annotation_metrics": {
"annotations": 0,
"replies": 0,
"last_activity": None,
"active": True,
"student": {
"h_userid": student_no_annos_no_name.h_userid,
"lms_id": student_no_annos_no_name.user_id,
"display_name": None,
"annotation_metrics": {
"annotations": 0,
"replies": 0,
"last_activity": None,
},
},
},
]
],
"last_updated": None,
}
assert response == expected

Expand Down Expand Up @@ -221,42 +231,52 @@ def test_students_metrics_with_auto_grading(
expected = {
"students": [
{
"h_userid": student.h_userid,
"lms_id": student.user_id,
"display_name": student.display_name,
"annotation_metrics": {
"annotations": 4,
"replies": sentinel.replies,
"last_activity": datetime(2024, 1, 1),
"student": {
"h_userid": student.h_userid,
"lms_id": student.user_id,
"display_name": student.display_name,
"annotation_metrics": {
"annotations": 4,
"replies": sentinel.replies,
"last_activity": datetime(2024, 1, 1),
},
},
"active": True,
},
{
"h_userid": student_no_annos.h_userid,
"lms_id": student_no_annos.user_id,
"display_name": student_no_annos.display_name,
"annotation_metrics": {
"annotations": 0,
"replies": 0,
"last_activity": None,
"student": {
"h_userid": student_no_annos.h_userid,
"lms_id": student_no_annos.user_id,
"display_name": student_no_annos.display_name,
"annotation_metrics": {
"annotations": 0,
"replies": 0,
"last_activity": None,
},
},
"active": True,
},
{
"h_userid": student_no_annos_no_name.h_userid,
"lms_id": student_no_annos_no_name.user_id,
"display_name": None,
"annotation_metrics": {
"annotations": 0,
"replies": 0,
"last_activity": None,
"student": {
"h_userid": student_no_annos_no_name.h_userid,
"lms_id": student_no_annos_no_name.user_id,
"display_name": None,
"annotation_metrics": {
"annotations": 0,
"replies": 0,
"last_activity": None,
},
},
"active": True,
},
]
],
"last_updated": None,
}
calls = []

last_grades = auto_grading_service.get_last_grades.return_value
for api_student in expected["students"]:
api_student["auto_grading_grade"] = {
api_student["student"]["auto_grading_grade"] = {
"current_grade": auto_grading_service.calculate_grade.return_value,
"last_grade": last_grades.get.return_value.grade
if with_last_grade
Expand All @@ -266,7 +286,10 @@ def test_students_metrics_with_auto_grading(
else None,
}
calls.append(
call(assignment.auto_grading_config, api_student["annotation_metrics"])
call(
assignment.auto_grading_config,
api_student["student"]["annotation_metrics"],
)
)

auto_grading_service.calculate_grade.assert_has_calls(calls)
Expand Down

0 comments on commit 9af7c04

Please sign in to comment.