功能:Web 前端与报告格式化(工作区中此前未提交的工作)
说明:本提交**不是本轮会话所做**,而是工作区里此前遗留的未提交改动。
为把历史分开,先单独提交它,再提交本轮会话的修改。
包含:
- Web 前端:web/index.html、web/app.js(统一 SPA,含回测/画像/Walk-forward 页面)
- 后端接口:web/server.py 路由、web/analysis.py(新增个股分析)
- 报告层:report/format.py(新增统一数字格式化 NumFmt)、
report/{backtest,profile,sensitivity,universe,walkforward}_report.py 接入 NumFmt、
report/renderer.py
- 股息率口径:factor/dividend_yield.py(毛刺消除 smooth_spikes)
- 筛选:universe/selector.py、universe/filters/dividend.py
- 绩效/敏感性:analysis/performance.py、analysis/sensitivity.py
- 部署:deploy/install-service.sh
- 测试:tests/test_format.py、tests/test_dividend_smoothing.py(新增)、
tests/test_web.py、tests/test_universe.py
提交时全量测试 403 项通过。
This commit is contained in:
@@ -9,6 +9,7 @@ from typing import Any
|
||||
import pandas as pd
|
||||
|
||||
from hdiv.core.config import config_hash, load_config
|
||||
from hdiv.report.format import NumFmt
|
||||
from hdiv.data import db
|
||||
from hdiv.data.repo import Repo
|
||||
from hdiv.report.renderer import Provenance, Renderer, query
|
||||
@@ -233,10 +234,16 @@ def _num(v: Any, dec: int = 2) -> str:
|
||||
return str(v)
|
||||
|
||||
|
||||
def _pct(v: Any, dec: int = 2) -> str:
|
||||
def _pct(v: Any, dec: int | None = None) -> str:
|
||||
"""百分比。``dec`` 显式给出时按其格式化,否则用配置的精度。
|
||||
|
||||
早期实现默认 dec=2 且从不读配置,于是 decimals.ratio 改了也没反应。
|
||||
"""
|
||||
if v is None or (isinstance(v, float) and v != v) or pd.isna(v):
|
||||
return "—"
|
||||
try:
|
||||
if dec is None:
|
||||
return NumFmt.from_config().pct(v)
|
||||
return f"{float(v) * 100:.{dec}f}%"
|
||||
except (TypeError, ValueError):
|
||||
return str(v)
|
||||
|
||||
Reference in New Issue
Block a user