From 423dff74b3e9f9364f38774f2c21f9f171445468 Mon Sep 17 00:00:00 2001 From: Charlie Date: Fri, 30 Aug 2024 11:16:29 +0100 Subject: [PATCH 1/2] fix: update date range specification --- vega_query/scripts/plots.py | 2 +- vega_query/utils.py | 2 +- vega_query/visualisations/plots/amm.py | 12 +++++------- vega_query/visualisations/plots/sla.py | 12 +++++------- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/vega_query/scripts/plots.py b/vega_query/scripts/plots.py index b917f0aff..58547076a 100644 --- a/vega_query/scripts/plots.py +++ b/vega_query/scripts/plots.py @@ -8,7 +8,7 @@ import vega_protos.protos as protos from vega_query.service.service import Service from vega_query.service.networks.constants import Network -from scripts.parser import PARSER +from vega_query.scripts.parser import PARSER if __name__ == "__main__": # Enrich parser with script specific options diff --git a/vega_query/utils.py b/vega_query/utils.py index f9768ef93..d5ac45c87 100644 --- a/vega_query/utils.py +++ b/vega_query/utils.py @@ -8,7 +8,7 @@ def timestamp_to_datetime(ts: int, nano: bool = True): if nano: ts = ts / 1e9 - return datetime.datetime.fromtimestamp(ts) + return datetime.datetime.fromtimestamp(ts, tz=datetime.timezone.utc) def datetime_to_timestamp(dt: datetime.datetime, nano: bool = True) -> int: diff --git a/vega_query/visualisations/plots/amm.py b/vega_query/visualisations/plots/amm.py index 2fdfffe31..bbb14f4bc 100644 --- a/vega_query/visualisations/plots/amm.py +++ b/vega_query/visualisations/plots/amm.py @@ -49,9 +49,9 @@ def create( # Default timestamps for getting data if required network_timestamp = service.api.data.get_vega_time() start_timestamp = ( - market.market_timestamps.proposed if start_timestamp is None else None + market.market_timestamps.proposed if start_timestamp is None else start_timestamp ) - end_timestamp = network_timestamp if end_timestamp is None else None + end_timestamp = network_timestamp if end_timestamp is None else end_timestamp # Get market specific information market_data_history = service.api.data.get_market_data_history_by_id( @@ -156,7 +156,7 @@ def create( if __name__ == "__main__": - from scripts.parser import PARSER + from vega_query.scripts.parser import PARSER args = PARSER.parse_args() @@ -188,14 +188,12 @@ def create( service, market_code=args.market, start_timestamp=( - timestamp_to_datetime(args.start_time, nano=True) + int(args.start_time.timestamp() * 1e9) if args.start_time is not None else None ), end_timestamp=( - timestamp_to_datetime(args.end_time, nano=True) - if args.end_time is not None - else None + int(args.end_time.timestamp() * 1e9) if args.end_time is not None else None ), ) plt.show() diff --git a/vega_query/visualisations/plots/sla.py b/vega_query/visualisations/plots/sla.py index 38f737fc8..634b478d3 100644 --- a/vega_query/visualisations/plots/sla.py +++ b/vega_query/visualisations/plots/sla.py @@ -52,9 +52,9 @@ def create( # Default timestamps for getting data if required network_timestamp = service.api.data.get_vega_time() start_timestamp = ( - market.market_timestamps.proposed if start_timestamp is None else None + market.market_timestamps.proposed if start_timestamp is None else start_timestamp ) - end_timestamp = network_timestamp if end_timestamp is None else None + end_timestamp = network_timestamp if end_timestamp is None else end_timestamp # Get market specific information market_data_history = service.api.data.get_market_data_history_by_id( @@ -155,7 +155,7 @@ def create( if __name__ == "__main__": - from scripts.parser import PARSER + from vega_query.scripts.parser import PARSER args = PARSER.parse_args() @@ -187,14 +187,12 @@ def create( service, market_code=args.market, start_timestamp=( - timestamp_to_datetime(args.start_time, nano=True) + int(args.start_time.timestamp() * 1e9) if args.start_time is not None else None ), end_timestamp=( - timestamp_to_datetime(args.end_time, nano=True) - if args.end_time is not None - else None + int(args.end_time.timestamp() * 1e9) if args.end_time is not None else None ), ) plt.show() From d79c415936e9ce778eeed435826c0e1602fa26b1 Mon Sep 17 00:00:00 2001 From: Charlie Date: Fri, 30 Aug 2024 11:37:00 +0100 Subject: [PATCH 2/2] chore: run black linter --- vega_query/visualisations/plots/amm.py | 4 +++- vega_query/visualisations/plots/sla.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/vega_query/visualisations/plots/amm.py b/vega_query/visualisations/plots/amm.py index bbb14f4bc..e02c89802 100644 --- a/vega_query/visualisations/plots/amm.py +++ b/vega_query/visualisations/plots/amm.py @@ -49,7 +49,9 @@ def create( # Default timestamps for getting data if required network_timestamp = service.api.data.get_vega_time() start_timestamp = ( - market.market_timestamps.proposed if start_timestamp is None else start_timestamp + market.market_timestamps.proposed + if start_timestamp is None + else start_timestamp ) end_timestamp = network_timestamp if end_timestamp is None else end_timestamp diff --git a/vega_query/visualisations/plots/sla.py b/vega_query/visualisations/plots/sla.py index 634b478d3..391894239 100644 --- a/vega_query/visualisations/plots/sla.py +++ b/vega_query/visualisations/plots/sla.py @@ -52,7 +52,9 @@ def create( # Default timestamps for getting data if required network_timestamp = service.api.data.get_vega_time() start_timestamp = ( - market.market_timestamps.proposed if start_timestamp is None else start_timestamp + market.market_timestamps.proposed + if start_timestamp is None + else start_timestamp ) end_timestamp = network_timestamp if end_timestamp is None else end_timestamp