"""Split a player log into per-session blocks and report what each session was. Night-8 triage: Oracle ran 4.11.659 for the first half of the evening and only switched to 4.11.674 at 21:27, so every claim from his log has to be attributed to the right build before it means anything. """ import re import sys import os path = sys.argv[1] want_build = sys.argv[2] if len(sys.argv) > 2 else None data = open(path, "r", encoding="latin-1", errors="replace").read() hdr = re.compile(r"===== BT411 SESSION\s+build=(\S+)\s+\(\S+\)\s+machine=(\S+)\s+user=(\S+).*?local=(\S+ \S+)") marks = [(m.start(), m.group(1), m.group(2), m.group(3), m.group(4)) for m in hdr.finditer(data)] print("%s: %d session(s)" % (os.path.basename(path), len(marks))) for i, (pos, build, mach, user, when) in enumerate(marks): end = marks[i + 1][0] if i + 1 < len(marks) else len(data) block = data[pos:end] if want_build and build != want_build: continue # what actually happened in this session mech = set(re.findall(r"vehicle[= ]+([A-Za-z0-9_]+)", block)) kills = len(re.findall(r"\bkill\b", block, re.I)) leaks = len(re.findall(r"\[cool\]|leak", block, re.I)) print(" #%-2d %s %s len=%-9d mech=%-22s lines=%d" % (i + 1, build, when, len(block), ",".join(sorted(mech))[:22] or "-", block.count("\n")))