From 5f47a9bdea4c2e47053544098992647befde8613 Mon Sep 17 00:00:00 2001 From: Tim Repke <repke@mcc-berlin.net> Date: Fri, 18 Aug 2023 17:02:29 +0200 Subject: [PATCH] add route for annotation indicators --- requirements.txt | 2 +- server/api/routes/annotations.py | 63 ++++---------------------------- 2 files changed, 8 insertions(+), 57 deletions(-) diff --git a/requirements.txt b/requirements.txt index e15d996..7864c9f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,4 @@ httpx[http2]==0.24.1 pymitter==0.4.0 uvicorn==0.23.2 python-multipart==0.0.6 -nacsos_data[scripts,server] @ git+ssh://git@gitlab.pik-potsdam.de/mcc-apsis/nacsos/nacsos-data.git@v0.9.4 +nacsos_data[scripts,server] @ git+ssh://git@gitlab.pik-potsdam.de/mcc-apsis/nacsos/nacsos-data.git@v0.9.5 diff --git a/server/api/routes/annotations.py b/server/api/routes/annotations.py index af60cb4..d08134f 100644 --- a/server/api/routes/annotations.py +++ b/server/api/routes/annotations.py @@ -57,7 +57,7 @@ from nacsos_data.db.crud.annotations import \ UserProjectAssignmentScope, \ store_assignments, \ store_resolved_bot_annotations, \ - update_resolved_bot_annotations + update_resolved_bot_annotations, read_assignment_overview_for_scope, AssignmentScopeEntry from nacsos_data.util.annotations.resolve import \ AnnotationFilterObject, \ get_resolved_item_annotations, \ @@ -287,61 +287,12 @@ async def get_assignments(assignment_scope_id: str, permissions=Depends(UserPerm return assignments -class ProgressIndicatorLabel(BaseModel): - repeat: int - value_int: int | None = None - value_bool: bool | None = None - - -class ProgressIndicator(BaseModel): - assignment_id: str | uuid.UUID - item_id: str | uuid.UUID - order: int - status: AssignmentStatus - labels: dict[str, list[ProgressIndicatorLabel]] | None = None - - -@router.get('/annotate/assignment/progress/{assignment_scope_id}', response_model=list[ProgressIndicator]) -async def get_assignment_indicators_for_scope_for_user(assignment_scope_id: str, - permissions=Depends(UserPermissionChecker('annotations_read'))) \ - -> list[ProgressIndicator]: - async with db_engine.session() as session: # type: AsyncSession - stmt = text(''' - WITH tmp as (SELECT assignment.assignment_id, - assignment.item_id, - assignment."order", - assignment.status, - annotation.key, - jsonb_agg(jsonb_build_object('repeat', annotation.repeat, - 'value_bool', annotation.value_bool, - 'value_int', annotation.value_int)) as pl - FROM assignment - LEFT OUTER JOIN annotation ON assignment.assignment_id = annotation.assignment_id - WHERE assignment.user_id = :user_id - AND assignment.assignment_scope_id = :scope_id - GROUP BY assignment.assignment_id, - assignment.item_id, - assignment."order", - annotation.key) - SELECT assignment_id, - item_id, - "order", - status, - jsonb_object_agg(key, pl) filter (where key is not null ) as labels - FROM tmp - GROUP BY tmp.assignment_id, - tmp.item_id, - tmp."order", - tmp.status - ORDER BY tmp."order" ASC; - ''') - - results = (await session.execute(stmt, { - 'scope_id': assignment_scope_id, - 'user_id': permissions.user.user_id - })).mappings().all() - - return [ProgressIndicator.model_validate(r) for r in results] +@router.get('/annotate/assignment/progress/{assignment_scope_id}', response_model=list[AssignmentScopeEntry]) +async def get_assignment_indicators_for_scope(assignment_scope_id: str, + permissions=Depends(UserPermissionChecker('annotations_read'))) \ + -> list[AssignmentScopeEntry]: + return await read_assignment_overview_for_scope(assignment_scope_id=assignment_scope_id, + db_engine=db_engine) @router.get('/annotate/assignments/scope/{assignment_scope_id}', response_model=list[AssignmentModel]) -- GitLab