Download scripts/flow_debug/count_views.py from beyarkay/factorio-blueprints: direct link, hf CLI and curl.
- Browser
- Download file 812 Bytes
-
https://huggingface.co/datasets/beyarkay/factorio-blueprints/resolve/main/scripts/flow_debug/count_views.py
- Command line
-
hf download hf://datasets/beyarkay/factorio-blueprints/scripts/flow_debug/count_views.py
-
curl -L -o count_views.py https://huggingface.co/datasets/beyarkay/factorio-blueprints/resolve/main/scripts/flow_debug/count_views.py
812 Bytes
| import glob, itertools, sys, time | |
| import numpy as np | |
| import corpus.convert as cv | |
| from build_tasks import records | |
| n, tr, counts = 30, 0.0, {15: [], 30: []} | |
| for rec in itertools.islice((r for r in records(sorted(glob.glob(sys.argv[1]))) if r.get("lanes")), 300): | |
| bp = next(cv.designs(rec["string"])); bp["unbuildable"] = rec["unbuildable"]; bp["lanes"] = rec["lanes"] | |
| t = time.time(); r = cv.rasterise(bp); tr += time.time() - t | |
| if r is None: continue | |
| W, H = r.ent.shape | |
| for s in counts: | |
| counts[s].append(sum(cv.cut(r, (slice(x, x + n), slice(y, y + n))) is not None for x in range(1, W - n, s) for y in range(1, H - n, s))) | |
| print(f"rasterise {tr / 300 * 1000:.0f} ms") | |
| for s, c in counts.items(): print(s, "mean", np.mean(c), "median", np.median(c), "zero", np.mean(np.array(c) == 0)) | |