"""12 random views (not filtered on success) built by corpus.convert.edit.""" import glob, random, sys import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt import numpy as np, torch sys.path.insert(0, "scripts") from render_png import draw import corpus.convert as cv from functional import MACH, sample from factorion import Channel, count_unpowered views = sample(open(sys.argv[1][1:]).read().split() if sys.argv[1][0] == "@" else sorted(glob.glob(sys.argv[1])), int(sys.argv[2]), nudge=True) pick = random.Random(int(sys.argv[4])).sample(range(len(views)), 12) fig, axes = plt.subplots(3, 4, figsize=(40, 31)) SRC, SNK = cv._SOURCE, cv._SINK for ax, i in zip(axes.flat, pick): r, lab, x0, y0 = views[i] r.lanes = {k: {getattr(cv.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] w = cv.paste(r, x0, y0, 32, cv.edit(r, x0, y0, 32, random.Random(0))) t, cr = cv.deliveries(w, cv._machine_items(w)[1]) ent = w[Channel.ENTITIES.value] has_m = np.isin(ent, list(MACH)).any() status = ("WORKS: machines deliver %.2f/s" % cr) if cr > 0 else ("delivers %.2f/s (belts only)" % t if t > 0 else "DELIVERS NOTHING") extra = f"{(ent == SRC).sum()} sources, {(ent == SNK).sum()} sinks" + (f", has machines, {count_unpowered(torch.from_numpy(w))} unpowered" if has_m else ", no machines") draw(w, ax, f"#{i}: {status}\n{extra}") ax.title.set_fontsize(22) fig.savefig(sys.argv[3], dpi=60, bbox_inches="tight")