collapse repetitive changes of less than 10 minutes

This commit is contained in:
Tomáš Mládek 2021-02-13 18:42:56 +01:00 committed by Tomáš Mládek
parent 39304d2392
commit ce98e5d6e5

View file

@ -180,6 +180,22 @@ def run_forever(address: str, period: int, ssid: str, output: str):
if lease.mac not in (l.mac for l in leases):
log.append(log_entry(ts, False, lease))
last_seen = leases
collapse_thresh = timedelta(minutes=10)
while True:
duplicate_index = None
for idx in range(len(log)):
if idx + 1 == len(log):
continue
if log[idx].lease.mac == log[idx + 1].lease.mac and \
not log[idx].state and log[idx + 1].state and \
log[idx + 1].ts - log[idx].ts < collapse_thresh:
duplicate_index = idx
if duplicate_index is None:
break
log.pop(duplicate_index) # IN
log.pop(duplicate_index) # OUT
log.reverse()
leaderboard_tmp = {}