Add TRK set preview and refresh draft analysis
Track the TRK preview package and the newest value artifacts for FRA20261007, move the 17lands API notes under data, and ignore downloaded 17lands, card image and live directories.
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
#!/usr/bin/env python3
|
||||
"""把 bin/advisor/v2.0/advisor pick 的结果 + 每张牌的 IIH / ALSA 排成人看的表。
|
||||
|
||||
用法(state JSON 与 advisor 完全一致):
|
||||
python scripts/pick_view.py --state state.json
|
||||
echo '{"pack":[...],"pool":[...]}' | python scripts/pick_view.py
|
||||
|
||||
字段说明:
|
||||
GIH = ever_drawn_win_rate(见过就赢的胜率)
|
||||
IIH = GIH − GNS(never_drawn_win_rate),即“置入手中带来的胜率提升”
|
||||
ALSA = avg_seen(平均最后被看到的位置,越小越早被抢)
|
||||
score = advisor 跨 20 个思路加权后的分(决定建议抓哪张)
|
||||
value = 这张牌在自己最合思路里的分
|
||||
"""
|
||||
import argparse
|
||||
import importlib.machinery
|
||||
import importlib.util
|
||||
import json
|
||||
import sys
|
||||
from collections import Counter
|
||||
from pathlib import Path
|
||||
|
||||
m_P0 = 0.5626 # advisor 的 P0,用于缺 GIH 时的粗估
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
def load_advisor():
|
||||
_c = sorted((ROOT / "bin" / "advisor").glob("v*/advisor"))
|
||||
_p = _c[-1] if _c else (ROOT / "bin" / "advisor" / "v2.0" / "advisor")
|
||||
loader = importlib.machinery.SourceFileLoader("advisor", str(_p))
|
||||
spec = importlib.util.spec_from_loader("advisor", loader)
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
loader.exec_module(mod)
|
||||
return mod
|
||||
|
||||
|
||||
def iih(d, name):
|
||||
"""IIH = GIH − GNS(百分点)。缺字段就退回 drawn_improvement_win_rate。"""
|
||||
c = d.cdata.get(name) or {}
|
||||
gih = c.get("ever_drawn_win_rate")
|
||||
gns = c.get("never_drawn_win_rate")
|
||||
if gih is not None and gns is not None:
|
||||
return (gih - gns) * 100
|
||||
imp = c.get("drawn_improvement_win_rate")
|
||||
if imp is not None:
|
||||
return imp * 100
|
||||
if gih is None and c.get("win_rate") is not None:
|
||||
return (d.gjwr(name) - m_P0) * 100 # 只能给个粗略下界,带 * 标记
|
||||
return None
|
||||
|
||||
|
||||
def fmt(v, width=6, digits=1, plus=True):
|
||||
if v is None:
|
||||
return " " * (width - 1) + "—"
|
||||
return ("%+*.*f" if plus else "%*.*f") % (width, digits, v)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--snapshot", default="FRA20261011")
|
||||
ap.add_argument("--state", default="-")
|
||||
a = ap.parse_args()
|
||||
adv = load_advisor()
|
||||
d = adv.Data(a.snapshot)
|
||||
st = json.load(open(a.state, encoding="utf-8")) if a.state != "-" else json.load(sys.stdin)
|
||||
|
||||
pack = [d.name_of(c) for c in st.get("pack") or []]
|
||||
bad = d.unknown(pack + [d.name_of(c) for c in (st.get("pool") or [])])
|
||||
if bad:
|
||||
print("无法识别的牌:", bad)
|
||||
return 2
|
||||
|
||||
scored, fits, weights = adv.score_cards(d, pack, adv.pool_counts(st.get("pool")), st.get("colors"))
|
||||
best_slug = max(fits, key=lambda s: fits[s]) if fits else None
|
||||
|
||||
def minmax(slug, nm):
|
||||
"""该牌在指定思路里的 min/max_copies(实测的同名张数区间)。"""
|
||||
if slug not in d.templates:
|
||||
return 0, 0
|
||||
c = d.templates[slug]["_cardmap"].get(nm)
|
||||
return int((c or {}).get("min_copies") or 0), int((c or {}).get("max_copies") or 0)
|
||||
|
||||
print("## 包内 %d 张(按 score 降序)\n" % len(pack))
|
||||
print("| # | 牌 | 费用 | GIH | **IIH** | **ALSA** | **score** | value | min/max | 该牌最合的思路 |")
|
||||
print("|---|---|---|---|---|---|---|---|---|---|")
|
||||
for i, r in enumerate(scored, 1):
|
||||
nm = r["name"]
|
||||
c = d.cdata.get(nm) or {}
|
||||
gih = c.get("ever_drawn_win_rate")
|
||||
tag = ""
|
||||
if gih is None and c.get("win_rate") is not None:
|
||||
gih = d.gjwr(nm) # 17lands 没给 ever_drawn,用回归外推
|
||||
tag = "*"
|
||||
slug = r.get("archetype")
|
||||
arch = d.templates[slug]["archetype_name"] if slug in d.templates else "—"
|
||||
sel = " ← **建议**" if i == 1 else ""
|
||||
mn, mx = minmax(slug, nm)
|
||||
mm = "%d/%d" % (mn, mx) if mx else "—"
|
||||
print("| %d | %s%s | `%s` | %s | %s | %s | **%.3f** | %.3f | %s | %s |" % (
|
||||
i, nm, sel, d.mana_cost(nm) or "—",
|
||||
(fmt(gih * 100, 5, 1, False) + tag) if gih is not None else fmt(None, 5, 1, False),
|
||||
fmt(iih(d, nm), 5), fmt(c.get("avg_seen"), 5, 2, False),
|
||||
r.get("score", 0), r.get("value", 0), mm, arch))
|
||||
|
||||
pool = adv.pool_counts(st.get("pool"))
|
||||
pips = Counter()
|
||||
for nm, n in pool.items():
|
||||
if nm in adv.BASICS or adv.is_land(d, nm):
|
||||
continue
|
||||
for ch in d.req_colors(nm):
|
||||
pips[ch] += n
|
||||
print("\n## 牌池 %d 张 · 色符 %s\n" % (
|
||||
sum(pool.values()), " · ".join("%s %d" % (k, v) for k, v in pips.most_common()) or "(空)"))
|
||||
|
||||
main = [s for s in d.index if not s.endswith("-Other")]
|
||||
print("## 20 个思路的 fit(对同一副牌池)\n")
|
||||
print("| 思路 | 色组 | fit | 权重 | 条形 |")
|
||||
print("|---|---|---|---|---|")
|
||||
top = max(fits.values()) if fits else 1
|
||||
for s in sorted(main, key=lambda x: -fits.get(x, 0)):
|
||||
t = d.templates[s]
|
||||
bar = "█" * max(0, int(round(fits.get(s, 0) / top * 20))) if top > 0 else ""
|
||||
print("| %s%s | %s | **%.3f** | %.3f | `%s` |" % (
|
||||
t["archetype_name"], " ←" if s == max(fits, key=lambda k: fits[k]) else "",
|
||||
(t.get("colors") or t["archetype"]).upper(), fits.get(s, 0), weights.get(s, 0), bar))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user