jay0826 commited on
Commit
7ed6ba6
·
verified ·
1 Parent(s): 41ebe4d

更新 9 個檔(discordbot.py、vb_osu_local.py、vb_help.py、2026102318.json…)

Browse files
data/echo/recent.npz CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:393c4f890f49ae4f9de9dbfee3b1828553d0dc53e838b66f6cf0c8ab6dee2392
3
- size 384696
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:286f4d182237a09b3cdec559218ed78e5402c24278232bbd62742c9948a9e716
3
+ size 373585
data/ecmwf/aifs-ens/2026102400.json ADDED
The diff for this file is too large to render. See raw diff
 
data/ecmwf/ifs-ens/2026102400.json ADDED
The diff for this file is too large to render. See raw diff
 
data/radar/recent.npz CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:680b3703d34888b4c3a919a67346dee44dacb9dbd4fbf414113caa5e5a49ce32
3
- size 36832
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8c5ee3eef5c1a398edb8162547ed2e80fbb7e6eff2a8879d8bb8444f63c36af1
3
+ size 35696
data/wlab/ensemble/2026102318.json ADDED
The diff for this file is too large to render. See raw diff
 
data/wlab/ensemble/2026102400.json ADDED
The diff for this file is too large to render. See raw diff
 
discordbot.py CHANGED
@@ -10975,6 +10975,12 @@ async def osu_record(interaction: discord.Interaction, 玩家: Optional[str] = N
10975
  try:
10976
  import vb_osu_attempts as _OAT
10977
  simple, full = await asyncio.wait_for(asyncio.to_thread(_OAT.run, 玩家), timeout=120)
 
 
 
 
 
 
10978
  except asyncio.TimeoutError:
10979
  simple = full = "讀記錄太久了喵~(Supabase 沒回),等一下再試"
10980
  except Exception as e:
@@ -10987,6 +10993,40 @@ async def osu_record(interaction: discord.Interaction, 玩家: Optional[str] = N
10987
  await interaction.followup.send(simple, **({"view": v} if v is not None else {}))
10988
 
10989
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10990
  # ── /delta:三角洲行動改槍碼+配件 ──
10991
  # ★2026-09-23 主人「雞肋指令全做」:/delta news 拿掉(聊天問「三角洲最新更新」走同一支 get_game_news)、
10992
  # /delta player 拿掉(沒有官方 API,只是拿玩家名去網路搜尋,Jina 額度用完時幾乎都回「找不到」);
@@ -13525,6 +13565,8 @@ async def on_ready():
13525
  try:
13526
  import vb_osu_track as _OTR # ★2026-10-10 主人:「開始記錄我的嘗試」(OSU_RESEARCH.md §7.3 P1)
13527
  _OTR.attach(load=_notes_row_load, save=_notes_row_save) # 每人每天一列 __osu_att__<uid>_<日期>、狀態 __osu_track__
 
 
13528
  if _OTR.start():
13529
  print("[osu 嘗試記錄] 開始:%s,每小時一輪" % "、".join(_OTR.users()), flush=True)
13530
  except Exception as _ot_e:
 
10975
  try:
10976
  import vb_osu_attempts as _OAT
10977
  simple, full = await asyncio.wait_for(asyncio.to_thread(_OAT.run, 玩家), timeout=120)
10978
+ # ★2026-10-24 /osu import 匯入過 lazer 本機過關記錄 → 接一段在後面(vb_osu_local)
10979
+ import vb_osu_local as _OLC
10980
+ import vb_osu_track as _OTR
10981
+ ls, lf = await asyncio.wait_for(asyncio.to_thread(_OLC.section, 玩家 or (_OTR.users() or [""])[0]), timeout=60)
10982
+ if ls:
10983
+ simple, full = "\n".join([simple] + ls), "\n".join([full] + lf)
10984
  except asyncio.TimeoutError:
10985
  simple = full = "讀記錄太久了喵~(Supabase 沒回),等一下再試"
10986
  except Exception as e:
 
10993
  await interaction.followup.send(simple, **({"view": v} if v is not None else {}))
10994
 
10995
 
10996
+ @osu_group.command(name="import", description="匯入 lazer 本機過關記錄(tools/osu_local_export.py 產的檔;只有擁有者)")
10997
+ @app_commands.describe(檔案="osu_local_<名字>.json.gz")
10998
+ async def osu_import(interaction: discord.Interaction, 檔案: discord.Attachment):
10999
+ # ★2026-10-24 主人:「做1」=匯入 lazer 本機的記錄(OSU_RESEARCH.md §7.3 P1b)。只收追蹤名單裡的人(要本人同意)。
11000
+ if not await _is_owner_quiet(interaction.user):
11001
+ await interaction.response.send_message("這個只有擁有者能用喵", ephemeral=True)
11002
+ return
11003
+ await interaction.response.defer()
11004
+ import vb_osu_local as _OLC
11005
+ import vb_osu_track as _OTR
11006
+ if (檔案.size or 0) > _OLC.MAX_BYTES:
11007
+ await interaction.followup.send("檔案太大了喵(上限 %d MB)" % (_OLC.MAX_BYTES // 1024 // 1024))
11008
+ return
11009
+ try:
11010
+ name, rows = _OLC.parse_upload(await 檔案.read())
11011
+ hit = next((n for n in _OTR.users() if n.lower() == name.lower()), None)
11012
+ if hit is None:
11013
+ await interaction.followup.send("只收追蹤中的玩家(目前:%s),檔案裡是 %s 喵" % ("、".join(_OTR.users()) or "沒有", name))
11014
+ return
11015
+ await asyncio.wait_for(asyncio.to_thread(_OLC.store, hit, rows), timeout=60)
11016
+ ls, _ = await asyncio.to_thread(_OLC.section, hit)
11017
+ except ValueError as e:
11018
+ await interaction.followup.send("看不懂這個檔案喵:%s" % e)
11019
+ return
11020
+ except asyncio.TimeoutError:
11021
+ await interaction.followup.send("存太久了喵~(Supabase 沒回),等一下再丟一次")
11022
+ return
11023
+ except Exception as e:
11024
+ await interaction.followup.send(_fail("/osu import", e))
11025
+ return
11026
+ await interaction.followup.send("\n".join(["📥 匯入 %s 的本機過關記錄 %d 筆(%s ~ %s)" % (
11027
+ hit, len(rows), rows[0]["t"][:10], rows[-1]["t"][:10])] + ls + ["-# 之後 /osu record 會多這一段;再匯入一次=整份換新"]))
11028
+
11029
+
11030
  # ── /delta:三角洲行動改槍碼+配件 ──
11031
  # ★2026-09-23 主人「雞肋指令全做」:/delta news 拿掉(聊天問「三角洲最新更新」走同一支 get_game_news)、
11032
  # /delta player 拿掉(沒有官方 API,只是拿玩家名去網路搜尋,Jina 額度用完時幾乎都回「找不到」);
 
13565
  try:
13566
  import vb_osu_track as _OTR # ★2026-10-10 主人:「開始記錄我的嘗試」(OSU_RESEARCH.md §7.3 P1)
13567
  _OTR.attach(load=_notes_row_load, save=_notes_row_save) # 每人每天一列 __osu_att__<uid>_<日期>、狀態 __osu_track__
13568
+ import vb_osu_local as _OLC # /osu import 的 lazer 本機過關記錄:一人一列 __osu_local__<名字>
13569
+ _OLC.attach(load=_notes_row_load, save=_notes_row_save)
13570
  if _OTR.start():
13571
  print("[osu 嘗試記錄] 開始:%s,每小時一輪" % "、".join(_OTR.users()), flush=True)
13572
  except Exception as _ot_e:
vb_help.py CHANGED
@@ -68,6 +68,8 @@ PAGES: Dict[str, str] = {
68
  `/osu edge 玩家` — 跟同水準玩家比,你哪類圖強、哪類弱
69
  `/osu backtest 玩家` — (主人)用現有成績回測 farm 的預測準不準
70
  `/osu curve 玩家` — 再打一次值得嗎:打完 3 次再打一次,10 張有幾張會刷新、刷新時多幾 pp(`詳細:是` 給完整曲線圖)
 
 
71
  `/valorant 玩家` — 段位與最近對戰(格式 `名稱#Tag`)
72
  `/delta 武器` — 三角洲改槍碼+配件
73
  -# 遊戲版本更新直接問香草,例如「三角洲最新更新」""",
 
68
  `/osu edge 玩家` — 跟同水準玩家比,你哪類圖強、哪類弱
69
  `/osu backtest 玩家` — (主人)用現有成績回測 farm 的預測準不準
70
  `/osu curve 玩家` — 再打一次值得嗎:打完 3 次再打一次,10 張有幾張會刷新、刷新時多幾 pp(`詳細:是` 給完整曲線圖)
71
+ `/osu record` — 你的嘗試記錄:打完率、什麼時候重開、各分組(樣本夠才顯示);匯入過本機記錄會多「第幾次打完、熱身」
72
+ `/osu import 檔案` — (主人)匯入 lazer 本機過關記錄(電腦上跑 `tools/osu_local_export.py` 產的檔)
73
  `/valorant 玩家` — 段位與最近對戰(格式 `名稱#Tag`)
74
  `/delta 武器` — 三角洲改槍碼+配件
75
  -# 遊戲版本更新直接問香草,例如「三角洲最新更新」""",
vb_osu_local.py ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """/osu import:lazer 本機過關記錄(tools/osu_local_export.py 產的檔)→ 存起來,/osu record 多一段「本機過關記錄」。
3
+
4
+ ★2026-10-24 主人:「做1」(OSU_RESEARCH.md §7.3 P1b)。lazer 每次打完都存 replay,可以回溯好幾年;
5
+ 失敗的不存(rank F 只有失敗時手動按存檔才有,匯出工具已經丟掉)→ **只有過關**,打完率、重開習慣還是看 vb_osu_track。
6
+ ★問的問題(都只看過關,結果要標):
7
+ · 同一張圖第幾次打完、一次連打的第幾首 → 那次有沒有「比這張圖平常好」。
8
+ · 比這張圖平常好=miss 比你在**同一張圖、同一組 mods**(vb_osu_attempts.mod_key)所有過關的 miss 中位數少。
9
+ 跟自己那張圖比,圖的難度就抵掉了;至少 MIN_PER_MAP 次過關的圖才算(不然中位數沒意義)。
10
+ · 門檻、比較照 vb_osu_attempts:Wilson 95% 半寬 ≤ 15 個百分點才顯示,區間不重疊才說誰高。
11
+ · 第幾次會跟「時間」混在一起(後來打的那幾次你整體也變強了),文字要講。
12
+ ★存:notes 一列 __osu_local__<名字小寫>,每次匯入整份換掉(工具每次都匯出全部)。
13
+ """
14
+ import gzip
15
+ import json
16
+ import time
17
+ from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple
18
+
19
+ import vb_osu_attempts as A
20
+
21
+ MAX_BYTES = 5 * 1024 * 1024 # 丟上來的檔(gzip);2,500 筆約 60 KB
22
+ MAX_RAW = 40 * 1024 * 1024
23
+ MAX_ROWS = 200000
24
+ KEY = "__osu_local__"
25
+ MIN_PER_MAP = 4
26
+ NTH_BINS = ((1, 1, "這張第 1 次打完"), (2, 3, "第 2–3 次"), (4, 9, "第 4–9 次"), (10, 10 ** 9, "第 10 次以後"))
27
+ POS_BINS = ((1, 3, "第 1–3 首(熱身)"), (4, 10, "第 4–10 首"), (11, 10 ** 9, "第 11 首以後"))
28
+ _ST: Dict[str, Any] = {"load": None, "save": None, "cache": {}}
29
+
30
+
31
+ def attach(load: Optional[Callable[[str], Optional[str]]] = None, save: Optional[Callable[[str, str], None]] = None) -> None:
32
+ _ST.update(load=load, save=save, cache={})
33
+
34
+
35
+ def _int(x: Any) -> int:
36
+ try:
37
+ return max(0, int(x))
38
+ except (TypeError, ValueError):
39
+ return 0
40
+
41
+
42
+ def parse_upload(raw: bytes) -> Tuple[str, List[Dict[str, Any]]]:
43
+ """丟上來的檔 → (名字, 列)。看不懂就 ValueError(訊息直接給主人看)。"""
44
+ if len(raw) > MAX_BYTES:
45
+ raise ValueError("檔案太大(上限 %d MB)" % (MAX_BYTES // 1024 // 1024))
46
+ try:
47
+ if raw[:2] == b"\x1f\x8b":
48
+ with gzip.GzipFile(fileobj=__import__("io").BytesIO(raw)) as fh:
49
+ raw = fh.read(MAX_RAW + 1)
50
+ if len(raw) > MAX_RAW:
51
+ raise ValueError("解開後太大")
52
+ d = json.loads(raw.decode("utf-8"))
53
+ except (OSError, EOFError, UnicodeDecodeError, json.JSONDecodeError):
54
+ raise ValueError("不是 osu_local_export.py 產的檔(解不開)")
55
+ if not isinstance(d, dict) or d.get("kind") != "osu_local" or not isinstance(d.get("rows"), list):
56
+ raise ValueError("不是 osu_local_export.py 產的檔")
57
+ name = str(d.get("name") or "").strip()[:32]
58
+ rows = []
59
+ for r in d["rows"][:MAX_ROWS]:
60
+ if not isinstance(r, dict) or not isinstance(r.get("md5"), str) or len(r["md5"]) != 32:
61
+ continue
62
+ t = str(r.get("t") or "")
63
+ if len(t) != 20 or not t.endswith("Z"):
64
+ continue
65
+ s = r.get("s") if isinstance(r.get("s"), dict) else {}
66
+ mods = [str(m)[:4] for m in (r.get("mods") or [])[:12] if isinstance(m, str)]
67
+ rows.append({"t": t, "md5": r["md5"].lower(), "mods": mods, "s": {k: _int(v) for k, v in s.items() if isinstance(k, str)},
68
+ "mx": _int(r.get("mx")), "p": r.get("pauses") if isinstance(r.get("pauses"), int) else None})
69
+ if not name or not rows:
70
+ raise ValueError("檔案裡沒有記錄")
71
+ rows.sort(key=lambda r: r["t"])
72
+ return name, rows
73
+
74
+
75
+ # ═══ 存/讀(compact:圖的 md5 另外一張表)══════════════════
76
+ def _pack(name: str, rows: Sequence[Dict[str, Any]]) -> str:
77
+ maps: Dict[str, int] = {}
78
+ out = []
79
+ for r in rows:
80
+ mi = maps.setdefault(r["md5"], len(maps))
81
+ s = r["s"]
82
+ out.append([r["t"], mi, ",".join(r["mods"]), s.get("great", 0), s.get("ok", 0), s.get("meh", 0), s.get("miss", 0),
83
+ s.get("large_tick_miss", 0), r["mx"], r["p"]])
84
+ return json.dumps({"v": 1, "name": name, "at": int(time.time()), "maps": list(maps), "rows": out},
85
+ ensure_ascii=False, separators=(",", ":"))
86
+
87
+
88
+ def _unpack(raw: str) -> Optional[Dict[str, Any]]:
89
+ try:
90
+ d = json.loads(raw)
91
+ maps = d["maps"]
92
+ rows = [{"ended_at": t, "checksum": maps[mi], "mods": [{"acronym": m} for m in mods.split(",") if m], "passed": True,
93
+ "statistics": {"great": g, "ok": o, "meh": me, "miss": mi_, "large_tick_miss": ltm},
94
+ "maximum_statistics": {"great": mx}, "pauses": p}
95
+ for t, mi, mods, g, o, me, mi_, ltm, mx, p in d["rows"]]
96
+ return {"name": d["name"], "at": d.get("at"), "rows": rows}
97
+ except (ValueError, KeyError, TypeError, IndexError):
98
+ return None
99
+
100
+
101
+ def store(name: str, rows: Sequence[Dict[str, Any]]) -> None:
102
+ if not _ST["save"]:
103
+ raise RuntimeError("沒有接上儲存")
104
+ raw = _pack(name, rows)
105
+ _ST["save"](KEY + name.lower(), raw)
106
+ _ST["cache"][name.lower()] = _unpack(raw)
107
+
108
+
109
+ def get(name: str) -> Optional[Dict[str, Any]]:
110
+ k = name.lower()
111
+ if k not in _ST["cache"]:
112
+ raw = None
113
+ if _ST["load"]:
114
+ try:
115
+ raw = _ST["load"](KEY + k)
116
+ except Exception:
117
+ raw = None
118
+ _ST["cache"][k] = _unpack(raw) if raw else None
119
+ return _ST["cache"][k]
120
+
121
+
122
+ # ═══ 分析 ═════════════════════════════════════════════
123
+ def annotate(rows: Sequence[Dict[str, Any]]) -> List[Dict[str, Any]]:
124
+ """_nth=同一張圖同一組 mods 第幾次打完、_pos=一次連打第幾首、_good=miss 比這張圖(這組 mods)的中位數少(圖不夠多次=None)。"""
125
+ rs = sorted((dict(r) for r in rows), key=lambda r: r["ended_at"])
126
+ seen: Dict[Tuple[str, str], List[Dict[str, Any]]] = {}
127
+ last, pos = None, 0
128
+ for r in rs:
129
+ ts = A._ts(r)
130
+ pos = pos + 1 if (last is not None and ts is not None and ts - last <= A.SESSION_GAP_S) else 1
131
+ last = ts if ts is not None else last
132
+ r["_pos"] = pos
133
+ k = (r["checksum"], A.mod_key(r))
134
+ seen.setdefault(k, []).append(r)
135
+ r["_nth"] = len(seen[k])
136
+ for grp in seen.values():
137
+ med = A._median([A._st(r, "miss") for r in grp]) if len(grp) >= MIN_PER_MAP else None
138
+ for r in grp:
139
+ r["_good"] = None if med is None else A._st(r, "miss") < med
140
+ return rs
141
+
142
+
143
+ def _groups(rs: Sequence[Dict[str, Any]], field: str, bins) -> List[Tuple[str, int, int]]:
144
+ out = []
145
+ for lo, hi, lab in bins:
146
+ g = [r for r in rs if r["_good"] is not None and lo <= r[field] <= hi]
147
+ out.append((lab, sum(1 for r in g if r["_good"]), len(g)))
148
+ return out
149
+
150
+
151
+ def compare(ok: Sequence[Tuple[str, int, int]]) -> Optional[Tuple[Tuple[str, int, int], Tuple[str, int, int]]]:
152
+ """任兩組區間不重疊 → (高的, 低的),挑差最多的那對;都重疊 → None。
153
+ (vb_osu_attempts.compare 只看最高跟最低兩組,樣本少的那組區間寬就會蓋掉中間明明分得開的。)"""
154
+ best = None
155
+ for x in ok:
156
+ for y in ok:
157
+ wx, wy = A.wilson(x[1], x[2]), A.wilson(y[1], y[2])
158
+ if wx[1] > wy[2] and (best is None or wx[0] - wy[0] > best[0]):
159
+ best = (wx[0] - wy[0], x, y)
160
+ return best and (best[1], best[2])
161
+
162
+
163
+ def analyze(rows: Sequence[Dict[str, Any]]) -> Dict[str, Any]:
164
+ rs = annotate(rows)
165
+ used = [r for r in rs if r["_good"] is not None]
166
+ qs = []
167
+ for title, field, bins in (("同一張圖第幾次打完", "_nth", NTH_BINS), ("一次連打的第幾首", "_pos", POS_BINS)):
168
+ gs = [x for x in _groups(rs, field, bins) if x[2]]
169
+ ok = [x for x in gs if A.enough(x[1], x[2])]
170
+ wait = [(x[0], A.need_more(x[1], x[2]), x[2]) for x in gs if not A.enough(x[1], x[2])]
171
+ qs.append({"title": title, "ok": ok, "wait": wait, "cmp": compare(ok) if len(ok) >= 2 else None})
172
+ return {"n": len(rs), "used": len(used), "good": sum(1 for r in used if r["_good"]),
173
+ "maps": len({r["checksum"] for r in rs}), "maps_used": len({(r["checksum"], A.mod_key(r)) for r in used}),
174
+ "first": rs[0]["ended_at"][:10] if rs else "", "last": rs[-1]["ended_at"][:10] if rs else "", "qs": qs}
175
+
176
+
177
+ def render(a: Dict[str, Any], at: Optional[int] = None) -> Tuple[List[str], List[str]]:
178
+ """→ (精簡的幾行, 完整的一段);給 /osu record 接在後面。"""
179
+ head = "**本機過關記錄**(lazer 匯入:%d 次過關、%d 張圖、%s ~ %s)" % (a["n"], a["maps"], a["first"], a["last"])
180
+ F = ["", head]
181
+ S: List[str] = []
182
+ if not a["used"]:
183
+ F.append("· 同一張圖(同一組 mods)過關 %d 次以上的還沒有,比不出來" % MIN_PER_MAP)
184
+ return S, F
185
+ F.append("-# 比的是「這次 miss 比你在這張圖平常(中位數)少」的比例;只算過關 %d 次以上的 %d 組圖+mods、%d 次過關" % (
186
+ MIN_PER_MAP, a["maps_used"], a["used"]))
187
+ for q in a["qs"]:
188
+ F.append("· %s" % q["title"])
189
+ F += [" · %s:%s(%d 次)" % (g, A.pct(k, m), m) for g, k, m in q["ok"]]
190
+ if q["cmp"]:
191
+ hi, lo = q["cmp"]
192
+ F.append(" → **%s** 明顯比 **%s** 常比平常好" % (hi[0], lo[0]))
193
+ S.append("%s:**%s** 有 %s 比平常好、**%s** %s" % (q["title"], lo[0], A.pct(lo[1], lo[2]).split("(")[0],
194
+ hi[0], A.pct(hi[1], hi[2]).split("(")[0]))
195
+ elif len(q["ok"]) >= 2:
196
+ F.append(" → 看不出差別(區間重疊)")
197
+ if q["wait"]:
198
+ F.append(" -# 還不夠:" + "、".join("%s 還差約 %d 次(現 %d)" % w for w in q["wait"]))
199
+ if not S:
200
+ S.append("-# 本機過關記錄(%d 次):第幾次打完、熱身都看不出差別" % a["n"])
201
+ else:
202
+ S.insert(0, "-# 以下是本機過關記錄(%d 次過關;比平常好=miss 比你在那張圖的中位數少)" % a["n"])
203
+ F.append("-# 只有過關(lazer 不存失敗的)。第幾次跟時間混在一起:打到第 10 次時你整體也比較強了。%s" % (
204
+ ("匯入於 %s" % time.strftime("%Y-%m-%d", time.localtime(at))) if at else ""))
205
+ return S, F
206
+
207
+
208
+ def section(name: str) -> Tuple[List[str], List[str]]:
209
+ """/osu record 用:有匯入過就回 (精簡, 完整),沒有就回空的。"""
210
+ d = get(name)
211
+ if not d or not d["rows"]:
212
+ return [], []
213
+ return render(analyze(d["rows"]), d.get("at"))