From d3429cf84eb4b571b04aec65e8d32240575dcbb6 Mon Sep 17 00:00:00 2001 From: Benjamin Webb <40066515+webb-ben@users.noreply.github.com> Date: Mon, 24 Oct 2022 09:42:01 +0200 Subject: [PATCH] Add 59 minute grace period (#20) * Add 59 minute grace period Set a 'day' period to be 24 hours 59 minutes 59 seconds * Remove trailing commas Co-Authored-By: Tom Kralidis Co-authored-by: Tom Kralidis --- wis2box_api/plugins/process/station_info.py | 28 ++++++++++----------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/wis2box_api/plugins/process/station_info.py b/wis2box_api/plugins/process/station_info.py index 72a7821..4270934 100644 --- a/wis2box_api/plugins/process/station_info.py +++ b/wis2box_api/plugins/process/station_info.py @@ -50,34 +50,34 @@ 'keywords': {'en': ['collection', 'topic', 'dataset']}, 'schema': { 'type': 'string', - 'default': None, + 'default': None }, 'minOccurs': 1, 'maxOccurs': 1, - 'metadata': None, # TODO how to use? + 'metadata': None # TODO how to use? }, 'wigos_station_identifier': { 'title': {'en': 'WIGOS Station Identifier'}, 'schema': { 'type': 'array', 'minItems': 1, - 'items': {'type': 'string'}, + 'items': {'type': 'string'} }, 'minOccurs': 0, 'maxOccurs': 1, - 'metadata': None, # TODO how to use? + 'metadata': None # TODO how to use? }, 'days': { 'title': {'en': 'Days'}, 'schema': {'type': 'number', 'default': 1}, 'minOccurs': 0, - 'maxOccurs': 1, + 'maxOccurs': 1 }, 'years': { 'title': {'en': 'Years'}, 'schema': {'type': 'number', 'default': 0}, 'minOccurs': 0, - 'maxOccurs': 1, + 'maxOccurs': 1 }, }, 'outputs': { @@ -89,15 +89,15 @@ }, 'schema': { 'type': 'object', - 'contentMediaType': 'application/json', - }, + 'contentMediaType': 'application/json' + } } }, 'example': { 'inputs': { - 'collection': 'mwi.mwi_met_centre.data.core.weather.surface-based-observations.SYNOP', # noqa + 'collection': 'mwi.mwi_met_centre.data.core.weather.surface-based-observations.SYNOP' # noqa } - }, + } } @@ -148,7 +148,8 @@ def execute(self, data): raise ProcessorExecuteError(msg) days = data.get('days', 1) + (data.get('years', 0) * 365) - date_offset = (datetime.utcnow() - timedelta(days=days)).isoformat() + _time_delta = timedelta(days=days, minutes=59, seconds=59) + date_offset = (datetime.utcnow() - _time_delta).isoformat() if CONFIG['resources'].get('stations') is None: msg = 'stations collection does not exist' @@ -182,10 +183,7 @@ def execute(self, data): }, 'aggs': { 'count': { - 'terms': { - 'field': 'reportId.raw', - 'size': 64000 - } + 'terms': {'field': 'reportId.raw', 'size': 64000} } } }