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
712f5c99
Commit
712f5c99
authored
3 years ago
by
Cain, Payton David
Browse files
Options
Downloads
Patches
Plain Diff
move _get_element outside of classes, chain commands
parent
48686488
No related branches found
No related tags found
2 merge requests
!146
Release CMO metadata to production
,
!96
SNCL/SNCLFactory
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
geomagio/edge/LegacySNCL.py
+39
-41
39 additions, 41 deletions
geomagio/edge/LegacySNCL.py
geomagio/edge/SNCL.py
+45
-47
45 additions, 47 deletions
geomagio/edge/SNCL.py
with
84 additions
and
88 deletions
geomagio/edge/LegacySNCL.py
+
39
−
41
View file @
712f5c99
from
typing
import
Optional
from
.SNCL
import
SNCL
,
_
_get_location_start
from
.SNCL
import
SNCL
,
_get_location_start
ELEMENT_CONVERSIONS
=
{
# e-field
...
...
@@ -36,9 +36,9 @@ class LegacySNCL(SNCL):
@property
def
element
(
self
)
->
str
:
predefined_element
=
self
.
__check_predefined
_element
(
)
element
=
self
.
__get_element
()
return
predefined_element
or
element
return
_check_
predefined_element
(
channel
=
self
.
channel
)
or
_get
_element
(
channel
=
self
.
channel
,
location
=
self
.
location
)
@property
def
interval
(
self
)
->
str
:
...
...
@@ -53,46 +53,25 @@ class LegacySNCL(SNCL):
return
"
day
"
raise
ValueError
(
f
"
Unexcepted interval code:
{
channel_start
}
"
)
def
__get_element
(
self
):
"""
Translates channel/location to element
"""
element_start
=
self
.
channel
[
2
]
channel
=
self
.
channel
channel_middle
=
channel
[
1
]
location_end
=
self
.
location
[
1
]
if
channel_middle
in
[
"
Q
"
,
"
E
"
]:
element_end
=
"
_Volt
"
elif
channel_middle
==
"
Y
"
:
element_end
=
"
_Bin
"
elif
channel_middle
==
"
K
"
:
element_end
=
"
_Temp
"
elif
location_end
==
"
1
"
:
element_end
=
"
_Sat
"
else
:
element_end
=
""
return
element_start
+
element_end
def
__check_predefined_element
(
self
)
->
Optional
[
str
]:
channel
=
self
.
channel
channel_end
=
channel
[
1
:]
if
channel_end
in
CHANNEL_CONVERSIONS
:
return
CHANNEL_CONVERSIONS
[
channel_end
]
return
None
def
get_channel
(
element
:
str
,
interval
:
str
)
->
str
:
predefined_channel
=
__check_predefined_channel
(
element
=
element
,
interval
=
interval
)
channel_start
=
__get_channel_start
(
interval
=
interval
)
channel_end
=
__get_channel_end
(
element
=
element
)
return
predefined_channel
or
(
channel_start
+
channel_end
)
return
_check_predefined_channel
(
element
=
element
,
interval
=
interval
)
or
(
_get_channel_start
(
interval
=
interval
)
+
_get_channel_end
(
element
=
element
)
)
def
get_location
(
element
:
str
,
data_type
:
str
)
->
str
:
location_start
=
__get_location_start
(
data_type
=
data_type
)
location_end
=
__get_location_end
(
element
=
element
)
return
location_start
+
location_end
return
_get_location_start
(
data_type
=
data_type
)
+
_get_location_end
(
element
=
element
)
def
_check_predefined_element
(
channel
:
str
)
->
Optional
[
str
]:
channel_end
=
channel
[
1
:]
if
channel_end
in
CHANNEL_CONVERSIONS
:
return
CHANNEL_CONVERSIONS
[
channel_end
]
return
None
def
__get_channel_start
(
interval
:
str
)
->
str
:
def
_get_channel_start
(
interval
:
str
)
->
str
:
if
interval
==
"
second
"
:
return
"
S
"
elif
interval
==
"
minute
"
:
...
...
@@ -104,9 +83,28 @@ def __get_channel_start(interval: str) -> str:
raise
ValueError
(
f
"
Unexcepted interval:
{
interval
}
"
)
def
__check_predefined_channel
(
element
:
str
,
interval
:
str
)
->
Optional
[
str
]:
def
_get_element
(
channel
:
str
,
location
:
str
)
->
str
:
"""
Translates channel/location to element
"""
element_start
=
channel
[
2
]
channel
=
channel
channel_middle
=
channel
[
1
]
location_end
=
location
[
1
]
if
channel_middle
in
[
"
Q
"
,
"
E
"
]:
element_end
=
"
_Volt
"
elif
channel_middle
==
"
Y
"
:
element_end
=
"
_Bin
"
elif
channel_middle
==
"
K
"
:
element_end
=
"
_Temp
"
elif
location_end
==
"
1
"
:
element_end
=
"
_Sat
"
else
:
element_end
=
""
return
element_start
+
element_end
def
_check_predefined_channel
(
element
:
str
,
interval
:
str
)
->
Optional
[
str
]:
if
element
in
ELEMENT_CONVERSIONS
:
return
_
_get_channel_start
(
interval
=
interval
)
+
ELEMENT_CONVERSIONS
[
element
]
return
_get_channel_start
(
interval
=
interval
)
+
ELEMENT_CONVERSIONS
[
element
]
elif
len
(
element
)
==
3
:
return
element
# chan.loc format
...
...
@@ -117,7 +115,7 @@ def __check_predefined_channel(element: str, interval: str) -> Optional[str]:
return
None
def
_
_get_channel_end
(
element
:
str
)
->
str
:
def
_get_channel_end
(
element
:
str
)
->
str
:
channel_middle
=
"
V
"
if
"
_Volt
"
in
element
:
channel_middle
=
"
E
"
...
...
@@ -131,7 +129,7 @@ def __get_channel_end(element: str) -> str:
return
channel_middle
+
channel_end
def
_
_get_location_end
(
element
:
str
)
->
str
:
def
_get_location_end
(
element
:
str
)
->
str
:
"""
Translates element suffix to end of location code
"""
if
"
_Sat
"
in
element
:
return
"
1
"
...
...
This diff is collapsed.
Click to expand it.
geomagio/edge/SNCL.py
+
45
−
47
View file @
712f5c99
...
...
@@ -63,9 +63,9 @@ class SNCL(BaseModel):
@property
def
element
(
self
)
->
str
:
predefined_element
=
self
.
__check_predefined
_element
(
)
element
=
self
.
__get_element
()
return
predefined_element
or
element
return
_check_
predefined_element
(
channel
=
self
.
channel
)
or
_get
_element
(
channel
=
self
.
channel
,
location
=
self
.
location
)
@property
def
interval
(
self
)
->
str
:
...
...
@@ -83,52 +83,25 @@ class SNCL(BaseModel):
return
"
day
"
raise
ValueError
(
f
"
Unexcepted interval code:
{
channel_start
}
"
)
def
__get_element
(
self
):
"""
Translates channel/location to element
"""
element_start
=
self
.
channel
[
2
]
channel
=
self
.
channel
channel_middle
=
channel
[
1
]
location_end
=
self
.
location
[
1
]
if
channel_middle
==
"
E
"
:
element_end
=
"
_Volt
"
elif
channel_middle
==
"
Y
"
:
element_end
=
"
_Bin
"
elif
channel_middle
==
"
K
"
:
element_end
=
"
_Temp
"
elif
location_end
==
"
1
"
:
element_end
=
"
_Sat
"
elif
location_end
==
"
D
"
:
element_end
=
"
_Dist
"
elif
location_end
==
"
Q
"
:
element_end
=
"
_SQ
"
elif
location_end
==
"
V
"
:
element_end
=
"
_SV
"
else
:
element_end
=
""
return
element_start
+
element_end
def
__check_predefined_element
(
self
)
->
Optional
[
str
]:
channel
=
self
.
channel
channel_end
=
channel
[
1
:]
if
channel_end
in
CHANNEL_CONVERSIONS
:
return
CHANNEL_CONVERSIONS
[
channel_end
]
return
None
def
get_channel
(
element
:
str
,
interval
:
str
)
->
str
:
predefined_channel
=
__check_predefined_channel
(
element
=
element
,
interval
=
interval
)
channel_start
=
__get_channel_start
(
interval
=
interval
)
channel_end
=
__get_channel_end
(
element
=
element
)
return
predefined_channel
or
(
channel_start
+
channel_end
)
return
_check_predefined_channel
(
element
=
element
,
interval
=
interval
)
or
(
_get_channel_start
(
interval
=
interval
)
+
_get_channel_end
(
element
=
element
)
)
def
get_location
(
element
:
str
,
data_type
:
str
)
->
str
:
location_start
=
__get_location_start
(
data_type
=
data_type
)
location_end
=
__get_location_end
(
element
=
element
)
return
location_start
+
location_end
return
_get_location_start
(
data_type
=
data_type
)
+
_get_location_end
(
element
=
element
)
def
_check_predefined_element
(
channel
:
str
)
->
Optional
[
str
]:
channel_end
=
channel
[
1
:]
if
channel_end
in
CHANNEL_CONVERSIONS
:
return
CHANNEL_CONVERSIONS
[
channel_end
]
return
None
def
__get_channel_start
(
interval
:
str
)
->
str
:
def
_get_channel_start
(
interval
:
str
)
->
str
:
if
interval
==
"
tenhertz
"
:
return
"
B
"
if
interval
==
"
second
"
:
...
...
@@ -142,9 +115,34 @@ def __get_channel_start(interval: str) -> str:
raise
ValueError
(
f
"
Unexcepted interval:
{
interval
}
"
)
def
__check_predefined_channel
(
element
:
str
,
interval
:
str
)
->
Optional
[
str
]:
def
_get_element
(
channel
:
str
,
location
:
str
)
->
str
:
"""
Translates channel/location to element
"""
element_start
=
channel
[
2
]
channel
=
channel
channel_middle
=
channel
[
1
]
location_end
=
location
[
1
]
if
channel_middle
==
"
E
"
:
element_end
=
"
_Volt
"
elif
channel_middle
==
"
Y
"
:
element_end
=
"
_Bin
"
elif
channel_middle
==
"
K
"
:
element_end
=
"
_Temp
"
elif
location_end
==
"
1
"
:
element_end
=
"
_Sat
"
elif
location_end
==
"
D
"
:
element_end
=
"
_Dist
"
elif
location_end
==
"
Q
"
:
element_end
=
"
_SQ
"
elif
location_end
==
"
V
"
:
element_end
=
"
_SV
"
else
:
element_end
=
""
return
element_start
+
element_end
def
_check_predefined_channel
(
element
:
str
,
interval
:
str
)
->
Optional
[
str
]:
if
element
in
ELEMENT_CONVERSIONS
:
return
_
_get_channel_start
(
interval
=
interval
)
+
ELEMENT_CONVERSIONS
[
element
]
return
_get_channel_start
(
interval
=
interval
)
+
ELEMENT_CONVERSIONS
[
element
]
elif
len
(
element
)
==
3
:
return
element
# chan.loc format
...
...
@@ -155,7 +153,7 @@ def __check_predefined_channel(element: str, interval: str) -> Optional[str]:
return
None
def
_
_get_channel_end
(
element
:
str
)
->
str
:
def
_get_channel_end
(
element
:
str
)
->
str
:
channel_middle
=
"
F
"
if
"
_Volt
"
in
element
:
channel_middle
=
"
E
"
...
...
@@ -167,7 +165,7 @@ def __get_channel_end(element: str) -> str:
return
channel_middle
+
channel_end
def
_
_get_location_start
(
data_type
:
str
)
->
str
:
def
_get_location_start
(
data_type
:
str
)
->
str
:
"""
Translates data type to beginning of location code
"""
if
data_type
==
"
variation
"
:
return
"
R
"
...
...
@@ -180,7 +178,7 @@ def __get_location_start(data_type: str) -> str:
raise
ValueError
(
f
"
Unexpected data type:
{
data_type
}
"
)
def
_
_get_location_end
(
element
:
str
)
->
str
:
def
_get_location_end
(
element
:
str
)
->
str
:
"""
Translates element suffix to end of location code
"""
if
"
_Sat
"
in
element
:
return
"
1
"
...
...
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