Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
NACSOS Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MCC APSIS
NACSOS
NACSOS Core
Merge requests
!41
Master
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Master
master
into
production
Overview
0
Commits
6
Pipelines
1
Changes
1
Merged
Tim Repke
requested to merge
master
into
production
1 year ago
Overview
0
Commits
6
Pipelines
1
Changes
1
Expand
0
0
Merge request reports
Viewing commit
1af3e91d
Prev
Next
Show latest version
1 file
+
44
−
29
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
1af3e91d
pimp the progress indicator route
· 1af3e91d
Tim Repke
authored
1 year ago
server/api/routes/annotations.py
+
44
−
29
Options
@@ -2,8 +2,9 @@ import uuid
from
typing
import
TYPE_CHECKING
from
pydantic
import
BaseModel
from
sqlalchemy
import
select
,
asc
,
join
,
and_
from
sqlalchemy
import
select
,
asc
,
join
,
and_
,
text
from
sqlalchemy.orm
import
load_only
from
sqlalchemy.dialects.postgresql
import
json
from
fastapi
import
APIRouter
,
Depends
,
HTTPException
,
status
as
http_status
,
Query
from
nacsos_data.db.schemas
import
\
@@ -287,46 +288,60 @@ 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
value_int
:
int
|
None
=
None
value_bool
:
bool
|
None
=
None
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
,
key
:
str
|
None
=
Query
(
default
=
None
),
repeat
:
int
|
None
=
Query
(
default
=
None
),
permissions
=
Depends
(
UserPermissionChecker
(
'
annotations_read
'
)))
\
->
list
[
ProgressIndicator
]:
async
with
db_engine
.
session
()
as
session
:
# type: AsyncSession
if
key
is
None
:
stmt
=
select
(
Assignment
.
assignment_id
,
Assignment
.
item_id
,
Assignment
.
order
,
Assignment
.
status
)
else
:
stmt
=
select
(
Assignment
.
assignment_id
,
Assignment
.
item_id
,
Assignment
.
order
,
Assignment
.
status
,
Annotation
.
value_int
,
Annotation
.
value_bool
)
\
.
select_from
(
join
(
left
=
Assignment
,
right
=
Annotation
,
onclause
=
and_
(
Assignment
.
assignment_id
==
Annotation
.
assignment_id
,
Annotation
.
repeat
==
(
1
if
repeat
is
None
else
repeat
),
Annotation
.
key
==
key
),
isouter
=
True
))
stmt
=
stmt
\
.
where
(
Assignment
.
user_id
==
permissions
.
user
.
user_id
,
Assignment
.
assignment_scope_id
==
assignment_scope_id
)
\
.
order_by
(
asc
(
Assignment
.
order
))
results
=
(
await
session
.
execute
(
stmt
)).
mappings
().
all
()
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
.
parse_obj
(
r
)
for
r
in
results
]
Loading