move get_abs_time to base.py

+ initialize Instrument().clients
This commit is contained in:
2024-10-23 16:34:55 +02:00
parent 7736e0f7e3
commit dc887e68d5

26
base.py
View File

@ -1,6 +1,24 @@
import sys
import time
import logging
ONEYEAR = 366 * 24 * 3600
def get_abs_time(times):
"""
Gets the absolute times for the given potential relative times. If a given timestamp is less than
one year, then the value is relative and converted into an absolute timestamp
Parameters :
times([(float)]) : an array of unix timestamps or relative duration (< 1 year) as floats
Returns :
[(float)] : an array of absolute unix timestamps as floats
"""
now = int(time.time() + 0.999)
return [t + now if t < ONEYEAR else t for t in times]
class Logger(object):
def __init__(self, logpath):
@ -17,7 +35,7 @@ class Logger(object):
class Instrument:
def __init__(self):
pass
self.clients = {}
def remove(self, client):
try:
@ -28,9 +46,3 @@ class Instrument:
def register(self, client):
self.clients[client.id] = client
return client
def get_abs_time(times):
now = int(time.time() + 0.999)
oneyear = 365 * 24 * 3600
return [t + now if t < oneyear else t for t in times]