Download scripts/flow_debug/belt_contents.py from beyarkay/factorio-blueprints: direct link, hf CLI and curl.
- Browser
- Download file 1.51 kB
-
https://huggingface.co/datasets/beyarkay/factorio-blueprints/resolve/main/scripts/flow_debug/belt_contents.py
- Command line
-
hf download hf://datasets/beyarkay/factorio-blueprints/scripts/flow_debug/belt_contents.py
-
curl -L -o belt_contents.py https://huggingface.co/datasets/beyarkay/factorio-blueprints/resolve/main/scripts/flow_debug/belt_contents.py
1.51 kB
| """Dump every belt-ish entity's per-line contents from a save (headless Factorio).""" | |
| import json, sys, collections | |
| from pathlib import Path | |
| import corpus.extract_saves as es | |
| es.LUA = """/sc local n = 0 | |
| for _, s in pairs(game.surfaces) do | |
| for _, e in pairs(s.find_entities_filtered{type = {"transport-belt", "underground-belt", "splitter"}, force = "player"}) do | |
| local lines = {} | |
| for i = 1, e.get_max_transport_line_index() do | |
| local items = {} | |
| for _, c in pairs(e.get_transport_line(i).get_contents()) do items[#items + 1] = c.name .. ":" .. c.count end | |
| lines[i] = table.concat(items, ",") | |
| end | |
| helpers.write_file("OUT", helpers.table_to_json{surface = s.name, name = e.name, x = e.position.x, y = e.position.y, | |
| dir = e.direction, kind = e.type == "underground-belt" and e.belt_to_ground_type or "", lines = lines} .. "\\n", true) | |
| n = n + 1 | |
| end | |
| end | |
| rcon.print(n)""" | |
| rows = es.extract(Path(sys.argv[1]), {"base"}, es.FACTORIO) | |
| json.dump(rows, open(sys.argv[2], "w")) | |
| c = collections.Counter() | |
| for r in rows: | |
| for line in r["lines"]: | |
| items = {x.split(":")[0] for x in line.split(",") if x} | |
| c["lines"] += 1 | |
| c[f"lines with {min(len(items), 2)}{'+' if len(items) >= 2 else ''} item kinds"] += 1 | |
| print(len(rows), "belt entities") | |
| for k, v in sorted(c.items()): | |
| print(f" {k}: {v}") | |
| top = collections.Counter(x.split(":")[0] for r in rows for line in r["lines"] for x in line.split(",") if x) | |
| print(" most common:", top.most_common(10)) | |