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
c969aaa8
Commit
c969aaa8
authored
1 year ago
by
Tim Repke
Browse files
Options
Downloads
Patches
Plain Diff
add export route wip
parent
2f0e6ef1
No related branches found
No related tags found
1 merge request
!45
Master
Pipeline
#1495
canceled
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/export.py
+17
-17
17 additions, 17 deletions
server/api/routes/export.py
with
17 additions
and
17 deletions
server/api/routes/export.py
+
17
−
17
View file @
c969aaa8
import
json
from
typing
import
TYPE_CHECKING
import
tempfile
import
csv
from
fastapi
import
APIRouter
,
Depends
,
Query
from
fastapi.responses
import
PlainTextResponse
...
...
@@ -9,10 +7,8 @@ from nacsos_data.db.schemas import AcademicItem, Project, ItemType, TwitterItem
from
nacsos_data.util.annotations.export
import
prepare_export_table
,
LabelSelector
from
server.util.security
import
\
UserPermissionChecker
,
\
InsufficientPermissions
UserPermissionChecker
from
nacsos_data.util.annotations
import
export
as
anno_export
from
nacsos_data.util.auth
import
UserPermissions
from
server.data
import
db_engine
...
...
@@ -25,30 +21,34 @@ router = APIRouter()
@router.get
(
'
/annotations/csv
'
,
response_class
=
PlainTextResponse
)
async
def
get_annotations_csv
(
labels
:
list
[
LabelSelector
],
bot_annotation_metadata_ids
:
list
[
str
]
|
None
=
Query
(
default
=
None
),
assignment_scope_ids
:
list
[
str
]
|
None
=
Query
(
default
=
None
),
user_ids
:
list
[
str
]
|
None
=
Query
(
default
=
None
),
item_fields
:
list
[
str
]
|
None
=
Query
(
default
=
None
),
permissions
:
UserPermissions
=
Depends
(
UserPermissionChecker
(
'
annotations_read
'
)))
\
bot_annotation_metadata_ids
:
list
[
str
]
|
None
=
Query
(
default
=
None
),
assignment_scope_ids
:
list
[
str
]
|
None
=
Query
(
default
=
None
),
user_ids
:
list
[
str
]
|
None
=
Query
(
default
=
None
),
item_fields
:
list
[
str
]
|
None
=
Query
(
default
=
None
),
permissions
:
UserPermissions
=
Depends
(
UserPermissionChecker
(
'
annotations_read
'
)))
\
->
str
:
async
with
db_engine
.
session
()
as
session
:
# type: AsyncSession
project
=
await
session
.
get
(
Project
,
permissions
.
permissions
.
project_id
)
if
project
is
None
:
raise
RuntimeError
(
'
This should not happen!
'
)
if
project
.
type
==
ItemType
.
academic
:
item_type
=
AcademicItem
item_type
=
AcademicItem
# type: ignore[assignment]
elif
project
.
type
==
ItemType
.
twitter
:
item_type
=
TwitterItem
item_type
=
TwitterItem
# type: ignore[assignment]
labels
=
await
prepare_export_table
(
bot_annotation_metadata_ids
=
bot_annotation_metadata_ids
,
result
=
await
prepare_export_table
(
bot_annotation_metadata_ids
=
bot_annotation_metadata_ids
,
assignment_scope_ids
=
assignment_scope_ids
,
user_ids
=
user_ids
,
labels
=
labels
,
item_fields
=
[
AcademicItem
.
text
,
AcademicItem
.
title
],
item_type
=
item_type
,
item_fields
=
[
AcademicItem
.
text
,
AcademicItem
.
title
],
# type: ignore[list-item]
item_type
=
item_type
,
# type: ignore[type-var]
db_engine
=
db_engine
)
ret
=
''
for
l
in
labels
[:
10
]:
ret
+=
json
.
dumps
(
l
)
+
'
\n
'
for
l
ab
in
result
[:
10
]:
ret
+=
json
.
dumps
(
l
ab
)
+
'
\n
'
return
ret
# with tempfile.TemporaryFile() as fp:
...
...
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