move get_abs_time to base.py
+ initialize Instrument().clients
This commit is contained in:
26
base.py
26
base.py
@ -1,6 +1,24 @@
|
|||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
import logging
|
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):
|
class Logger(object):
|
||||||
def __init__(self, logpath):
|
def __init__(self, logpath):
|
||||||
@ -17,7 +35,7 @@ class Logger(object):
|
|||||||
|
|
||||||
class Instrument:
|
class Instrument:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
self.clients = {}
|
||||||
|
|
||||||
def remove(self, client):
|
def remove(self, client):
|
||||||
try:
|
try:
|
||||||
@ -28,9 +46,3 @@ class Instrument:
|
|||||||
def register(self, client):
|
def register(self, client):
|
||||||
self.clients[client.id] = client
|
self.clients[client.id] = client
|
||||||
return 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]
|
|
||||||
|
Reference in New Issue
Block a user