Files
openclaw-dnd-city-visualiza…/scripts/cost.py
T
rick 3d50023cfa Toolkit: segment, mass, render plates, batch, gate, matrices, cost, smoke test
Generalized from the render lanes' proven tools: map segmentation, 2.5D massing by
wealth zone, a CPU ray marcher with analytic landmarks and true-scale proxy people,
prompt composition from blocks, a self-calibrating batch submitter with a renderer
adapter point, the plate-vs-frame gates (drift, ECC, landmark region, skyline and
invented structures, figure brackets, corner sweep), matrix job builders, a cost
line, and an end-to-end smoke test on a synthetic town.
2026-10-14 11:39:57 +00:00

41 lines
1.7 KiB
Python

#!/usr/bin/env python3
"""Sum the render ledgers into the Cost line every run report must carry.
usage: cost.py --config citykit.json out_day/results.jsonl out_sunset/results.jsonl ... [--gpu-minutes 0]
Prices come from config.renderer.cost_usd: {"per_call_1ref": 0.06, "per_call_4ref": 0.09} (interpolated by the
number of references, measured 2026-10 on one hosted model at 2048x1152 high quality; set your own).
Counts every call, accepted and rejected, because volume is what costs money, not the unit price.
"""
import argparse
import json
from citykit import load_config
if __name__ == "__main__":
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("ledgers", nargs="+")
ap.add_argument("--config", required=True)
ap.add_argument("--gpu-minutes", type=float, default=0.0)
a = ap.parse_args()
cfg = load_config(a.config)
c = cfg["renderer"].get("cost_usd", {"per_call_1ref": 0.06, "per_call_4ref": 0.09})
c1, c4 = float(c["per_call_1ref"]), float(c["per_call_4ref"])
calls = ok = fail = 0
usd = 0.0
secs = 0.0
for p in a.ledgers:
for line in open(p):
if not line.strip():
continue
row = json.loads(line)
calls += 1
secs += row.get("secs", 0)
if row.get("status") == 200:
ok += 1
n = row.get("refs", 1)
usd += c1 + (c4 - c1) * min(max(n - 1, 0), 3) / 3.0
else:
fail += 1
print("Cost: %d renderer calls (%d accepted, %d failed/retried), about $%.2f; %.1f render-minutes of API time; "
"%.0f local GPU-minutes." % (calls, ok, fail, usd, secs / 60, a.gpu_minutes))