import os
import subprocess
alg = "Barycenter"
want = "Number of leaf edge crossings: "
for sweeps in range(1, 11):
    sumcr = 0
    cnt = 0
    for filename in list(os.listdir("./data/experiments")):
        fin = os.path.join("./data/experiments/", filename)
        cmd = ["./build/TTMAlex", "-fin", f"{fin}", f"-{alg}", "-sweeps", str(sweeps)]
        out = subprocess.getoutput(" ".join(cmd))
        for line in out.split("\n"):
            if line.startswith(want):
                cr = int(line.strip().removeprefix(want))
        sumcr += cr
        cnt += 1
    print("{} sweeps:".format(int(sweeps)), sumcr/cnt)
    