From aee48599828d3b802e3695c062da017ba73ae221 Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Sun, 24 Apr 2016 15:15:16 +0200 Subject: [PATCH] influxdb: fix numpy scalar bool, uints, str * use types from the numpy hierarchy because e.g. np.issubtype(np.uint64, int) == False * streamline influxdb formatting * tested with influxdb 0.12 --- artiq/frontend/artiq_influxdb.py | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/artiq/frontend/artiq_influxdb.py b/artiq/frontend/artiq_influxdb.py index 143c09797..7028b7bf5 100755 --- a/artiq/frontend/artiq_influxdb.py +++ b/artiq/frontend/artiq_influxdb.py @@ -64,24 +64,16 @@ def get_argparser(): return parser -def influxdb_str(s): - return '"' + s.replace('"', '\\"') + '"' - - def format_influxdb(v): - if isinstance(v, bool): - if v: - return "bool", "t" - else: - return "bool", "f" - elif np.issubdtype(type(v), int): - return "int", "{}i".format(v) - elif np.issubdtype(type(v), float): - return "float", "{}".format(v) - elif isinstance(v, str): - return "str", influxdb_str(v) - else: - return "pyon", influxdb_str(pyon.encode(v)) + if np.issubdtype(type(v), np.bool_): + return "bool={}".format(v) + if np.issubdtype(type(v), np.integer): + return "int={}i".format(v) + if np.issubdtype(type(v), np.floating): + return "float={}".format(v) + if np.issubdtype(type(v), np.str_): + return "str=\"{}\"".format(v.replace('"', '\\"')) + return "pyon=\"{}\"".format(pyon.encode(v).replace('"', '\\"')) class DBWriter(TaskObject): @@ -107,9 +99,8 @@ class DBWriter(TaskObject): url = self.base_url + "/write" params = {"u": self.user, "p": self.password, "db": self.database, "precision": "ms"} - fmt_ty, fmt_v = format_influxdb(v) - data = "{},dataset={} {}={} {}".format( - self.table, k, fmt_ty, fmt_v, round(t*1e3)) + data = "{},dataset={} {} {}".format( + self.table, k, format_influxdb(v), round(t*1e3)) try: response = await aiohttp.request( "POST", url, params=params, data=data)