diff --git a/h/services/bulk_api/lms_stats.py b/h/services/bulk_api/lms_stats.py index 73cfa059f51..5966a1f0e06 100644 --- a/h/services/bulk_api/lms_stats.py +++ b/h/services/bulk_api/lms_stats.py @@ -36,7 +36,7 @@ def _annotation_query( self, groups: list[str], h_userids: list[str] | None = None, - assignment_id: str | None = None, + assignment_ids: list[str] | None = None, ): query = ( select( @@ -77,10 +77,11 @@ def _annotation_query( Group.authority_provided_id.in_(groups), ) ) - if assignment_id: + if assignment_ids: query = query.where( - AnnotationMetadata.data["lms"]["assignment"]["resource_link_id"].astext - == assignment_id, + AnnotationMetadata.data["lms"]["assignment"][ + "resource_link_id" + ].astext.in_(assignment_ids) ) if h_userids: @@ -106,7 +107,7 @@ def get_annotation_counts( groups: list[str], group_by: CountsGroupBy, h_userids: list[str] | None = None, - assignment_id: str | None = None, + assignment_ids: list[str] | None = None, ) -> list[AnnotationCounts]: """ Get basic stats per user for an LMS assignment. @@ -114,10 +115,10 @@ def get_annotation_counts( :param groups: List of "authority_provided_id" to filter groups by. :param group_by: By which column to aggregate the data. :param h_userids: List of User.userid to filter annotations by - :param assignment_id: ID of the assignment to filter annotations by + :param assignment_ids: ID of the assignment to filter annotations by """ annos_query = self._annotation_query( - groups, h_userids=h_userids, assignment_id=assignment_id + groups, h_userids=h_userids, assignment_ids=assignment_ids ).cte("annotations") # Alias some columns diff --git a/h/views/api/bulk/annotation_counts.json b/h/views/api/bulk/annotation_counts.json index 06fe8aea9e3..44aea36f85b 100644 --- a/h/views/api/bulk/annotation_counts.json +++ b/h/views/api/bulk/annotation_counts.json @@ -31,10 +31,14 @@ "h_userids": { "$ref": "#/$defs/nonEmptyStringArray" }, - "assignment_id": { - "type": [ - "string", - "null" + "assignment_ids": { + "anyOf": [ + { + "ref": "#/$defs/nonEmptyStringArray" + }, + { + "type": "null" + } ] } }, diff --git a/h/views/api/bulk/stats.py b/h/views/api/bulk/stats.py index 39c36c84b45..b73490d35cd 100644 --- a/h/views/api/bulk/stats.py +++ b/h/views/api/bulk/stats.py @@ -31,7 +31,7 @@ def get_annotation_counts(request): stats = request.find_service(BulkLMSStatsService).get_annotation_counts( group_by=CountsGroupBy[data["group_by"].upper()], groups=query_filter["groups"], - assignment_id=query_filter.get("assignment_id"), + assignment_ids=query_filter.get("assignment_ids"), h_userids=query_filter.get("h_userids"), ) diff --git a/tests/unit/h/services/bulk_api/lms_stats_test.py b/tests/unit/h/services/bulk_api/lms_stats_test.py index b18b041d67d..fcdca2c8015 100644 --- a/tests/unit/h/services/bulk_api/lms_stats_test.py +++ b/tests/unit/h/services/bulk_api/lms_stats_test.py @@ -17,7 +17,7 @@ def test_get_annotation_counts_by_user( ): stats = svc.get_annotation_counts( groups=[group.authority_provided_id], - assignment_id="ASSIGNMENT_ID", + assignment_ids=["ASSIGNMENT_ID"], group_by=CountsGroupBy.USER, ) diff --git a/tests/unit/h/views/api/bulk/stats_test.py b/tests/unit/h/views/api/bulk/stats_test.py index b17b3630c20..862b4ece048 100644 --- a/tests/unit/h/views/api/bulk/stats_test.py +++ b/tests/unit/h/views/api/bulk/stats_test.py @@ -38,7 +38,7 @@ def test_get_annotation_counts( bulk_stats_service.get_annotation_counts.assert_called_once_with( group_by=CountsGroupBy.USER, groups=assignment_request["filter"]["groups"], - assignment_id=assignment_request["filter"]["assignment_id"], + assignment_ids=assignment_request["filter"]["assignment_ids"], h_userids=assignment_request["filter"]["h_userids"], ) return_data = [ @@ -63,7 +63,7 @@ def assignment_request(self, pyramid_request): "filter": { "groups": ["3a022b6c146dfd9df4ea8662178eac"], "h_userids": ["acc:user@authority"], - "assignment_id": "ASSIGNMENT_ID", + "assignment_ids": ["ASSIGNMENT_ID"], }, }