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:
|
||||
return
|
||||
converters = key_dict = table_properties = None # make IDE happy
|
||||
for i in range(5):
|
||||
while 1:
|
||||
header = {}
|
||||
if row[0]: # this is a header
|
||||
header[row[0]] = row
|
||||
@ -647,17 +647,23 @@ class InfluxDBWrapper:
|
||||
result[stream] = entry.tags.get('instrument', '0')
|
||||
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
|
||||
|
||||
:param stream: the uri of the stream
|
||||
:param value: instrument, "0" when unknown or None when switching to off
|
||||
: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)
|
||||
if row is not None:
|
||||
if prev in (None, '0') or ts < row[0]:
|
||||
prev, prevts = self.get_instrument(stream, ts, **tags)
|
||||
if prevts is not None:
|
||||
if prev in (None, '0'):
|
||||
ts = prevts + 0.001
|
||||
else:
|
||||
if value == '0' and guess:
|
||||
value = prev
|
||||
if ts < prevts:
|
||||
ts = prevts + 0.001
|
||||
tags['stream'] = stream
|
||||
if value:
|
||||
tags['instrument'] = value
|
||||
|
Reference in New Issue
Block a user