Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
geomag-algorithms
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ghsc
National Geomagnetism Program
geomag-algorithms
Commits
32938369
Commit
32938369
authored
4 years ago
by
Jeremy M Fee
Browse files
Options
Downloads
Patches
Plain Diff
Update observatory and data_type validation
parent
e7cc5dd6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!146
Release CMO metadata to production
,
!21
Update observatory and data_type validation
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
geomagio/api/ws/DataApiQuery.py
+10
-29
10 additions, 29 deletions
geomagio/api/ws/DataApiQuery.py
with
10 additions
and
29 deletions
geomagio/api/ws/DataApiQuery.py
+
10
−
29
View file @
32938369
...
...
@@ -7,36 +7,13 @@ from pydantic import BaseModel, root_validator, validator
from
...
import
pydantic_utcdatetime
from
.Element
import
ELEMENTS
,
ELEMENT_INDEX
from
.Observatory
import
OBSERVATORY_INDEX
DEFAULT_ELEMENTS
=
[
"
X
"
,
"
Y
"
,
"
Z
"
,
"
F
"
]
REQUEST_LIMIT
=
345600
VALID_ELEMENTS
=
[
e
.
id
for
e
in
ELEMENTS
]
VALID_OBSERVATORIES
=
[
"
BDT
"
,
"
BOU
"
,
"
BRT
"
,
"
BRW
"
,
"
BSL
"
,
"
CMO
"
,
"
CMT
"
,
"
DED
"
,
"
DHT
"
,
"
FDT
"
,
"
FRD
"
,
"
FRN
"
,
"
GUA
"
,
"
HON
"
,
"
NEW
"
,
"
SHU
"
,
"
SIT
"
,
"
SJG
"
,
"
SJT
"
,
"
TST
"
,
"
TUC
"
,
"
USGS
"
,
]
class
DataType
(
str
,
enum
.
Enum
):
VARIATION
=
"
variation
"
...
...
@@ -44,6 +21,10 @@ class DataType(str, enum.Enum):
QUASI_DEFINITIVE
=
"
quasi-definitive
"
DEFINITIVE
=
"
definitive
"
@classmethod
def
values
(
cls
)
->
List
[
str
]:
return
[
t
.
value
for
t
in
cls
]
class
OutputFormat
(
str
,
enum
.
Enum
):
IAGA2002
=
"
iaga2002
"
...
...
@@ -71,10 +52,10 @@ class DataApiQuery(BaseModel):
def
validate_data_type
(
cls
,
data_type
:
Union
[
DataType
,
str
]
)
->
Union
[
DataType
,
str
]:
if
data_type
not
in
DataType
and
len
(
data_type
)
!=
2
:
if
data_type
not
in
DataType
.
values
()
and
len
(
data_type
)
!=
2
:
raise
ValueError
(
f
"
Bad data type value
'
{
data_type
}
'
.
"
f
"
Valid values are:
{
'
,
'
.
join
(
list
(
DataType
))
}
"
f
"
Valid values are:
{
'
,
'
.
join
(
DataType
.
values
(
))
}
"
)
return
data_type
...
...
@@ -94,10 +75,10 @@ class DataApiQuery(BaseModel):
@validator
(
"
id
"
)
def
validate_id
(
cls
,
id
:
str
)
->
str
:
if
id
not
in
VALID_
OBSERVATOR
IES
:
if
id
not
in
OBSERVATOR
Y_INDEX
:
raise
ValueError
(
f
"
Bad observatory id
'
{
id
}
'
.
"
f
"
Valid values are:
{
'
,
'
.
join
(
VALID_
OBSERVATOR
IES
)
}
.
"
f
"
Valid values are:
{
'
,
'
.
join
(
sorted
(
OBSERVATOR
Y_INDEX
.
keys
())
)
}
.
"
)
return
id
...
...
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