method 'complete': move end_time_dict to an argument
get_streams should return all tags
This commit is contained in:
13
influx.py
13
influx.py
@ -559,16 +559,15 @@ class InfluxDBWrapper:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def complete(curve_dict, end_time=0, tag='stream'):
|
def complete(curve_dict, end_time=0, tag=None):
|
||||||
"""complete to end_time
|
"""complete to end_time
|
||||||
|
|
||||||
if end_time is not given, is is the max timestamp within the same stream
|
if tag is given, end_time is a dict <tag value> of <end time>
|
||||||
"""
|
"""
|
||||||
|
if tag is None:
|
||||||
end_time_dict = {}
|
end_time_dict = {}
|
||||||
if not end_time:
|
else:
|
||||||
for curve in curve_dict.values():
|
end_time_dict, end_time = end_time, 0
|
||||||
key = curve.tags.get(tag)
|
|
||||||
end_time_dict[key] = max(end_time_dict.get(key, 0), curve[-1][0])
|
|
||||||
for curve in curve_dict.values():
|
for curve in curve_dict.values():
|
||||||
if len(curve):
|
if len(curve):
|
||||||
tlast, value = curve[-1]
|
tlast, value = curve[-1]
|
||||||
@ -651,7 +650,7 @@ class InfluxDBWrapper:
|
|||||||
for stream, entries in all_entries.items():
|
for stream, entries in all_entries.items():
|
||||||
entry = sorted(entries, key=lambda r: r[0])[-1]
|
entry = sorted(entries, key=lambda r: r[0])[-1]
|
||||||
if entry[1]: # on=True
|
if entry[1]: # on=True
|
||||||
result[stream] = entry.tags.get('instrument', '0')
|
result[stream] = entry.tags
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def set_instrument(self, stream, value, ts=None, guess=True, **tags):
|
def set_instrument(self, stream, value, ts=None, guess=True, **tags):
|
||||||
|
@ -278,8 +278,9 @@ class EventStream:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('can not connect to', uri, repr(e))
|
print('can not connect to', uri, repr(e))
|
||||||
continue
|
continue
|
||||||
|
device = stream.tags.get('device')
|
||||||
events.append(('stream', kwargs.get('instrument', '0'),
|
events.append(('stream', kwargs.get('instrument', '0'),
|
||||||
{}, uri, int(time.time())))
|
{'device': device}, uri, int(time.time())))
|
||||||
for name, stream in self.streams.items():
|
for name, stream in self.streams.items():
|
||||||
try:
|
try:
|
||||||
if stream.get_events(events, maxevents):
|
if stream.get_events(events, maxevents):
|
||||||
|
Reference in New Issue
Block a user