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
Commits
7920bd68
Commit
7920bd68
authored
1 year ago
by
Tim Repke
Browse files
Options
Downloads
Patches
Plain Diff
add route for querying label-dependent assignment progress
parent
d594345b
No related branches found
No related tags found
1 merge request
!40
Master
Pipeline
#1415
passed
1 year ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/api/routes/annotations.py
+54
-9
54 additions, 9 deletions
server/api/routes/annotations.py
server/util/security.py
+1
-1
1 addition, 1 deletion
server/util/security.py
with
55 additions
and
10 deletions
server/api/routes/annotations.py
+
54
−
9
View file @
7920bd68
import
uuid
from
typing
import
TYPE_CHECKING
from
typing
import
TYPE_CHECKING
from
pydantic
import
BaseModel
from
pydantic
import
BaseModel
from
sqlalchemy
import
select
from
sqlalchemy
import
select
,
asc
,
join
,
and_
from
sqlalchemy.orm
import
load_only
from
sqlalchemy.orm
import
load_only
from
fastapi
import
APIRouter
,
Depends
,
HTTPException
,
status
as
http_status
,
Query
from
fastapi
import
APIRouter
,
Depends
,
HTTPException
,
status
as
http_status
,
Query
...
@@ -9,7 +10,7 @@ from nacsos_data.db.schemas import \
...
@@ -9,7 +10,7 @@ from nacsos_data.db.schemas import \
BotAnnotationMetaData
,
\
BotAnnotationMetaData
,
\
AssignmentScope
,
\
AssignmentScope
,
\
User
,
\
User
,
\
Annotation
Annotation
,
Assignment
from
nacsos_data.models.annotations
import
\
from
nacsos_data.models.annotations
import
\
AnnotationSchemeModel
,
\
AnnotationSchemeModel
,
\
AssignmentScopeModel
,
\
AssignmentScopeModel
,
\
...
@@ -286,6 +287,49 @@ async def get_assignments(assignment_scope_id: str, permissions=Depends(UserPerm
...
@@ -286,6 +287,49 @@ async def get_assignments(assignment_scope_id: str, permissions=Depends(UserPerm
return
assignments
return
assignments
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
@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
()
return
[
ProgressIndicator
.
parse_obj
(
r
)
for
r
in
results
]
@router.get
(
'
/annotate/assignments/scope/{assignment_scope_id}
'
,
response_model
=
list
[
AssignmentModel
])
@router.get
(
'
/annotate/assignments/scope/{assignment_scope_id}
'
,
response_model
=
list
[
AssignmentModel
])
async
def
get_assignments_for_scope
(
assignment_scope_id
:
str
,
async
def
get_assignments_for_scope
(
assignment_scope_id
:
str
,
permissions
=
Depends
(
UserPermissionChecker
(
'
annotations_read
'
)))
\
permissions
=
Depends
(
UserPermissionChecker
(
'
annotations_read
'
)))
\
...
@@ -364,11 +408,12 @@ async def make_assignments(payload: MakeAssignmentsRequestModel,
...
@@ -364,11 +408,12 @@ async def make_assignments(payload: MakeAssignmentsRequestModel,
detail
=
str
(
e
))
detail
=
str
(
e
))
elif
payload
.
config
.
config_type
==
'
random_exclusion
'
:
elif
payload
.
config
.
config_type
==
'
random_exclusion
'
:
try
:
try
:
assignments
=
await
random_assignments_with_exclusion
(
assignment_scope_id
=
payload
.
scope_id
,
assignments
=
await
random_assignments_with_exclusion
(
annotation_scheme_id
=
payload
.
annotation_scheme_id
,
assignment_scope_id
=
payload
.
scope_id
,
project_id
=
permissions
.
permissions
.
project_id
,
annotation_scheme_id
=
payload
.
annotation_scheme_id
,
config
=
payload
.
config
,
# type: ignore[arg-type] # FIXME
project_id
=
permissions
.
permissions
.
project_id
,
engine
=
db_engine
)
config
=
payload
.
config
,
# type: ignore[arg-type] # FIXME
engine
=
db_engine
)
except
ValueError
as
e
:
except
ValueError
as
e
:
raise
HTTPException
(
status_code
=
http_status
.
HTTP_400_BAD_REQUEST
,
raise
HTTPException
(
status_code
=
http_status
.
HTTP_400_BAD_REQUEST
,
detail
=
str
(
e
))
detail
=
str
(
e
))
...
@@ -516,7 +561,7 @@ async def list_saved_resolved_annotations(permissions=Depends(UserPermissionChec
...
@@ -516,7 +561,7 @@ async def list_saved_resolved_annotations(permissions=Depends(UserPermissionChec
return
[
BotAnnotationMetaDataBaseModel
.
parse_obj
(
e
.
__dict__
)
for
e
in
exports
]
return
[
BotAnnotationMetaDataBaseModel
.
parse_obj
(
e
.
__dict__
)
for
e
in
exports
]
@router.get
(
'
/config/resolved/
:
bot_annotation_meta_id
'
,
response_model
=
SavedResolutionResponse
)
@router.get
(
'
/config/resolved/
{
bot_annotation_meta_id
}
'
,
response_model
=
SavedResolutionResponse
)
async
def
get_saved_resolved_annotations
(
bot_annotation_metadata_id
:
str
,
async
def
get_saved_resolved_annotations
(
bot_annotation_metadata_id
:
str
,
permissions
=
Depends
(
UserPermissionChecker
(
'
annotations_edit
'
))):
permissions
=
Depends
(
UserPermissionChecker
(
'
annotations_edit
'
))):
bot_annotations
=
await
read_bot_annotations
(
bot_annotation_metadata_id
=
bot_annotation_metadata_id
,
bot_annotations
=
await
read_bot_annotations
(
bot_annotation_metadata_id
=
bot_annotation_metadata_id
,
...
@@ -533,7 +578,7 @@ async def get_saved_resolved_annotations(bot_annotation_metadata_id: str,
...
@@ -533,7 +578,7 @@ async def get_saved_resolved_annotations(bot_annotation_metadata_id: str,
)
)
@router.delete
(
'
/config/resolved/
:
bot_annotation_meta_id
'
)
@router.delete
(
'
/config/resolved/
{
bot_annotation_meta_id
}
'
)
async
def
delete_saved_resolved_annotations
(
bot_annotation_metadata_id
:
str
,
async
def
delete_saved_resolved_annotations
(
bot_annotation_metadata_id
:
str
,
permissions
=
Depends
(
UserPermissionChecker
(
'
annotations_edit
'
))):
permissions
=
Depends
(
UserPermissionChecker
(
'
annotations_edit
'
))):
async
with
db_engine
.
session
()
as
session
:
# type: AsyncSession
async
with
db_engine
.
session
()
as
session
:
# type: AsyncSession
...
...
This diff is collapsed.
Click to expand it.
server/util/security.py
+
1
−
1
View file @
7920bd68
from
fastapi
import
Depends
,
HTTPException
,
status
as
http_status
,
Header
from
fastapi
import
Depends
,
status
as
http_status
,
Header
from
fastapi.security
import
OAuth2PasswordBearer
from
fastapi.security
import
OAuth2PasswordBearer
from
nacsos_data.models.users
import
UserModel
,
UserInDBModel
from
nacsos_data.models.users
import
UserModel
,
UserInDBModel
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment