feat: add daily commission history for Web 2.0.8

This commit is contained in:
AttilaNet
2026-11-13 09:59:43 +08:00
parent ad25d5b403
commit 296653d8d3
25 changed files with 2179 additions and 96 deletions
+101 -9
View File
@@ -13,6 +13,7 @@ from ranch_assistant.drop_statistics import analyze
from ranch_assistant.presentation import monster_rows
from ranch_assistant.battle_messages import battle_message
from ranch_assistant.resource_stages import available_item_count, item_requirements, with_resource_data
from ranch_assistant.quests import commission_priority, commission_selection
from .policies import default_config, validate_config
@@ -126,7 +127,10 @@ def build_view(engine, page, config, query=None):
"form": [field | {"value": _value(config, field["path"])} for field in fields],
"filters": [], "details": {}, "actions": [{"operation": "refresh", "label": "刷新本页", "payload": {"page": page}}]}
builder = _BUILDERS.get(page)
if engine.snapshot is None and page not in ("login", "yields", "statistics"):
if page == "commissions":
dto["tabs"] = [{"key": "current", "title": "当前委托"}, {"key": "history", "title": "每日记录"}]
local_history = page == "commissions" and (query or {}).get("tab") == "history"
if engine.snapshot is None and page not in ("login", "yields", "statistics") and not local_history:
dto["summary"] = "请先登录或打开离线演示"
return dto
if builder is not None:
@@ -562,33 +566,121 @@ def _battles(dto, engine, config, query):
dto["actions"] = [{"operation": "refresh_tasks", "label": "刷新战斗记录", "payload": {}}]
COMMISSION_STATES = {"accepted": "已接取", "active": "进行中", "in_progress": "进行中", "completed": "已完成", "pending": "等待核对",
"claimed": "已领奖", "confirmed": "已确认", "unknown": "结果待核对", "failed": "失败", "cancelled": "已取消", "observed": "仅观察到任务", "blocked": "等待条件"}
COMMISSION_EVENTS = {"accept": "接取", "step": "推进步骤", "claim": "领取奖励", "complete": "领取奖励", "dialogue": "对话", "battle": "战斗",
"navigate": "前往任务地点", "farm": "收集委托材料", "local_step": "步骤收尾", "reset": "刷新每日委托",
"handin": "交付", "handin_items": "提交道具", "handin_monsters": "提交魔物", "handin_money": "提交金币",
"quest_accept": "接取", "quest_step": "推进步骤", "quest_complete": "领取奖励", "observe": "观察到任务"}
def _commission_time(value):
if value is None or value == "":
return "—"
try:
if type(value) in (int, float):
stamp = datetime.fromtimestamp(value / 1000 if value >= 1e12 else value, CHINA_TIME)
elif isinstance(value, str):
stamp = datetime.fromisoformat(value.replace("Z", "+00:00"))
if stamp.tzinfo is None:
stamp = stamp.replace(tzinfo=CHINA_TIME)
else:
return "—"
return stamp.astimezone(CHINA_TIME).strftime("%Y-%m-%d %H:%M:%S")
except (ValueError, OverflowError, OSError):
return "时间未确认"
def _commission_history(dto, engine, query):
selected = query.get("date") or datetime.now(CHINA_TIME).date().isoformat()
try:
if not isinstance(selected, str) or datetime.strptime(selected, "%Y-%m-%d").date().isoformat() != selected:
raise ValueError
except (TypeError, ValueError):
raise ValueError("记录日期须为 YYYY-MM-DD") from None
history = engine.commission_history(day=selected)
totals = history.get("summary") or {}
dto["form"] = []
dto["actions"] = [{"operation": "reload_view", "label": "刷新记录"}]
dto["filters"] = [_filter("date", "记录日期(北京时间)", selected, kind="date")]
search = _search(dto, query)
dto["columns"] = [_column(key, label) for key, label in (("name", "委托"), ("status_label", "状态"),
("expected_ke", "预计氪金"), ("confirmed_ke", "已确认氪金"), ("accepted_at", "接取时间(北京时间)"),
("completed_at", "完成时间(北京时间)"), ("last_action", "最近行动"))]
sources = history.get("rows") or []
for index, source in enumerate(sources):
status = _text(source.get("status"), "unknown")
row = {"id": _text(source.get("id"), str(index)), "task_type_id": _text(source.get("task_type_id")),
"name": _text(source.get("name")), "status_label": COMMISSION_STATES.get(status, "结果待核对"),
"expected_ke": source.get("expected_ke") if type(source.get("expected_ke")) in (int, float) else "未记录",
"confirmed_ke": source.get("confirmed_ke") if type(source.get("confirmed_ke")) in (int, float) else "未确认",
"accepted_at": _commission_time(source.get("accepted_at")), "completed_at": _commission_time(source.get("completed_at")),
"last_action": _text(source.get("last_action"), "暂无行动记录")}
events = []
for event in source.get("events") or []:
kind, outcome = _text(event.get("kind"), "unknown"), _text(event.get("status"), "unknown")
label = {"success": "已确认", "succeeded": "已确认", "confirmed": "已确认", "completed": "已确认",
"failed": "失败", "unknown": "结果待核对", "pending": "等待核对", "cancelled": "已取消"}.get(outcome, "结果待核对")
events.append(f"{_commission_time(event.get('time'))} · {COMMISSION_EVENTS.get(kind, '委托行动')} · {label} · {_text(event.get('description'))}")
detail = {"委托": row["name"], "任务编号": row["task_type_id"], "状态": row["status_label"],
"预计氪金": row["expected_ke"], "已确认氪金": row["confirmed_ke"], "接取时间(北京时间)": row["accepted_at"],
"完成时间(北京时间)": row["completed_at"], "选择 / 回退原因": _text(source.get("selection_reason"), "未记录"),
"行动记录": "\n".join(events) or "暂无行动记录"}
if search and search not in " ".join(map(str, [*row.values(), *detail.values()])).casefold():
continue
dto["rows"].append(row)
dto["details"][row["id"]] = detail
dto["summary"] = (f"{selected} · 已记录接取 {totals.get('accepted_count', 0)} · 已记录完成 {totals.get('completed_count', 0)}"
f" · 当日领奖确认氪金 {totals.get('confirmed_ke', 0)} · 当日接取标注氪金 {totals.get('expected_ke', 0)}"
f" · 操作待核对 {totals.get('pending_count', 0)} · 领奖金额未记录 {totals.get('unknown_reward_count', 0)}")
dto["summary"] += ";仅有本地已保存记录" if sources else ";当日暂无本地记录,历史接取与奖励未追溯"
if history.get("error"):
dto["summary"] += ";" + _text(history["error"])
def _commissions(dto, engine, config, query):
if query.get("tab") == "history":
_commission_history(dto, engine, query)
return
snapshot, catalog = engine.snapshot, engine.catalog
search = _search(dto, query)
dto["columns"] = [_column(key, label) for key, label in (("task_type_id", "编号"), ("name", "委托"), ("status", "状态"),
("reward_money", "金币奖励"), ("reward_ke", "氪金奖励"), ("reason", "需求 / 下一步 / 阻塞原因"))]
dto["columns"] = [_column(key, label) for key, label in (("task_type_id", "编号"), ("name", "委托"), ("city", "城市"), ("status", "状态"),
("reward_money", "标注金币"), ("reward_ke", "标注氪金"), ("selection_reason", "选择 / 回退原因"), ("reason", "需求 / 下一步 / 阻塞原因"))]
diagnostics = {str(row.get("task_type_id")): row for row in engine.progression_rows() if _category(row.get("category")) == "commission"}
source = engine.tasks.rows(snapshot, engine.quest_policy, engine.policy)
offer_rows = engine.commission_offer_diagnostics()
offers = {(str(row.get("task_type_id")), str(row.get("city"))): row for row in offer_rows}
selected = next((row for row in offer_rows if row.get("eligible") is True), {})
selection = commission_selection({"reward": {"ke": selected.get("expected_ke", 0)}}, offer_rows,
[row for row in offer_rows if row.get("eligible") is False]) if selected else {}
source = sorted(engine.tasks.rows(snapshot, engine.quest_policy, engine.policy), key=lambda row: (
"city" in row[4], commission_priority(catalog.data.get("task_info", {}).get(str(row[0]), {}))))
for index, (key, name, status, text, meta) in enumerate(source):
diagnostic = diagnostics.get(str(key), {})
reason = diagnostic.get("block_reason") or diagnostic.get("blocked_reason")
offer = offers.get((str(key), str(meta.get("city"))), {}) if "city" in meta else {}
if "city" in meta:
status = "可接取" if offer.get("eligible") is True else "候选 / 条件待核对"
reason = (offer.get("reason") if offer.get("eligible") is False else None) if offer else diagnostic.get("block_reason") or diagnostic.get("blocked_reason")
if reason:
status = "暂不接取" if "city" in meta else "等待条件"
text = reason
elif diagnostic.get("next_action"):
elif not offer and diagnostic.get("next_action"):
text = diagnostic["next_action"]
info = catalog.data.get("task_info", {}).get(str(key), {})
reward = info.get("reward") or {}
row = {"id": f"{key}:{index}", "task_type_id": str(key), "name": name, "status": status,
"reward_money": reward.get("money", 0), "reward_ke": reward.get("ke", 0), "reason": battle_message(text),
"city": meta.get("city"), "active": "city" not in meta}
"city": meta.get("city"), "active": "city" not in meta,
"selection_reason": _text(offer.get("selection_reason") or (selection.get("selection_reason") if offer and offer == selected else None)
or diagnostic.get("selection_reason") or meta.get("selection_reason") or (reason if "city" in meta else None),
"较高氪金的可执行委托优先" if offer.get("eligible") is True else "接取条件待核对" if "city" in meta else "已接取,优先推进当前委托")}
if search and search not in " ".join(map(str, row.values())).casefold():
continue
dto["rows"].append(row)
dto["details"][row["id"]] = {"描述": info.get("des", ""), "需求 / 下一步": row["reason"],
dto["details"][row["id"]] = {"描述": info.get("des", ""), "标注奖励": reward_summary(catalog, reward),
"城市": _text(meta.get("city")), "选择 / 回退原因": row["selection_reason"], "需求 / 下一步": row["reason"],
"交付限制": {"允许物品": engine.quest_policy.allow_items, "允许魔物": engine.quest_policy.allow_monsters,
"单次金币上限": engine.quest_policy.max_money, "允许已支持战斗": engine.quest_policy.battle_tasks},
"接取优先级": "氪金奖励较高的委托优先;仅接取原规划器确认可支持的委托"}
"接取优先级": "跨城市按标注氪金 20 → 15 → 10 优先;20 氪金均不可用时回退到可执行的 15 / 10 氪金委托"}
dto["summary"] = f"今日剩余可接次数:{snapshot.raw.get('history', {}).get('loopTaskNum', '未知')};当前委托:{len(engine.tasks.current(snapshot))}"