Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-dfs
csst-dfs-api-cluster
Commits
6143d55f
Commit
6143d55f
authored
Feb 12, 2023
by
Wei Shoulin
Browse files
add filter
parent
5fef4e45
Changes
4
Hide whitespace changes
Inline
Side-by-side
csst_dfs_api_cluster/common/utils.py
View file @
6143d55f
import
os
from
datetime
import
datetime
import
time
import
grpc
from
csst_dfs_commons.models
import
Result
from
csst_dfs_proto.common.misc
import
misc_pb2
,
misc_pb2_grpc
from
.service
import
ServiceProxy
def
format_datetime
(
dt
):
return
dt
.
strftime
(
'%Y-%m-%d %H:%M:%S'
)
...
...
@@ -14,7 +19,6 @@ def format_time_ms(float_time):
data_secs
=
(
float_time
-
int
(
float_time
))
*
1000
return
"%s.%03d"
%
(
data_head
,
data_secs
)
def
get_parameter
(
kwargs
,
key
,
default
=
None
):
""" Get a specified named value for this (calling) function
...
...
@@ -40,7 +44,6 @@ def to_int(s, default_value = 0):
except
:
return
default_value
def
singleton
(
cls
):
_instance
=
{}
...
...
@@ -51,4 +54,15 @@ def singleton(cls):
return
inner
def
get_auth_headers
():
return
((
"csst_dfs_app"
,
os
.
getenv
(
"CSST_DFS_APP_ID"
)),(
"csst_dfs_token"
,
os
.
getenv
(
"CSST_DFS_APP_TOKEN"
)),)
\ No newline at end of file
return
((
"csst_dfs_app"
,
os
.
getenv
(
"CSST_DFS_APP_ID"
)),(
"csst_dfs_token"
,
os
.
getenv
(
"CSST_DFS_APP_TOKEN"
)),)
def
get_nextId_by_prefix
(
prefix
):
stub
=
misc_pb2_grpc
.
MiscSrvStub
(
ServiceProxy
().
channel
())
try
:
resp
,
_
=
stub
.
GetSeqId
.
with_call
(
misc_pb2
.
GetSeqIdReq
(
prefix
=
prefix
),
metadata
=
get_auth_headers
()
)
return
Result
.
ok_data
(
data
=
resp
.
nextId
)
except
grpc
.
RpcError
as
e
:
return
Result
.
error
(
message
=
"%s:%s"
%
(
e
.
code
().
value
,
e
.
details
()))
\ No newline at end of file
csst_dfs_api_cluster/cpic/level1.py
View file @
6143d55f
...
...
@@ -72,7 +72,7 @@ class Level1DataApi(object):
return
Result
.
error
(
message
=
f
"data not found"
)
return
Result
.
ok_data
(
data
=
Level1Record
().
from_proto_model
(
resp
.
record
))
except
grpc
.
RpcError
as
e
:
return
Result
.
error
(
message
=
"%s:%s"
%
(
e
.
code
().
value
,
e
.
details
()))
...
...
csst_dfs_api_cluster/facility/level0.py
View file @
6143d55f
...
...
@@ -20,9 +20,10 @@ class Level0DataApi(object):
obs_id: [str]
detector_no: [str]
obs_type: [str]
obs_time : (start, end),
qc0_status : [int],
prc_status : [int],
filter: [str]
obs_time : (start, end)
qc0_status : [int]
prc_status : [int]
file_name: [str]
limit: limits returns the number of records,default 0:no-limit
...
...
@@ -43,6 +44,7 @@ class Level0DataApi(object):
radius
=
get_parameter
(
kwargs
,
"radius"
,
0
),
object_name
=
get_parameter
(
kwargs
,
"object_name"
,
None
),
version
=
get_parameter
(
kwargs
,
"version"
,
None
),
filter
=
get_parameter
(
kwargs
,
"filter"
,
None
),
limit
=
get_parameter
(
kwargs
,
"limit"
,
0
),
other_conditions
=
{
"test"
:
"cnlab.test"
}
),
metadata
=
get_auth_headers
())
...
...
csst_dfs_api_cluster/mbi/level2.py
View file @
6143d55f
...
...
@@ -61,6 +61,7 @@ class Level2DataApi(object):
parameter kwargs:
obs_id: [str]
detector_no: [str]
filter: [str]
ra: [float] in deg
dec: [float] in deg
radius: [float] in deg
...
...
@@ -71,8 +72,9 @@ class Level2DataApi(object):
'''
try
:
resp
,
_
=
self
.
stub
.
FindCatalog
.
with_call
(
level2_pb2
.
FindLevel2CatalogReq
(
obs_id
=
get_parameter
(
kwargs
,
"obs_id"
),
detector_no
=
get_parameter
(
kwargs
,
"detector_no"
),
obs_id
=
get_parameter
(
kwargs
,
"obs_id"
,
None
),
detector_no
=
get_parameter
(
kwargs
,
"detector_no"
,
None
),
filter
=
get_parameter
(
kwargs
,
"filter"
,
None
),
obs_time_start
=
get_parameter
(
kwargs
,
"obs_time"
,
[
None
,
None
])[
0
],
obs_time_end
=
get_parameter
(
kwargs
,
"obs_time"
,
[
None
,
None
])[
1
],
ra
=
get_parameter
(
kwargs
,
"ra"
),
...
...
@@ -97,6 +99,7 @@ class Level2DataApi(object):
parameter kwargs:
obs_id: [str]
detector_no: [str]
filter: [str]
ra: [float] in deg
dec: [float] in deg
radius: [float] in deg
...
...
@@ -109,6 +112,7 @@ class Level2DataApi(object):
resp
,
_
=
self
.
stub
.
FindCatalogFile
.
with_call
(
level2_pb2
.
FindLevel2CatalogReq
(
obs_id
=
get_parameter
(
kwargs
,
"obs_id"
),
detector_no
=
get_parameter
(
kwargs
,
"detector_no"
),
filter
=
get_parameter
(
kwargs
,
"filter"
,
None
),
obs_time_start
=
get_parameter
(
kwargs
,
"obs_time"
,
[
None
,
None
])[
0
],
obs_time_end
=
get_parameter
(
kwargs
,
"obs_time"
,
[
None
,
None
])[
1
],
ra
=
get_parameter
(
kwargs
,
"ra"
),
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment