tor_multipath_voip/scripts/links_parse.py
2019-09-16 19:20:38 +02:00

36 lines
858 B
Python
Executable file

#!/usr/bin/python3
import sys,re
acc = []
previous=None
for line in sys.stdin:
res = re.match(r"\[(\d+)\] Blacklisted links: ([_U]+)", line)
if not res: continue
ts,l = res.groups()
ts = int(ts)
l2 = [(i, 'up' if l[i] == "U" else 'down') for i in range(len(l))]
acc.append((ts,l2))
l2 = None
if len(acc) <= 0: sys.exit(0)
ts_first, l_first = acc[0]
ts_last, l_last = acc[len(acc) - 1]
xp_time = ts_last - ts_first
durations = [0 for i,v in l_first]
for j in range(len(acc)):
ts, l = acc[j]
ts_next, l_next = acc[j]
if j+1 < len(acc): ts_next, l_next = acc[j+1]
delta = ts_next - ts
for i,v in l:
durations[i] += delta
i_next,v_next = l_next[i]
will_change = v != v_next or j+1 == len(acc)
print(f"{sys.argv[1]},{ts},{i},{v},{delta},{durations[i]},{will_change},{xp_time}")
if will_change: durations[i] = 0