From 1e505ec33aaba0122bdde55676c42baf26d1b3e8 Mon Sep 17 00:00:00 2001 From: pcain-usgs <pcain@usgs.gov> Date: Wed, 10 Mar 2021 12:30:59 -0700 Subject: [PATCH 1/2] Get factory from interval --- geomagio/api/ws/DataApiQuery.py | 7 ------- geomagio/api/ws/data.py | 12 +++++++----- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/geomagio/api/ws/DataApiQuery.py b/geomagio/api/ws/DataApiQuery.py index 8202c6b6e..af1c3f73f 100644 --- a/geomagio/api/ws/DataApiQuery.py +++ b/geomagio/api/ws/DataApiQuery.py @@ -39,13 +39,6 @@ class SamplingPeriod(float, enum.Enum): HOUR = 3600.0 DAY = 86400.0 - @property - def input_factory(self): - if self in [SamplingPeriod.TEN_HERTZ, SamplingPeriod.HOUR, SamplingPeriod.DAY]: - return "miniseed" - else: - return "edge" - class DataApiQuery(BaseModel): id: str diff --git a/geomagio/api/ws/data.py b/geomagio/api/ws/data.py index 797e382cd..374ca754b 100644 --- a/geomagio/api/ws/data.py +++ b/geomagio/api/ws/data.py @@ -29,13 +29,15 @@ def get_data_factory( Edge or miniseed factory object """ host = os.getenv("DATA_HOST", "cwbpub.cr.usgs.gov") - factory = query.sampling_period.input_factory - if factory == "edge": - return EdgeFactory(host=host, port=os.getenv("DATA_EARTHWORM_PORT", "2060")) - elif factory == "miniseed": + sampling_period = query.sampling_period + if sampling_period in [ + SamplingPeriod.TEN_HERTZ, + SamplingPeriod.HOUR, + SamplingPeriod.DAY, + ]: return MiniSeedFactory(host=host, port=os.getenv("DATA_MINISEED_PORT", "2061")) else: - return None + return EdgeFactory(host=host, port=os.getenv("DATA_EARTHWORM_PORT", "2060")) def get_data_query( -- GitLab From d014a1380fda26f203a0d7261abe90edfc6a8860 Mon Sep 17 00:00:00 2001 From: pcain-usgs <pcain@usgs.gov> Date: Wed, 10 Mar 2021 12:34:27 -0700 Subject: [PATCH 2/2] Return none for invalid sampling period --- geomagio/api/ws/data.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/geomagio/api/ws/data.py b/geomagio/api/ws/data.py index 374ca754b..2592daa49 100644 --- a/geomagio/api/ws/data.py +++ b/geomagio/api/ws/data.py @@ -36,8 +36,10 @@ def get_data_factory( SamplingPeriod.DAY, ]: return MiniSeedFactory(host=host, port=os.getenv("DATA_MINISEED_PORT", "2061")) - else: + elif sampling_period in [SamplingPeriod.SECOND, SamplingPeriod.MINUTE]: return EdgeFactory(host=host, port=os.getenv("DATA_EARTHWORM_PORT", "2060")) + else: + return None def get_data_query( -- GitLab