feat: add HTML report screenshot generation via Playwright
- Add html_report.py module for Playwright-based screenshot generation - Add generate_html_report() method to SimpleRotationStrategy - Modify backtest_viewer.html to use window-scoped variables for external injection - Inject monthly/yearly returns table into screenshot - Auto-generate HTML report in __main__ after export_results() Output: simple_rotation_html_report.png with ranking table + monthly returns
This commit is contained in:
@@ -1418,6 +1418,37 @@ class SimpleRotationStrategy:
|
||||
plt.close()
|
||||
print(f" + Report: {chart_path}")
|
||||
|
||||
def generate_html_report(self, output_dir: str = None, target_date: str = None):
|
||||
"""Generate HTML-based report screenshot using Playwright.
|
||||
|
||||
Renders backtest_viewer.html in headless Chromium and captures
|
||||
the ranking table + monthly returns as a PNG.
|
||||
|
||||
Args:
|
||||
output_dir: Directory to save the PNG (default: rotation/results)
|
||||
target_date: Date to navigate to (YYYY-MM-DD). None = last day.
|
||||
"""
|
||||
from rotation.html_report import generate_html_screenshot
|
||||
|
||||
if output_dir is None:
|
||||
output_dir = Path(__file__).parent / 'results'
|
||||
output_dir = Path(output_dir)
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
detail_path = output_dir / 'simple_rotation_detail.json'
|
||||
if not detail_path.exists():
|
||||
print(f" x Detail JSON not found: {detail_path}")
|
||||
print(" Run export_results() first.")
|
||||
return
|
||||
|
||||
output_path = output_dir / 'simple_rotation_html_report.png'
|
||||
generate_html_screenshot(
|
||||
detail_json_path=str(detail_path),
|
||||
output_path=str(output_path),
|
||||
target_date=target_date,
|
||||
daily_records=self.daily_records,
|
||||
)
|
||||
|
||||
|
||||
# ============================================================
|
||||
# Entry point
|
||||
@@ -1433,3 +1464,4 @@ if __name__ == "__main__":
|
||||
if result:
|
||||
strategy.export_results()
|
||||
strategy.generate_report()
|
||||
strategy.generate_html_report()
|
||||
|
||||
Reference in New Issue
Block a user