factorio-blueprints / scripts /flow_debug /render_sample.py
beyarkay's picture
Lane re-export scripts and progress, window debugging scripts
0a3edb6 verified
Raw History Blame Contribute Delete
1.3 kB
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
from functional import MACH, C, SRC, SNK, sample, window, crafted_delivery, thput
from measure import CONFIGS
from factorion import count_unpowered
views = sample(sorted(glob.glob(sys.argv[1])), int(sys.argv[2]), nudge=True)
cfg, out = CONFIGS[sys.argv[3]], sys.argv[4]
pick = random.Random(int(sys.argv[5]) if len(sys.argv) > 5 else 1).sample(range(len(views)), 12)
fig, axes = plt.subplots(3, 4, figsize=(40, 31))
for ax, i in zip(axes.flat, pick):
r, lab, x0, y0 = views[i]
w, _ = window(r, lab, x0, y0, cfg)
t, cr = thput(w), crafted_delivery(w)
n_src, n_snk = int((w[C[0]] == SRC).sum()), int((w[C[0]] == SNK).sum())
has_m = np.isin(w[C[0]], 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"{n_src} sources, {n_snk} sinks" + (", has machines" if has_m else ", no machines") + (f", {count_unpowered(torch.from_numpy(w))} unpowered" if has_m else "")
draw(w, ax, f"#{i}: {status}\n{extra}")
ax.title.set_fontsize(22)
fig.savefig(out, dpi=60, bbox_inches="tight")