Skip to content

Commit

Permalink
refactor: update timestamp handling in n1081b.py and handle_stats.py
Browse files Browse the repository at this point in the history
  • Loading branch information
furkan-bilgin committed Oct 16, 2024
1 parent 99bcd3d commit 255d1ce
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/daq/jobs/caen/n1081b.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import time
from dataclasses import dataclass
from datetime import datetime

from N1081B import N1081B
from websocket import WebSocket

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
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/daq/jobs/handle_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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 [
Expand Down

0 comments on commit 255d1ce

Please sign in to comment.