refactor(statistic): decouple statistics collection from report generation

Introduces a dedicated `HTMLReportGenerator` class in `report_generator.py` to handle all aspects of HTML and chart rendering. This decouples the report presentation logic from the data collection process within `StatisticOutputTask`.

Key changes include:
- Migrated all HTML and JavaScript generation into the new `HTMLReportGenerator`.
- Extracted all statistic key constants into a separate `statistic_keys.py` file for improved organization.
- Renamed `_generate_chart_data` to `_collect_chart_data` to better reflect its purpose.
- Improved data handling robustness by using `.get()` for dictionary access and safely handling database query results.
This commit is contained in:
minecraft1024a
2025-11-12 20:34:36 +08:00
parent 61d86875ad
commit 6ef1829072
5 changed files with 429 additions and 680 deletions

View File

@@ -21,6 +21,10 @@ class LocalStoreManager:
self.store = {}
self.load_local_store()
def __contains__(self, key: str) -> bool:
"""检查键是否存在"""
return key in self.store
def __getitem__(self, item: str) -> str | list | dict | int | float | bool | None:
"""获取本地存储数据"""
return self.store.get(item)
@@ -38,9 +42,9 @@ class LocalStoreManager:
else:
logger.warning(f"尝试删除不存在的键: {key}")
def __contains__(self, item: str) -> bool:
"""检查本地存储数据是否存在"""
return item in self.store
def get(self, key: str, default=None):
"""获取本地存储数据,支持默认值"""
return self.store.get(key, default)
def load_local_store(self):
"""加载本地存储数据"""