From 255d1ce5295b43d8b9837a9fdf89b0dd624cd4a0 Mon Sep 17 00:00:00 2001 From: Furkan Date: Wed, 16 Oct 2024 17:08:48 +0300 Subject: [PATCH] refactor: update timestamp handling in n1081b.py and handle_stats.py --- src/daq/jobs/caen/n1081b.py | 4 ++-- src/daq/jobs/handle_stats.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/daq/jobs/caen/n1081b.py b/src/daq/jobs/caen/n1081b.py index 343023f..340df53 100644 --- a/src/daq/jobs/caen/n1081b.py +++ b/src/daq/jobs/caen/n1081b.py @@ -1,6 +1,5 @@ import time from dataclasses import dataclass -from datetime import datetime from N1081B import N1081B from websocket import WebSocket @@ -8,6 +7,7 @@ from daq.base import DAQJob from daq.models import DAQJobMessage from daq.store.models import DAQJobMessageStore, StorableDAQJobConfig +from utils.time import get_now_unix_timestamp_ms N1081B_QUERY_INTERVAL_SECONDS = 1 N1081B_WEBSOCKET_TIMEOUT_SECONDS = 5 @@ -88,7 +88,7 @@ def _poll_sections(self): def _send_store_message(self, data: dict, section): keys = ["timestamp", *[f"lemo_{x['lemo']}" for x in data["counters"]]] values = [ - int(datetime.now().timestamp() * 1000), # unix timestamp in milliseconds + get_now_unix_timestamp_ms(), # unix timestamp in milliseconds *[x["value"] for x in data["counters"]], ] self.message_out.put( diff --git a/src/daq/jobs/handle_stats.py b/src/daq/jobs/handle_stats.py index d531399..fed41d5 100644 --- a/src/daq/jobs/handle_stats.py +++ b/src/daq/jobs/handle_stats.py @@ -6,6 +6,7 @@ from daq.base import DAQJob from daq.models import DAQJobMessage, DAQJobStats, DAQJobStatsRecord from daq.store.models import DAQJobMessageStore, StorableDAQJobConfig +from utils.time import get_unix_timestamp_ms DAQJobStatsDict = Dict[type[DAQJob], DAQJobStats] @@ -47,7 +48,7 @@ def handle_message(self, message: DAQJobMessageStats) -> bool: def datetime_to_str(dt: Optional[datetime]): if dt is None: return "N/A" - return int(dt.timestamp() * 1000) + return get_unix_timestamp_ms(dt) def unpack_record(record: DAQJobStatsRecord): return [