1
0
mirror of https://github.com/skaringa/water-counter.git synced 2024-11-23 18:04:25 +01:00

Avoid error when no data is available

This commit is contained in:
Martin Kompf 2019-09-24 15:06:21 +02:00
parent dcd1ac89df
commit 05004cbac0

View File

@ -73,14 +73,15 @@ def detect_pauses(data):
def main():
#counter = read_fetch_output()
counter = read_rrd()
pauses = detect_pauses(counter)
if verbose:
for p in pauses:
print("Pause starting at {0:%Y-%m-%d %H:%M:%S}: {1:.1f} hours"
.format(datetime.fromtimestamp(p['start']), p['duration']/3600.0))
if len(pauses) == 0:
print("Possible leak detected! There is no break of at least {0} hours."
.format(min_pause/3600.0))
if len(counter) > 0:
pauses = detect_pauses(counter)
if verbose:
for p in pauses:
print("Pause starting at {0:%Y-%m-%d %H:%M:%S}: {1:.1f} hours"
.format(datetime.fromtimestamp(p['start']), p['duration']/3600.0))
if len(pauses) == 0:
print("Possible leak detected! There is no break of at least {0} hours."
.format(min_pause/3600.0))
if __name__ == '__main__':
main()