#!/usr/bin/env python3 """Summarize a shellmap bot-war from lua.log BAL telemetry. Usage: balance_report.py [path-to-lua.log] """ import os, re, sys path = sys.argv[1] if len(sys.argv) > 1 else os.path.expanduser('~/Library/Application Support/OpenRA/Logs/lua.log') rows = [] for line in open(path): m = re.search(r'BAL t=(\d+) (\w+) cash=(\d+) stored=(\d+) units=(\d+) buildings=(\d+)', line) if m: rows.append((int(m[1]), m[2], int(m[3]), int(m[4]), int(m[5]), int(m[6]))) m = re.search(r'BAL t=(\d+) (\w+) ELIMINATED', line) if m: print(f'*** {m[2]} ELIMINATED at tick {m[1]} (~{int(m[1]) // 25}s)') if not rows: sys.exit('no BAL telemetry found') bots = sorted({r[1] for r in rows}) print(f'{"tick":>6} ' + ''.join(f'{b + " $/store/u/b":>28}' for b in bots)) ticks = sorted({r[0] for r in rows}) for t in ticks[:: max(1, len(ticks) // 12)]: line = f'{t:>6} ' for b in bots: r = next((x for x in rows if x[0] == t and x[1] == b), None) line += f'{f"{r[2]}/{r[3]}/{r[4]}/{r[5]}" if r else "-":>28}' print(line) print('\nfinal:') for b in bots: r = [x for x in rows if x[1] == b][-1] print(f' {b}: cash={r[2]} stored={r[3]} units={r[4]} buildings={r[5]}')