jay0826 commited on
Commit
9b03532
·
verified ·
1 Parent(s): c02f2d3

更新 2 個檔(vb_osu_farm.py、recent.npz)

Browse files
Files changed (1) hide show
  1. vb_osu_farm.py +73 -14
vb_osu_farm.py CHANGED
@@ -183,15 +183,63 @@ def acc_factor(user_scores: List[Dict[str, Any]], peer_scores: List[Dict[str, An
183
  return max(0.97, min(1.01, u / p))
184
 
185
 
186
- def predict(c: Dict[str, Any], factor: float) -> Dict[str, Any]:
187
- acc = max(80.0, min(100.0, statistics.median(c["accs"]) * factor))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  miss = int(round(statistics.median(c["misses"])))
189
  mc = c.get("map_max_combo") or c.get("max_combo")
190
  if mc:
191
  ratio = statistics.median(min(1.0, x / mc) for x in c["combos"]) if c["combos"] else 0.9
192
  else:
193
  ratio = 0.9
194
- return {"acc": acc, "miss": miss, "combo_ratio": max(0.3, min(1.0, ratio)), "n": len(c["users"])}
 
195
 
196
 
197
  # ── 校準:rosu vs 官方 pp ─────────────────────────────────────────
@@ -267,15 +315,20 @@ def confidence(n: int) -> float:
267
 
268
  # ── 逐張評估 ───────────────────────────────────────────────────────
269
  def evaluate(short: List[Dict[str, Any]], user_best: Dict[int, float], factor: float,
270
- calc: CalcFn, profile: Optional[Dict[str, Any]] = None) -> List[Dict[str, Any]]:
 
271
  """預期 pp = P(FC)×FC 的 pp + (1−P(FC))×「掉主人常見 miss 數」的 pp。
272
- P(FC) 來自主人自己的 top 成績;acc 來自同水準玩家在這張圖的表現 × 主人的 acc 係數。"""
 
 
273
  prof = profile or {"p_fc": 1.0, "miss": 0, "combo_ratio": 0.9}
274
  out = []
275
  for c in short:
276
- p = predict(c, factor)
277
  miss = int(prof["miss"]) if prof["p_fc"] < 1.0 else 0
278
  try:
 
 
 
279
  fc = calc(c["beatmap_id"], c["mods"], p["acc"], 0, None, c["lazer"])
280
  mc = fc["max_combo"]
281
  combo = max(1, int(round(mc * prof["combo_ratio"])))
@@ -287,10 +340,12 @@ def evaluate(short: List[Dict[str, Any]], user_best: Dict[int, float], factor: f
287
  star_warn = (c["mods_key"] == "" and c.get("stars_api") and
288
  abs(fc["stars"] - c["stars_api"]) > STAR_TOL)
289
  gain = marginal_gain(user_best, c["beatmap_id"], exp_pp)
290
- out.append(dict(c, acc=p["acc"], miss=miss, n=p["n"], combo=combo, p_fc=prof["p_fc"],
 
 
291
  stars=fc["stars"], max_combo=mc, fc_pp=fc["pp"], bad_pp=bad["pp"], exp_pp=exp_pp,
292
  gain=gain, gain_fc=marginal_gain(user_best, c["beatmap_id"], fc["pp"]),
293
- rank_key=gain * confidence(p["n"]),
294
  have_pp=user_best.get(c["beatmap_id"], 0.0), star_warn=bool(star_warn)))
295
  out.sort(key=lambda r: -(r.get("rank_key") or 0.0))
296
  return out
@@ -329,17 +384,19 @@ def format_report(username: str, user_pp: float, results: List[Dict[str, Any]],
329
  return "\n".join(head + ["同水準玩家的圖你都已經有更高的 pp 了,或候選裡沒有符合 mods 篩選的圖。"])
330
  p_fc = rows[0].get("p_fc", 1.0)
331
  tail = ["-# 預期=FC 機率 %.0f%%(來自你的 top 成績)× FC 的 pp + 其餘 × 掉 %d miss 的 pp;"
332
- "acc 取同水準玩家在該圖的中位數 × 你的 acc 係數。排序=總 pp 增加 × 樣本信心。只列 ranked/approved。"
 
333
  % (p_fc * 100, rows[0].get("miss", 0))]
334
  lines: List[str] = []
335
  budget = 1950 - len("\n".join(head + tail)) - 2
336
  for i, r in enumerate(rows, 1):
337
- ln = ("**%d.** [%s - %s [%s]](https://osu.ppy.sh/b/%d) · **%s** · %.2f★ · 樣本 %d 人%s\n"
 
338
  " 預期 **%.0f pp** → 總 pp **+%.0f**(FC %.0f pp → +%.0f;acc %.1f%%%s)" % (
339
  i, r["artist"][:24], r["title"][:32], r["version"][:18], r["beatmap_id"],
340
  _mods_txt(r["mods_key"]), r["stars"], r["n"],
341
  "(⚠ 星數與官方差 %.2f)" % abs(r["stars"] - r["stars_api"]) if r.get("star_warn") else "",
342
- r["exp_pp"], r["gain"], r["fc_pp"], r["gain_fc"], r["acc"],
343
  (";你現有 %.0f pp" % r["have_pp"]) if r["have_pp"] else ""))
344
  if len(ln) + 1 > budget:
345
  break
@@ -521,7 +578,9 @@ def run(client: Any, username: str, filt: str = "any", top_n: int = 10, peers_n:
521
  short = shortlist(cands, user_best, shortlist_n)
522
  factor = acc_factor(user_scores, peer_scores)
523
  prof = user_profile(user_scores)
524
- results = evaluate(short, user_best, factor, calc, prof)
525
- log("[osu] 候選 %d、精算 %d、acc 係數 %.3f、FC 率 %.0f%%、非 FC 中位 miss %d" % (
526
- len(cands), len(short), factor, prof["p_fc"] * 100, prof["miss"]))
 
 
527
  return format_report(uname, upp, results, calib, filt, len(peer_ids), top_n, engine, notes)
 
183
  return max(0.97, min(1.01, u / p))
184
 
185
 
186
+ def acc_model(user_scores: List[Dict[str, Any]]) -> Dict[str, Any]:
187
+ """主人自己的「acc 對星數」趨勢(top 成績最小平方直線)+ 常打的星數範圍。
188
+
189
+ ★第一次成功實跑:推薦全是 5.5–6.2★、acc 85–89% 的圖,而主人的 top 全是 4.4–4.9★、93–98%。
190
+ 那些 acc 是**單一同水準玩家在那張圖的最佳成績**,樣本 1 人時就是選擇偏誤。
191
+ 所以 acc 改成「同水準玩家 × 主人 acc 係數」跟「主人自己趨勢外推」的混合,樣本越少越信自己。"""
192
+ pts = [(float(s["stars"]), float(s["acc"])) for s in user_scores
193
+ if s.get("pp") and s.get("stars") and s.get("acc")]
194
+ if len(pts) < 5:
195
+ return {"n": len(pts), "a": None, "b": 0.0, "p90": None, "max": None}
196
+ n = len(pts)
197
+ mx = sum(x for x, _ in pts) / n
198
+ my = sum(y for _, y in pts) / n
199
+ den = sum((x - mx) ** 2 for x, _ in pts)
200
+ b = (sum((x - mx) * (y - my) for x, y in pts) / den) if den > 1e-9 else 0.0
201
+ b = min(0.0, b) # 星數越高 acc 只會更低,不外推成更高
202
+ a = my - b * mx
203
+ srs = sorted(x for x, _ in pts)
204
+ return {"n": n, "a": a, "b": b, "p90": srs[int(0.9 * (n - 1))], "max": srs[-1]}
205
+
206
+
207
+ def acc_at(model: Dict[str, Any], stars: float) -> Optional[float]:
208
+ if not model or model.get("a") is None:
209
+ return None
210
+ return max(70.0, min(100.0, model["a"] + model["b"] * float(stars)))
211
+
212
+
213
+ def difficulty_factor(model: Dict[str, Any], stars: float) -> Tuple[float, float]:
214
+ """(排序係數, 比常打的難多少★)。超過主人 top 的 p90 星數 0.3★ 以上就打折,超過最高 0.6★ 以上打大折。"""
215
+ if not model or model.get("p90") is None:
216
+ return 1.0, 0.0
217
+ over = float(stars) - model["p90"]
218
+ if float(stars) > model["max"] + 0.6:
219
+ return 0.25, over
220
+ if over > 0.3:
221
+ return 0.5, over
222
+ return 1.0, over
223
+
224
+
225
+ def predict(c: Dict[str, Any], factor: float, model: Optional[Dict[str, Any]] = None,
226
+ stars: Optional[float] = None) -> Dict[str, Any]:
227
+ acc_peer = max(80.0, min(100.0, statistics.median(c["accs"]) * factor))
228
+ n = len(c["users"])
229
+ own = acc_at(model, stars) if (model and stars) else None
230
+ if own is None:
231
+ acc = acc_peer
232
+ else:
233
+ w = n / (n + 2.0) # 樣本 1 人:1/3 信同水準玩家、2/3 信自己的趨勢
234
+ acc = w * acc_peer + (1 - w) * own
235
  miss = int(round(statistics.median(c["misses"])))
236
  mc = c.get("map_max_combo") or c.get("max_combo")
237
  if mc:
238
  ratio = statistics.median(min(1.0, x / mc) for x in c["combos"]) if c["combos"] else 0.9
239
  else:
240
  ratio = 0.9
241
+ return {"acc": acc, "acc_peer": acc_peer, "acc_own": own, "miss": miss,
242
+ "combo_ratio": max(0.3, min(1.0, ratio)), "n": n}
243
 
244
 
245
  # ── 校準:rosu vs 官方 pp ─────────────────────────────────────────
 
315
 
316
  # ── 逐張評估 ───────────────────────────────────────────────────────
317
  def evaluate(short: List[Dict[str, Any]], user_best: Dict[int, float], factor: float,
318
+ calc: CalcFn, profile: Optional[Dict[str, Any]] = None,
319
+ model: Optional[Dict[str, Any]] = None) -> List[Dict[str, Any]]:
320
  """預期 pp = P(FC)×FC 的 pp + (1−P(FC))×「掉主人常見 miss 數」的 pp。
321
+ P(FC) 來自主人自己的 top 成績;acc = 同水準玩家在這張圖的表現 × 主人 acc 係數,
322
+ 再跟主人自己「acc 對星數」的趨勢混合(樣本越少越信自己);星數用官方帶 mods 的值。
323
+ 比主人常打的難太多的圖排序打折(不是不列,是往後排並標出來)。"""
324
  prof = profile or {"p_fc": 1.0, "miss": 0, "combo_ratio": 0.9}
325
  out = []
326
  for c in short:
 
327
  miss = int(prof["miss"]) if prof["p_fc"] < 1.0 else 0
328
  try:
329
+ # 先用官方(帶 mods)星數算出 acc,再算 pp:星數只跟圖與 mods 有關,先問一次 FC 拿星數
330
+ probe = calc(c["beatmap_id"], c["mods"], 100.0, 0, None, c["lazer"])
331
+ p = predict(c, factor, model, probe["stars"])
332
  fc = calc(c["beatmap_id"], c["mods"], p["acc"], 0, None, c["lazer"])
333
  mc = fc["max_combo"]
334
  combo = max(1, int(round(mc * prof["combo_ratio"])))
 
340
  star_warn = (c["mods_key"] == "" and c.get("stars_api") and
341
  abs(fc["stars"] - c["stars_api"]) > STAR_TOL)
342
  gain = marginal_gain(user_best, c["beatmap_id"], exp_pp)
343
+ dfac, over = difficulty_factor(model or {}, fc["stars"])
344
+ out.append(dict(c, acc=p["acc"], acc_peer=p["acc_peer"], acc_own=p["acc_own"], miss=miss, n=p["n"],
345
+ combo=combo, p_fc=prof["p_fc"],
346
  stars=fc["stars"], max_combo=mc, fc_pp=fc["pp"], bad_pp=bad["pp"], exp_pp=exp_pp,
347
  gain=gain, gain_fc=marginal_gain(user_best, c["beatmap_id"], fc["pp"]),
348
+ rank_key=gain * confidence(p["n"]) * dfac, over_stars=over, hard=(dfac < 1.0),
349
  have_pp=user_best.get(c["beatmap_id"], 0.0), star_warn=bool(star_warn)))
350
  out.sort(key=lambda r: -(r.get("rank_key") or 0.0))
351
  return out
 
384
  return "\n".join(head + ["同水準玩家的圖你都已經有更高的 pp 了,或候選裡沒有符合 mods 篩選的圖。"])
385
  p_fc = rows[0].get("p_fc", 1.0)
386
  tail = ["-# 預期=FC 機率 %.0f%%(來自你的 top 成績)× FC 的 pp + 其餘 × 掉 %d miss 的 pp;"
387
+ "acc=同水準玩家在該圖的中位數 × 你的 acc 係數,再與你自己「acc 對星數」的趨勢混合(樣本越少越信你自己)。"
388
+ "排序=總 pp 增加 × 樣本信心 × 難度合理性(比你常打的難太多會往後排)。只列 ranked/approved。"
389
  % (p_fc * 100, rows[0].get("miss", 0))]
390
  lines: List[str] = []
391
  budget = 1950 - len("\n".join(head + tail)) - 2
392
  for i, r in enumerate(rows, 1):
393
+ hard = (" ⚠ 比你常打的難 +%.1f★" % r["over_stars"]) if r.get("hard") else ""
394
+ ln = ("**%d.** [%s - %s [%s]](https://osu.ppy.sh/b/%d) · **%s** · %.2f★ · 樣本 %d 人%s%s\n"
395
  " 預期 **%.0f pp** → 總 pp **+%.0f**(FC %.0f pp → +%.0f;acc %.1f%%%s)" % (
396
  i, r["artist"][:24], r["title"][:32], r["version"][:18], r["beatmap_id"],
397
  _mods_txt(r["mods_key"]), r["stars"], r["n"],
398
  "(⚠ 星數與官方差 %.2f)" % abs(r["stars"] - r["stars_api"]) if r.get("star_warn") else "",
399
+ hard, r["exp_pp"], r["gain"], r["fc_pp"], r["gain_fc"], r["acc"],
400
  (";你現有 %.0f pp" % r["have_pp"]) if r["have_pp"] else ""))
401
  if len(ln) + 1 > budget:
402
  break
 
578
  short = shortlist(cands, user_best, shortlist_n)
579
  factor = acc_factor(user_scores, peer_scores)
580
  prof = user_profile(user_scores)
581
+ model = acc_model(user_scores)
582
+ results = evaluate(short, user_best, factor, calc, prof, model)
583
+ log("[osu] 候選 %d、精算 %d、acc 係數 %.3f、FC 率 %.0f%%、非 FC 中位 miss %d、常打星數 p90 %s 最高 %s" % (
584
+ len(cands), len(short), factor, prof["p_fc"] * 100, prof["miss"],
585
+ ("%.2f" % model["p90"]) if model.get("p90") else "?", ("%.2f" % model["max"]) if model.get("max") else "?"))
586
  return format_report(uname, upp, results, calib, filt, len(peer_ids), top_n, engine, notes)