checkpoint

This commit is contained in:
2025-11-09 08:52:03 +00:00
parent 11fe895274
commit f9e1ad0768
4 changed files with 85 additions and 1 deletions

30
main.py
View File

@@ -339,6 +339,36 @@ def index():
"inputs": step_inputs,
})
# Build consumers index per item from the steps' inputs
consumers_by_item: Dict[str, List[dict]] = defaultdict(list)
for s in steps:
for inp in s.get("inputs", []):
consumers_by_item[inp["item"]].append({
"recipe": s["recipe"],
"building": s["building"],
"rate": inp["rate"],
})
# Targets by item for final outputs annotation
target_rates_by_item: Dict[str, float] = {}
for itm, qty in targets.items():
if qty > 0:
target_rates_by_item[itm.value.name] = qty
# Attach destinations to each step (who consumes this step's primary output)
for s in steps:
item_name = s["item"]
dests = list(consumers_by_item.get(item_name, []))
# If this item is also a final target, add a synthetic destination
if item_name in target_rates_by_item:
dests.append({
"recipe": "Final output",
"building": "",
"rate": target_rates_by_item[item_name],
})
# Sort destinations by descending rate for display
dests.sort(key=lambda x: x["rate"], reverse=True)
s["destinations"] = dests
# Aggregate targets for display
result_targets = {}
for itm, qty in targets.items():