"""Delivers-anything / machine-output rates of two builder versions on the same views.""" import importlib.util, random, sys import numpy as np from functional import MACH, sample def load(path): spec = importlib.util.spec_from_file_location("cv_" + str(abs(hash(path))), path) m = importlib.util.module_from_spec(spec); spec.loader.exec_module(m); return m mods = [load(p) for p in sys.argv[3:]] views = sample(open(sys.argv[1]).read().split(), int(sys.argv[2]), nudge=True) cv0 = mods[0] for r, lab, *_ in views: r.lanes = {k: {getattr(cv0.str2item(n), "value", -1) or -1 for n in v} for k, v in lab.items()} r.drills = [(fx, fy, d) for (fx, fy), d in r.drills] has = [bool(np.isin(r.ent[x0:x0 + 30, y0:y0 + 30], list(MACH)).any()) for r, _, x0, y0 in views] for path, cv in zip(sys.argv[3:], mods): res = [] for r, lab, x0, y0 in views: w = cv.paste(r, x0, y0, 32, cv.edit(r, x0, y0, 32, random.Random(0))) tot, cr = cv.deliveries(w, cv._machine_items(w)[1]) res.append((tot > 0, cr > 0)) print(f"{path.split('/')[-1]:20s} deliver {np.mean([a for a, _ in res]):.1%} machines {np.mean([b for (_, b), h in zip(res, has) if h]):.1%} (of {sum(has)})")