Skip to main content

HV-BIE(HV Battle Intelligence Extractor)

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

  • 支援環境:Python 3.14
  • 主要相依:beautifulsoup4>=4.15.0
  • 套件名稱: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.14
  • 作業系統不限(純 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

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.7.3.tar.gz (671.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.7.3-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hv_bie-0.7.3.tar.gz
  • Upload date:
  • Size: 671.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for hv_bie-0.7.3.tar.gz
Algorithm Hash digest
SHA256 e5d257e9fdcba184d6ca2271562ddccfedc200b43a41b7ef7e1a4098abe37aea
MD5 1423fa6e53203f0eb9c920a8b78eaf46
BLAKE2b-256 a4a6d47119735d6345ebeace4b964613d654198e15127a405fd7ad69fe6be7c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for hv_bie-0.7.3.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.7.3-py3-none-any.whl.

File metadata

  • Download URL: hv_bie-0.7.3-py3-none-any.whl
  • Upload date:
  • Size: 23.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for hv_bie-0.7.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5ab5595d2806c65d4523de85c31785f0da466429f7e73a1be13a92b31d9d75fb
MD5 2b8e6779ba2227266d55c3734abb7add
BLAKE2b-256 5110ecac916f1e48cf8ca1e1a4fbe6f895df3cca70c5835eb94b91ff113dad36

See more details on using hashes here.

Provenance

The following attestation bundles were made for hv_bie-0.7.3-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.

Release history Release notifications | RSS feed

This release

0.7.3 This release

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.1

2 files

0.6.0

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.7

2 files

0.3.6

2 files

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page