fix bug and add guess for instrument
This commit is contained in:
16
influx.py
16
influx.py
@ -403,7 +403,7 @@ class InfluxDBWrapper:
|
|||||||
except StopIteration:
|
except StopIteration:
|
||||||
return
|
return
|
||||||
converters = key_dict = table_properties = None # make IDE happy
|
converters = key_dict = table_properties = None # make IDE happy
|
||||||
for i in range(5):
|
while 1:
|
||||||
header = {}
|
header = {}
|
||||||
if row[0]: # this is a header
|
if row[0]: # this is a header
|
||||||
header[row[0]] = row
|
header[row[0]] = row
|
||||||
@ -647,17 +647,23 @@ class InfluxDBWrapper:
|
|||||||
result[stream] = entry.tags.get('instrument', '0')
|
result[stream] = entry.tags.get('instrument', '0')
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def set_instrument(self, stream, value, ts=None, **tags):
|
def set_instrument(self, stream, value, ts=None, guess=True, **tags):
|
||||||
"""set stream and instrument on or off
|
"""set stream and instrument on or off
|
||||||
|
|
||||||
:param stream: the uri of the stream
|
:param stream: the uri of the stream
|
||||||
:param value: instrument, "0" when unknown or None when switching to off
|
:param value: instrument, "0" when unknown or None when switching to off
|
||||||
:param ts: the time or None when now
|
:param ts: the time or None when now
|
||||||
|
:param guess: when instrument is undefined, take from previous
|
||||||
"""
|
"""
|
||||||
prev, row = self.get_instrument(stream, ts, **tags)
|
prev, prevts = self.get_instrument(stream, ts, **tags)
|
||||||
if row is not None:
|
if prevts is not None:
|
||||||
if prev in (None, '0') or ts < row[0]:
|
if prev in (None, '0'):
|
||||||
ts = prevts + 0.001
|
ts = prevts + 0.001
|
||||||
|
else:
|
||||||
|
if value == '0' and guess:
|
||||||
|
value = prev
|
||||||
|
if ts < prevts:
|
||||||
|
ts = prevts + 0.001
|
||||||
tags['stream'] = stream
|
tags['stream'] = stream
|
||||||
if value:
|
if value:
|
||||||
tags['instrument'] = value
|
tags['instrument'] = value
|
||||||
|
Reference in New Issue
Block a user