Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
ADEX-backend-fastapi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ASTRON SDC
ADEX-backend-fastapi
Commits
2b8f9208
Commit
2b8f9208
authored
Sep 6, 2022
by
Nico Vermaas
Browse files
Options
Downloads
Patches
Plain Diff
adding dataproduct_type, dataproduct_subtype, level, collection filters
parent
b85f52a0
No related branches found
No related tags found
1 merge request
!5
adding dataproduct_type, dataproduct_subtype, level, collection filters
Pipeline
#35489
passed
Sep 6, 2022
Stage: build
Changes
4
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+3
-0
3 additions, 0 deletions
README.md
database/crud.py
+28
-0
28 additions, 0 deletions
database/crud.py
main.py
+3
-0
3 additions, 0 deletions
main.py
routers/skyviews.py
+62
-4
62 additions, 4 deletions
routers/skyviews.py
with
96 additions
and
4 deletions
README.md
+
3
−
0
View file @
2b8f9208
...
@@ -10,6 +10,9 @@
...
@@ -10,6 +10,9 @@
*
http://localhost:8000/adex-fastapi/skyviews/
*
http://localhost:8000/adex-fastapi/skyviews/
*
http://localhost:8000/adex-fastapi/skyviews_rectangle/?ra_min=40&ra_max=50&dec_min=25&dec_max=35&limit=1000
*
http://localhost:8000/adex-fastapi/skyviews_rectangle/?ra_min=40&ra_max=50&dec_min=25&dec_max=35&limit=1000
*
http://localhost:8000/adex-fastapi/docs
*
http://localhost:8000/adex-fastapi/redoc
### sdc-dev (test environment)
### sdc-dev (test environment)
*
https://sdc-dev.astron.nl/adex-fastapi/skyviews/
*
https://sdc-dev.astron.nl/adex-fastapi/skyviews/
*
https://sdc-dev.astron.nl/adex-fastapi/skyviews_rectangle/?ra_min=40&ra_max=50&dec_min=25&dec_max=35&limit=1000
*
https://sdc-dev.astron.nl/adex-fastapi/skyviews_rectangle/?ra_min=40&ra_max=50&dec_min=25&dec_max=35&limit=1000
...
...
This diff is collapsed.
Click to expand it.
database/crud.py
+
28
−
0
View file @
2b8f9208
...
@@ -17,3 +17,31 @@ def get_skyviews_rectangle(db: Session, ra_min: float = 0.0, ra_max: float = 1.0
...
@@ -17,3 +17,31 @@ def get_skyviews_rectangle(db: Session, ra_min: float = 0.0, ra_max: float = 1.0
).
limit
(
limit
).
all
()
).
limit
(
limit
).
all
()
print
(
"
retrieved
"
+
str
(
len
(
list
))
+
'
dataproducts
'
)
print
(
"
retrieved
"
+
str
(
len
(
list
))
+
'
dataproducts
'
)
return
list
return
list
@timeit
def
get_skyviews_dataproducts
(
db
:
Session
,
ra_min
:
float
=
0.0
,
ra_max
:
float
=
1.0
,
dec_min
:
float
=
0.0
,
dec_max
:
float
=
1.0
,
limit
:
int
=
1000
,
collections
:
list
=
None
,
beams
:
list
=
None
,
levels
:
list
=
None
,
dp_types
:
list
=
None
,
dp_subtypes
:
list
=
None
):
# https://www.tutorialspoint.com/sqlalchemy/sqlalchemy_orm_using_query.htm
# https://docs.sqlalchemy.org/en/14/orm/query.html
list
=
db
.
query
(
SkyView
).
filter
(
SkyView
.
ra
>
ra_min
,
SkyView
.
ra
<
ra_max
,
SkyView
.
dec
>
dec_min
,
SkyView
.
dec
<
dec_max
,
SkyView
.
collection
.
in_
(
collections
),
#SkyView.beam.in_(beams),
SkyView
.
level
.
in_
(
levels
),
SkyView
.
dataproduct_type
.
in_
(
dp_types
),
SkyView
.
dataproduct_subtype
.
in_
(
dp_subtypes
),
).
limit
(
limit
).
all
()
print
(
"
retrieved
"
+
str
(
len
(
list
))
+
'
dataproducts
'
)
return
list
\ No newline at end of file
This diff is collapsed.
Click to expand it.
main.py
+
3
−
0
View file @
2b8f9208
...
@@ -10,6 +10,9 @@ app = FastAPI(
...
@@ -10,6 +10,9 @@ app = FastAPI(
title
=
"
ADEX backend
"
,
title
=
"
ADEX backend
"
,
description
=
"
ADEX backend FastAPI
"
,
description
=
"
ADEX backend FastAPI
"
,
version
=
"
0.0.1
"
,
version
=
"
0.0.1
"
,
docs_url
=
'
/adex-fastapi/docs
'
,
redoc_url
=
'
/adex-fastapi/redoc
'
,
openapi_url
=
'
/adex-fastapi/openapi.json
'
,
contact
=
{
contact
=
{
"
name
"
:
"
Nico Vermaas
"
,
"
name
"
:
"
Nico Vermaas
"
,
"
email
"
:
"
vermaas@astron.nl
"
,
"
email
"
:
"
vermaas@astron.nl
"
,
...
...
This diff is collapsed.
Click to expand it.
routers/skyviews.py
+
62
−
4
View file @
2b8f9208
from
typing
import
List
from
typing
import
List
,
Union
from
fastapi
import
APIRouter
,
Query
,
Depends
from
fastapi
import
APIRouter
,
Query
,
Depends
from
sqlalchemy.orm
import
Session
from
sqlalchemy.orm
import
Session
...
@@ -15,6 +15,13 @@ def get_db():
...
@@ -15,6 +15,13 @@ def get_db():
finally
:
finally
:
db
.
close
()
db
.
close
()
def
get_all_dp_types
():
return
[
'
image
'
,
'
cube
'
,
'
timeSeries
'
,
'
visibility
'
]
def
get_all_dp_subtypes
():
return
[
'
uncalibratedVisibility
'
,
'
lineCube
'
,
'
continuumCube
'
,
'
beamCube
'
,
'
continuumChunk
'
,
'
polarizationCube
'
,
'
pulsarTimingTimeSeries
'
,
'
compressedUncalibratedVisibility
'
,
'
splitttedUncalibratedVisibility
'
,
'
calibratedImage
'
,
'
calibratedVisibility
'
,
'
continuumMF
'
,
'
polarisationImage
'
]
# http://127.0.0.1:8000/skyviews/
# http://127.0.0.1:8000/skyviews/
# http://127.0.0.1:8000/skyviews/?skip=100&limit=100
# http://127.0.0.1:8000/skyviews/?skip=100&limit=100
...
@@ -25,9 +32,60 @@ async def get_skyviews(skip: int = 0, limit: int = 1000, db: Session = Depends(g
...
@@ -25,9 +32,60 @@ async def get_skyviews(skip: int = 0, limit: int = 1000, db: Session = Depends(g
# http://localhost:8000/adex-fastapi/skyviews_rectangle/?ra_min=40&ra_max=50&dec_min=25&dec_max=35&limit=1000
# http://localhost:8000/adex-fastapi/skyviews_rectangle/?ra_min=40&ra_max=50&dec_min=25&dec_max=35&limit=1000
@router.get
(
"
/skyviews_rectangle/
"
,
tags
=
[
"
skyviews
"
],
response_model
=
List
[
schemas
.
SkyView
])
@router.get
(
"
/skyviews_rectangle/
"
,
tags
=
[
"
skyviews
"
],
response_model
=
List
[
schemas
.
SkyView
])
async
def
get_skyviews_rectangle
(
ra_min
:
float
=
0.0
,
ra_max
:
float
=
1.0
,
async
def
get_skyviews_rectangle
(
db
:
Session
=
Depends
(
get_db
)
,
dec_min
:
float
=
0.0
,
dec_max
:
float
=
1.0
,
ra_min
:
float
=
0.0
,
ra_max
:
float
=
1.0
,
dec_min
:
float
=
0.0
,
dec_max
:
float
=
1.0
,
limit
:
int
=
1000
,
db
:
Session
=
Depends
(
get_db
)
):
limit
:
int
=
1000
):
items
=
crud
.
get_skyviews_rectangle
(
db
,
ra_min
=
ra_min
,
ra_max
=
ra_max
,
dec_min
=
dec_min
,
dec_max
=
dec_max
,
limit
=
limit
)
items
=
crud
.
get_skyviews_rectangle
(
db
,
ra_min
=
ra_min
,
ra_max
=
ra_max
,
dec_min
=
dec_min
,
dec_max
=
dec_max
,
limit
=
limit
)
return
items
return
items
# http://localhost:8000/adex-fastapi/skyviews_dataproducts/?ra_min=40&ra_max=50&dec_min=25&dec_max=35&limit=1000&dp_types=image,ube
@router.get
(
"
/skyviews_dataproducts/
"
,
tags
=
[
"
skyviews
"
],
response_model
=
List
[
schemas
.
SkyView
])
async
def
get_skyviews_dataproducts
(
db
:
Session
=
Depends
(
get_db
),
ra_min
:
float
=
0.0
,
ra_max
:
float
=
1.0
,
dec_min
:
float
=
0.0
,
dec_max
:
float
=
1.0
,
collections
:
str
=
None
,
beams
:
str
=
None
,
levels
:
str
=
None
,
dp_types
:
str
=
None
,
dp_subtypes
:
str
=
None
,
limit
:
int
=
1000
):
# TODO: get rid of these hardcoded values
# no values should result in something like 'all',
# but I don't know how to do that in SQLAlchemy query filters
try
:
collections_list
=
collections
.
split
(
'
,
'
)
except
:
collections_list
=
[
'
apertif-imaging
'
,
'
apertif-timeseries
'
]
try
:
beams_list
=
beams
.
split
(
'
,
'
)
except
:
beams_list
=
[
0
]
try
:
levels_list
=
levels
.
split
(
'
,
'
)
except
:
levels_list
=
[
0
,
1
,
2
]
try
:
dp_types_list
=
dp_types
.
split
(
'
,
'
)
except
:
# if no dp_types are given, assume 'image' (better than nothing)
dp_types_list
=
get_all_dp_types
()
try
:
dp_subtypes_list
=
dp_subtypes
.
split
(
'
,
'
)
except
:
# if no dp_types are given, assume 'image' (better than nothing)
dp_subtypes_list
=
get_all_dp_subtypes
()
items
=
crud
.
get_skyviews_dataproducts
(
db
,
ra_min
=
ra_min
,
ra_max
=
ra_max
,
dec_min
=
dec_min
,
dec_max
=
dec_max
,
collections
=
collections_list
,
beams
=
beams_list
,
levels
=
levels_list
,
dp_types
=
dp_types_list
,
dp_subtypes
=
dp_subtypes_list
,
limit
=
limit
)
return
items
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