Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# 更新日志

## 0.1.6 · 2026-11-18

- 玩家概览标出胜率来自多少场,雷达区分实际胜率与赛果超预期;少量对局直接显示胜负场数。
- 近期战绩更容易逐场扫读,单局玩家改为分队表格。双方数据不全时不再绘制误导性的对比条。
- 修正部分兵种资料缺失导致整份评分消失的问题。图片开关、主题和发送方式移到常用设置顶部。

## 0.1.5 · 2026-11-18

- 玩家概览与近期战绩图片加宽,排版更紧凑,表格数字不再拆行。
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

AstrBot 原生《断箭》(Broken Arrow)战绩查询插件。以简洁排版展示玩家概览、近期战绩与单局核心数据,支持图片战报和默认账号绑定,不依赖大模型。

用 `ba me` 查看综合评分、称号和五维雷达图。图中的「胜负预期」衡量近期战果相对赛前预期的表现;「实际胜率」是近期已知胜负对局中获胜的比例。`ba recent` 查看逐局评分,`ba last` 查看最近一局的赛前预测、双方对比和玩家数据。
用 `ba me` 查看综合评分和五维表现。「实际胜率」是已知赛果中获胜的比例;「赛果超预期」则看对手强弱:同样十战五胜,赢下更多不被看好的对局,这项表现会更好。`ba recent` 查看逐局评分,`ba last` 对比双方队伍与玩家。

> 数据来源 [BATrace](https://dash.batrace.top/),如有帮助请支持该平台。更新内容见 [更新日志](CHANGELOG.md)。

Expand Down
6 changes: 3 additions & 3 deletions docs/API_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ SteamID64 与 STB ID 均保持字符串;**未找到可靠的 Steam→STB 映

`scoring.py` 使用 `assets/scoring-model.json`,移植 ba-dragon 固定提交的 `computeDragonScore`。近期战绩使用逐局分,不显示称号;玩家概览接收按时间从新到旧排列的对局,先跳过无效局,再取最多 20 场,将逐局标准分从旧到新输入 Kalman 滤波器,短局权重较低。再查 `playerPct` 得到 1–10 综合分,按显示分数及 `tiers` 给出称号;它不是单局显示分的平均值。1 场有效对局也可评分,`sample_size` 保留实际场数;0 场时综合分、称号和前四维均为 `None`。

五个雷达值均为 0–100。分值 K/D、摧毁贡献、占点贡献分别表示相对同条件玩家的表现百分位;占点不计入综合分。「胜负预期」是逐局 `phi((S-E)/outSd)` 的平均表现:`S` 采用上游模型内部的排位 ELO 涨跌,`E` 由双方赛前 ELO 和其他挂机者修正得出。前四项均按可用分项取平均后四舍五入为百分制整数。与上游缺失值回退不同,插件在缺少本人或在线队友占点时跳过该局的占点轴,缺少任何参战者所需的 ELO 或摧毁/损失价值时跳过整局。已归一化的真实零仍参与计算。
雷达的「交换效率」「摧毁贡献」「夺点表现」分别是相对同条件玩家的表现分;夺点次数不等于守点时长,也不计入综合分。「赛果超预期」取逐局 `phi((S-E)/outSd)` 的平均值。`S` 优先用该玩家、该对局明确的 `won`;明确记录互相矛盾则跳过该局。没有明确赛果时,模型仍可用 ELO 涨跌估计 `S`,但不据此给公开战绩补写胜负。`E` 由双方赛前 ELO 和其他挂机者修正得出。兵种花费中个别缺失的观测不覆盖同一份资料中有效的观测;没有可用花费时才采用模型总体基准。

第五维 `win_rate` 由服务层传入,仅统计近期样本中目标玩家有明确布尔 `won` 的对局。没有已知赛果时为 `None`,已知赛果全部为负时为 `0`;即使没有有效评分局,也可独立提供该轴。两种胜负指标不互相填补,评分本身不触发网络请求。
第五维「实际胜率」仅统计近期窗口中该玩家有明确赛果的不同对局;概览胜率则使用分析记录中的不同对局。两者都排除缺少对局 ID、没有明确赛果或赛果冲突的记录。图中区分评分有效场数与胜率分母,少于 5 场已知赛果时列出胜负数,不画该轴。模型没有同版本、同 ELO 段、同窗口的原始胜率分布,实际胜率按原始百分比显示,不套用总评分的分位表。近期伤害交换比只使用同场伤害与承伤均已知的记录,以总伤害除以总承伤;不以某场 `dmr` 代替近期结果。评分本身不触发网络请求。

`ba last` 的单局图片顶部展示基于双方赛前 ELO 的赛前预测及双队摘要;中部左侧兵种构成、右侧双方对比;底部展示队伍玩家数据。摘要区分赛前平均 ELO(`OldRating`)与赛后平均 ELO(`NewRating`)。预测是模型估算,不表示实际赛果。兵种构成按模型的单位角色与基础价格估算出动花费,缺少单位价格或记录时保留不完整说明,不冒充实际结算。
`ba last` 的单局图片顶部展示基于双方赛前 ELO 的胜率估算及队伍摘要;中部左侧兵种构成、右侧双方对比;底部按队列出玩家。正式队伍为 A/B,观战组不参与对比。两队人数不等,或详情缺少近期列表中已知的同队玩家时,不作预测、不画比例条;名单较完整的详情仍可用于比较。仅某项统计不全时,保留该项已知数字及覆盖人数,不画该项比例条。兵种构成按模型的单位角色与基础价格估算出动价值,不等于实际结算。

所有战报图片页脚内嵌 `assets/github-mark-black.svg` 或 `assets/github-mark-white.svg`,并包含 `timeance/astrbot_plugin_BA_stats` 与固定文字「数据来源 BATracer」。设置提示仍原样保留「数据来源 BATrace ,如有帮助请支持该平台」。

Expand Down
2 changes: 1 addition & 1 deletion docs/THIRD_PARTY.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

`scoring.py` 将固定提交中的 `src/shared/dragon/score.ts`、`roles.ts`、`model.ts` 相关逻辑移植为 Python;`assets/scoring-model.json` 从同一提交的 `src/shared/dragon/model.json` 提取评分参数,单位表仅保留角色和基础价格。模型内的 `source` 记录仓库、提交、来源文件和完整 MIT 文本。

玩家概览使用 `computeDragonScore` 的 Kalman 聚合、玩家分位表、分档和四个表现分项;分档称号取自 `src/renderer/src/features/players/PlayerDetail.tsx`。第五项「实际胜率」由插件服务根据明确的 `won` 计算并传入评分模块。近期战绩保持逐局评分。未移植单局奖项、时间线或实力 ELO;这些模型分数不代表官方评价。
玩家概览使用 `computeDragonScore` 的 Kalman 聚合、玩家分位表、分档和四个表现分项;分档称号取自 `src/renderer/src/features/players/PlayerDetail.tsx`。插件优先采用可核对的明确赛果计算赛果表现。第五项「实际胜率」仅使用明确的 `won`,按对局去重;没有套用上游综合评分的分位表。近期战绩保持逐局评分。未移植单局奖项、时间线或实力 ELO;这些模型分数不代表官方评价。

[BA_DRAGON_LICENSE.txt](BA_DRAGON_LICENSE.txt) 和模型的 `source.licenseText` 均原样保留固定提交的 `LICENSE`,包括 `Copyright (c) 2026 AlexanderHYu` 及 `Copyright (c) 2025-2026 Zola (Zawinzala)` 与原文件的沿用部分说明。分发这些移植代码或模型时,安装包、源码和 Gemini 文案包均应保留完整上游版权及 MIT 许可;文案润色不修改该文本。

Expand Down
6 changes: 4 additions & 2 deletions docs/VALIDATION.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# 验证记录

验证日期:2026-11-18(Asia/Hong_Kong)。版本:v0.1.5。
## v0.1.6 · 战绩与图片

## 本次结果
2026-11-18(Asia/Hong_Kong)。端到端样例覆盖明确胜负与 ELO 方向相反、重复赛果冲突、近期与分析样本分母不同、伤害数据部分缺失。浏览器检查手机聊天比例下的雷达、近期卡片、分队玩家表,以及两种主题的设置页。

## v0.1.5 验证结果

| 项目 | 结果 |
| --- | --- |
Expand Down
7 changes: 5 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
from .web_settings import SettingsError, WebSettings


PLUGIN_VERSION = "0.1.6"


def extract_arguments(event, prefixes):
"""Rebuild Plain/At components; keep quoted nickname spacing and true IDs."""
parts, mentions = [], []
Expand Down Expand Up @@ -155,7 +158,7 @@ async def initialize(self):
await self.storage.open()
self._images.mkdir(parents=True, exist_ok=True)
self._prune_images()
self.diagnostics.record("plugin_start", status="0.1.5")
self.diagnostics.record("plugin_start", status=PLUGIN_VERSION)

async def _run(self, awaitable, *, timed=True):
if self._closed:
Expand Down Expand Up @@ -309,7 +312,7 @@ async def _status(self):
"schema": "响应结构变化", "identity_mismatch": "身份校验失败",
"no_data": "暂无收录", "upstream": "上游暂不可用", "queue_full": "队列已满",
"not_configured": "接入未配置", "closed": "客户端已关闭", "daily_quota": "每日额度已用完"}
return (f"断箭战报 v0.1.5\n在线查询:{'已启用' if status['configured'] else '未启用或 API 地址无效'}\n"
return (f"断箭战报 v{PLUGIN_VERSION}\n在线查询:{'已启用' if status['configured'] else '未启用或 API 地址无效'}\n"
f"今日总请求:{usage['global']}/{GLOBAL_DAILY_LIMIT}(固定上限);北京时间 0 点重置\n"
f"本次运行请求:{status['requests']};进行中:{status['inflight']}\n"
f"API 缓存:{await self.storage.cache_count()} 条;命中:{status['cache_hits']};旧缓存:{status['stale_hits']}\n"
Expand Down
2 changes: 1 addition & 1 deletion metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: astrbot_plugin_ba_stats
display_name: 断箭战报
short_desc: "《断箭》战绩查询,支持玩家评分、五维雷达图与图片战报。"
desc: "查询《断箭》(Broken Arrow)玩家概览、近期战绩和单局战报,展示玩家评分、五维雷达图、逐局评分、赛前预测与双方对比,支持账号绑定、群友查询及图片或文字展示。在设置中心或原生插件配置中开启在线查询后使用。"
version: "0.1.5"
version: "0.1.6"
author: timeance
repo: https://github.com/timeance/astrbot_plugin_BA_stats
astrbot_version: ">=4.29.4"
Expand Down
41 changes: 40 additions & 1 deletion models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@

from __future__ import annotations

from collections.abc import Iterable, Mapping
from dataclasses import dataclass, field
from datetime import datetime
import math
from typing import Any, Generic, Literal, TypeVar
from urllib.parse import quote

Outcome = Literal["win", "loss", "unknown"]
AnalysisOutcome = Literal["win", "loss", "conflict"]
PROFILE_AXES = (("kd", "交换效率"), ("contrib", "摧毁贡献"), ("obj", "夺点表现"),
("outcome", "赛果超预期"), ("win_rate", "实际胜率"))
Mode = Literal["ranked", "custom", "unknown"]
T = TypeVar("T")

Expand Down Expand Up @@ -116,6 +120,33 @@ def canonical_id(value: Any) -> str:
return result


def analysis_outcomes(analysis: Mapping | None) -> dict[str, AnalysisOutcome]:
"""Resolve explicit results by exact match ID; absence is distinct from conflict."""
outcomes: dict[str, AnalysisOutcome] = {}
for point in (analysis or {}).get("trend", {}).get("points", []):
try:
mid = canonical_id(point.get("matchId"))
except ValueError:
continue
won = point.get("won")
if point.get("wonConflict") is True:
outcomes[mid] = "conflict"
elif isinstance(won, bool):
result = "win" if won else "loss"
outcomes[mid] = result if outcomes.get(mid, result) == result else "conflict"
return outcomes


def win_rate_sample(outcomes: Iterable[AnalysisOutcome]) -> dict:
wins = losses = 0
for outcome in outcomes:
wins += outcome == "win"
losses += outcome == "loss"
size = wins + losses
return {"value": 100 * wins / size if size else None,
"sample_size": size, "wins": wins, "losses": losses}


def _object(value: Any) -> dict[str, Any]:
if not isinstance(value, dict):
raise ValueError("expected an object")
Expand Down Expand Up @@ -207,10 +238,16 @@ def _parse_analysis(payload: Any) -> dict[str, Any]:
previous["endTime"] is None or point["endTime"] > previous["endTime"]
):
points[positions[mid]] = point
points[positions[mid]]["won"] = next(iter(outcomes)) if len(outcomes) == 1 else None
for mid, outcomes in results.items():
point = points[positions[mid]]
point["won"] = next(iter(outcomes)) if len(outcomes) == 1 else None
if len(outcomes) > 1:
point["wonConflict"] = True
units = []
for raw in _array(analysis, "highlightUnits"):
row = _object(raw)
if row.get("unitId") is None:
continue
units.append({
"unitId": canonical_id(row.get("unitId")),
"unitName": _name(row.get("unitName")) or None,
Expand All @@ -224,6 +261,8 @@ def _parse_analysis(payload: Any) -> dict[str, Any]:
categories = []
for raw in _array(analysis, "categoryPreferences"):
row = _object(raw)
if row.get("categoryKey") is None:
continue
categories.append({
"categoryKey": canonical_id(row.get("categoryKey")),
"percentage": _percentage(row.get("percentage")),
Expand Down
Loading
Loading