diff --git a/requirements.txt b/requirements.txt index e15d9965b6df37baaff4ba1bb28e3b030d17c4f0..7864c9faa4950728fb103595c4deb7bc2dc05da6 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 af60cb45299ee64ec683d35cd8dcfa7eda09f16d..d08134f1826f7531d56305e7f2e8d1bb81b4d2b8 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])