Skip to main content

HV Battle Intelligence Extractor: parse HentaiVerse battle HTML into structured Python dataclasses

Project description

HV-BIE(HV Battle Intelligence Extractor)

將 HentaiVerse 戰鬥頁面的 HTML 原始碼字串解析為結構化的 Python 資料類別(dataclasses)。

  • 支援環境:Python 3.13+
  • 主要相依:beautifulsoup4>=4.13.4
  • 套件名稱:hv_bie
  • 發佈名稱(PyPI):hv-bie;匯入名稱(Python):hv_bie

更多介面與資料模型細節,請參考:


功能一覽

依據 SRS 的功能需求(FR-1 ~ FR-7),本套件可從單一 HV 戰鬥頁面 HTML 中抽取:

  • 玩家資源(HP/MP/SP 百分比與數值、Overcharge 整數值)
  • 玩家 Buff/Debuff(名稱、剩餘時間或永久旗標)
  • 技能與法術清單(可用狀態、成本/冷卻若可推知)
  • 怪物清單(名稱、是否存活、資源百分比、系統怪物類型、怪物 Buff)
  • 戰鬥文字紀錄(由舊到新),含目前/總回合數(若頁面有顯示)
  • 道具與快捷列(名稱、槽位、可用狀態)

解析結果以單一「戰鬥快照」物件回傳,確保同一份 HTML 的各區塊資訊彼此一致。


安裝

可以透過 PyPI 安裝,或從原始碼安裝:

# 從 PyPI 安裝(若已發布)
pip install hv-bie

# 或在專案根目錄從原始碼安裝
pip install -e .

快速上手

from hv_bie import parse_snapshot
from hv_bie.types.models import BattleSnapshot
from pathlib import Path

# 讀取你的戰鬥頁面 HTML(字串)
html = Path("tests/fixtures/hv/The HentaiVerse.htm").read_text(encoding="utf-8")

snap: BattleSnapshot = parse_snapshot(html)

# 玩家資訊
print(snap.player.hp_value, snap.player.hp_percent)
print("Spirit Stance" in snap.player.buffs)

# 技能/法術
for name, sk in snap.abilities.skills.items():
 print(name, sk.available, sk.cost_type, sk.cost, sk.cooldown_turns)

# 怪物清單
for idx, m in snap.monsters.items():
 print(idx, m.name, m.alive, m.system_monster_type, m.hp_percent)

# 戰報(由舊到新)與回合資訊
print(snap.log.current_round, "/", snap.log.total_round)
print(snap.log.lines[0], "->", snap.log.lines[-1])

# 道具與快捷列
print("Health Draught" in snap.items.items)
print(len(snap.items.quickbar))

# 序列化
print(snap.as_dict())
print(snap.to_json())

公開 API(最小穩定面)

from hv_bie import parse_snapshot
from hv_bie.types import BattleSnapshot

def parse_snapshot(html: str) -> BattleSnapshot: ...
  • parse_snapshot(html: str) -> BattleSnapshot
    • 從單一戰鬥頁面 HTML 產生一次「戰鬥快照」。
    • 容錯:若頁面某區塊缺漏,不丟例外;以預設值補齊,並在 BattleSnapshot.warnings 累積文字告警。

更多說明請參考 API_SPEC.md


資料模型(概要)

主要 dataclasses 定義於 hv_bie/types/models.py,鍵名與型別視為穩定契約:

  • BattleSnapshot
    • player: PlayerState
    • abilities: AbilitiesState
    • monsters: dict[int, Monster]
    • log: CombatLog
    • items: ItemsState
    • warnings: list[str]
    • as_dict() -> dict / to_json() -> str
  • PlayerState:HP/MP/SP 百分比與數值、Overcharge 整數值、玩家 Buff
  • AbilitiesStateskills / spells(各為 dict[str, Ability]
  • Monster:插槽序號、名稱、是否存活、系統怪物類型、各資源百分比、Buff
  • CombatLoglines(由舊到新)、current_roundtotal_round
  • ItemsStateitems(道具字典)、quickbar(快捷列清單)

系統怪物對照可參考 hv_bie/types/system_monsters.py 提供的查詢輔助。


容錯與告警

  • 解析不會因缺漏 DOM 區塊而失敗;以預設值/空集合回傳。
  • 告警文字會累積於 BattleSnapshot.warnings(例如:"pane_vitals not found""table_skills not found")。
  • 呼叫端可依告警採取重試或記錄行為。

效能與非功能性

  • 目標(NFR-P1):在一般桌機上解析單頁應具互動式體驗(建議目標 ≲ 50ms,實測見 tests/perf/)。
  • 相依精簡:僅使用 BeautifulSoup(bs4)。
  • 安全:僅解析字串,不執行頁面腳本、不進行任何網路互動。

更多 NFR 請見 SRS.md


相容性

  • Python 3.13+
  • 作業系統不限(純 Python,OS Independent)

測試與驗證

本庫提供單元與整合測試,樣本 HTML 置於 tests/fixtures/hv/

# 執行測試
python -m pytest -q

重要測試:

  • 單元測試:tests/unit/test_parsers.py
  • 整合測試:tests/unit/test_snapshot_integration.py
  • 效能測試:tests/perf/test_nfr_p1_performance.py

版本與文件


LICENSE

本專案以 AGPL-3.0-or-later 授權釋出。詳見檔案:LICENSE

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hv_bie-0.4.1.tar.gz (25.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hv_bie-0.4.1-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

Details for the file hv_bie-0.4.1.tar.gz.

File metadata

  • Download URL: hv_bie-0.4.1.tar.gz
  • Upload date:
  • Size: 25.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hv_bie-0.4.1.tar.gz
Algorithm Hash digest
SHA256 b37d5305bcdb576b4e6e8929dec08e76e586070590fea014f00b10f97d4a32fc
MD5 1867460c20b95b132b02831758a40fa1
BLAKE2b-256 ba375977871dfee83650659561af97685363246118f2b9e6f51509a869680b01

See more details on using hashes here.

Provenance

The following attestation bundles were made for hv_bie-0.4.1.tar.gz:

Publisher: publish.yml on Kuan-Lun/hv-bie

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hv_bie-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: hv_bie-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hv_bie-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 582f7709844ce24a3c871e6deeb4e82de55d4fcafff4d055a18070e7af883df9
MD5 1ca8ec7c832f54e3edbbcef2fca7140f
BLAKE2b-256 8c29dc1e209cf6dbc505e526f71e3ab6aedda07cf470ed4e19514e3e60d046b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for hv_bie-0.4.1-py3-none-any.whl:

Publisher: publish.yml on Kuan-Lun/hv-bie

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page