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
920baf4d
Commit
920baf4d
authored
1 year ago
by
Tim Repke
Browse files
Options
Downloads
Patches
Plain Diff
add bot annotation listing
parent
fcffd74b
No related branches found
No related tags found
1 merge request
!85
Master
Pipeline
#2916
passed
1 year ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/api/routes/annotations.py
+29
-2
29 additions, 2 deletions
server/api/routes/annotations.py
with
29 additions
and
2 deletions
server/api/routes/annotations.py
+
29
−
2
View file @
920baf4d
from
typing
import
TYPE_CHECKING
from
pydantic
import
BaseModel
from
sqlalchemy
import
select
from
sqlalchemy
import
select
,
func
as
F
,
distinct
from
sqlalchemy.orm
import
load_only
from
fastapi
import
APIRouter
,
Depends
,
HTTPException
,
status
as
http_status
,
Query
...
...
@@ -9,7 +9,7 @@ from nacsos_data.db.schemas import (
BotAnnotationMetaData
,
AssignmentScope
,
User
,
Annotation
Annotation
,
BotAnnotation
)
from
nacsos_data.models.annotations
import
(
AnnotationSchemeModel
,
...
...
@@ -553,3 +553,30 @@ async def delete_saved_resolved_annotations(bot_annotation_metadata_id: str,
await
session
.
delete
(
meta
)
# TODO: do we need to commit?
# TODO: ensure bot_annotations are deleted via cascade
class
BotMetaInfo
(
BotAnnotationMetaDataBaseModel
):
num_annotations
:
int
num_annotated_items
:
int
@router.get
(
'
/bot/annotations
'
)
async
def
get_bot_annotations
(
include_resolve
:
bool
=
False
,
permissions
=
Depends
(
UserPermissionChecker
(
'
annotations_read
'
)))
->
list
[
BotMetaInfo
]:
async
with
db_engine
.
session
()
as
session
:
# type: AsyncSession
stmt
=
(
select
(
BotAnnotationMetaData
,
F
.
count
(
BotAnnotation
.
bot_annotation_id
).
label
(
'
num_annotations
'
),
F
.
count
(
distinct
(
BotAnnotation
.
item_id
)).
label
(
'
num_annotated_items
'
))
.
join
(
BotAnnotation
,
BotAnnotation
.
bot_annotation_metadata_id
==
BotAnnotationMetaData
.
bot_annotation_metadata_id
)
# TODO: filter for != RESOLVE
.
where
(
BotAnnotationMetaData
.
project_id
==
permissions
.
permissions
.
project_id
)
.
group_by
(
BotAnnotationMetaData
.
bot_annotation_metadata_id
))
rslt
=
(
await
session
.
execute
(
stmt
)).
mappings
().
all
()
if
rslt
:
return
[
BotMetaInfo
.
model_validate
({
**
r
[
'
BotAnnotationMetaData
'
].
__dict__
,
'
num_annotations
'
:
r
[
'
num_annotations
'
],
'
num_annotated_items
'
:
r
[
'
num_annotated_items
'
]
})
for
r
in
rslt
]
return
[]
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