97 lines
3.6 KiB
Python
97 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
|
"""$0-довески отчёта research/24 (заявление = команда): реплика DetectSeries на BANK-FULL ·
|
|
доля spread>=2 на полном банке · чувствительность состава совета (grok, C4) · деньги из сырья."""
|
|
import collections
|
|
import glob
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
from arbitrate import parse_pass, eq, majority # noqa: E402
|
|
|
|
BANKFULL = "/home/ubuntu/books/gu-zhenren/coldrun-a/BANK-FULL.tsv"
|
|
RAW = str(Path.home() / "books" / "gu-zhenren" / "bank-arbitration")
|
|
GOLD = [json.loads(l) for l in open(Path(__file__).resolve().parent / "gold" / "gold.jsonl", encoding="utf-8")]
|
|
|
|
|
|
def series_replica():
|
|
surfs = [l.split("\t")[0] for l in open(BANKFULL, encoding="utf-8").read().split("\n")[1:] if l.strip()]
|
|
groups = collections.defaultdict(list)
|
|
order = []
|
|
for s in surfs:
|
|
rs = list(s)
|
|
n = len(rs)
|
|
if n < 2:
|
|
continue
|
|
for pos in range(n - 1): # head-final: последняя руна — голова
|
|
skel = (n, pos, "".join(rs[:pos]) + "\x00" + "".join(rs[pos + 1:]))
|
|
if skel not in groups:
|
|
order.append(skel)
|
|
if s not in groups[skel]:
|
|
groups[skel].append(s)
|
|
order.sort(key=lambda g: -len(groups[g]))
|
|
assigned = {}
|
|
sid = 0
|
|
for g in order:
|
|
fresh = [k for k in groups[g] if k not in assigned]
|
|
if len(fresh) >= 3:
|
|
sid += 1
|
|
for k in fresh:
|
|
assigned[k] = sid
|
|
series = collections.defaultdict(list)
|
|
for k, v in assigned.items():
|
|
series[v].append(k)
|
|
for i, ms in sorted(series.items()):
|
|
print("series", i, ":", " ".join(sorted(ms)))
|
|
|
|
|
|
def contested_share():
|
|
rows = [l.split("\t") for l in open(BANKFULL, encoding="utf-8").read().split("\n")[1:] if l.strip()]
|
|
sp = [int(r[5]) for r in rows if len(r) > 5]
|
|
n2 = sum(1 for s in sp if s >= 2)
|
|
print(f"BANK-FULL: {len(sp)} строк, spread>=2: {n2} ({n2 / len(sp):.0%})")
|
|
|
|
|
|
def council4():
|
|
inb = {r["bank_src"]: r for r in GOLD if r["in_bank"]}
|
|
p = {t: parse_pass(t) for t in ["ds1", "glm1", "mis1", "gro1"]}
|
|
acc = {}
|
|
for t in p:
|
|
ok = [s for s, g in inb.items() if eq(p[t]["map"].get(s, ("", None))[0], g["gold_dst"])]
|
|
acc[t] = set(ok)
|
|
print(f"{t}: {len(ok)}/45 (cost ${p[t]['cost']:.6f})")
|
|
c4 = set()
|
|
for s, g in inb.items():
|
|
votes = [p[t]["map"].get(s, ("", None))[0] for t in ["ds1", "glm1", "mis1", "gro1"]]
|
|
if eq(majority(votes, fallback=votes[0]), g["gold_dst"]):
|
|
c4.add(s)
|
|
print(f"C4 (majority из 4): {len(c4)}/45")
|
|
print("gro1-only wins:", sorted(acc["gro1"] - (acc["ds1"] | acc["glm1"] | acc["mis1"])))
|
|
for m in sorted(s for s in inb if s.startswith("古月")):
|
|
print(" ", m, "gro1=", p["gro1"]["map"].get(m, ("", None))[0])
|
|
|
|
|
|
def money():
|
|
tot = 0.0
|
|
by = collections.defaultdict(float)
|
|
for f in glob.glob(RAW + "/*.json"):
|
|
r = json.load(open(f))
|
|
tag = r["tag"].split("-b")[0].split("-w")[0]
|
|
by[tag] += r["cost_usd"]
|
|
tot += r["cost_usd"]
|
|
for t, c in sorted(by.items()):
|
|
print(f"{t}: ${c:.6f}")
|
|
print(f"TOTAL: ${tot:.6f}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
cmd = sys.argv[1] if len(sys.argv) > 1 else "all"
|
|
if cmd in ("series", "all"):
|
|
series_replica()
|
|
if cmd in ("contested", "all"):
|
|
contested_share()
|
|
if cmd in ("c4", "all"):
|
|
council4()
|
|
if cmd in ("money", "all"):
|
|
money()
|