2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-26 03:38:25 +08:00

influxdb: use types

This commit is contained in:
Sebastien Bourdeauducq 2015-08-18 13:34:42 +08:00
parent 2275017651
commit 2ac8c53bbe

View File

@ -7,6 +7,7 @@ import atexit
import fnmatch import fnmatch
from functools import partial from functools import partial
import numpy as np
import aiohttp import aiohttp
from artiq.tools import verbosity_args, init_logger from artiq.tools import verbosity_args, init_logger
@ -100,19 +101,31 @@ class DBWriter(TaskObject):
response.close() response.close()
def format_influxdb(v):
if isinstance(v, bool):
if v:
return "t"
else:
return "f"
elif np.issubdtype(type(v), int):
return "{}i".format(v)
elif np.issubdtype(type(v), float):
return "{}".format(v)
elif isinstance(v, str):
return '"' + v.replace('"', '\\"') + '"'
else:
return None
class Parameters: class Parameters:
def __init__(self, filter_function, writer, init): def __init__(self, filter_function, writer, init):
self.filter_function = filter_function self.filter_function = filter_function
self.writer = writer self.writer = writer
def __setitem__(self, k, v): def __setitem__(self, k, v):
try: v_db = format_influxdb(v)
v = float(v) if v_db is not None and self.filter_function(k):
except: self.writer.update(k, v_db)
pass
else:
if self.filter_function(k):
self.writer.update(k, v)
class MasterReader(TaskObject): class MasterReader(TaskObject):