#!/bin/bash
# ozet: print the measured results straight from the raw logs (no numbers typed by hand).
R="$HOME/Projects/csint-mullvad-test/raw"
python3 - "$R" <<'PY'
import json, sys
R = sys.argv[1]
d = json.load(open(f"{R}/grafik.json"))
g = {l.split()[0]: l.split() for l in open(f"{R}/gizleme.log") if l.strip()}
k = {"off": [], "on": []}
for l in open(f"{R}/kuantum.log"):
    f = l.split(); k[f[0]].append(float(f[3]) - float(f[2]))
lat = [l.split("median")[1].strip() for l in open(f"{R}/gecikme.log") if "median" in l]
m = lambda v: sorted(v)[len(v) // 2]
print(f"DAITA off   {d['kapali']['packets']:>6} packets  {d['kapali']['distinct_sizes']:>3} sizes  {d['kapali']['bytes']/1e6:5.1f} MB")
print(f"DAITA on    {d['acik']['packets']:>6} packets  {d['acik']['distinct_sizes']:>3} sizes  {d['acik']['bytes']/1e6:5.1f} MB")
for mode in ("off", "udp2tcp", "shadowsocks", "quic", "lwo", "wireguard-port"):
    f = g[mode]
    print(f"{mode:15s} WireGuard {f[4]:>5} of {f[5]:<5} connect {float(f[2]) - float(f[1]):.2f} s")
print(f"multihop        connect ms  single {lat[0]}  multihop {lat[1]}")
print(f"quantum         connect s   off {m(k['off']):.2f}  on {m(k['on']):.2f}")
PY
