Files
seweb/base.py
Markus Zolliker 65aa822b96 major rework
using influxdb structure independed of nicos cache
2025-02-25 14:29:25 +01:00

51 lines
1.2 KiB
Python

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 (to now, rounded up to a full second) 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):
self.terminal = sys.stdout
self.log = open(logpath, "a")
def write(self, message):
self.terminal.write(message)
self.log.write(message)
def flush(self):
pass
class Instrument:
def __init__(self):
self.clients = {}
def remove(self, client):
try:
del self.clients[client.id]
except KeyError:
logging.warning('client already removed %s', client.id)
def register(self, client):
self.clients[client.id] = client
return client