#!/usr/bin/env python3 # -*- coding: utf-8 -*- """作业 9 · 解析自测。""" from __future__ import annotations import json import sys import _bootstrap # noqa: F401 from 作业9_ppt_data import mom_from_daily, parse_langfuse_daily, simulated_langfuse from 作业9_build_html import render_html def main() -> int: raw = json.dumps( { "data": [ {"date": "2026-08-01", "countTraces": 10, "usage": [{"totalUsage": 1000}]}, {"date": "2026-08-08", "countTraces": 20, "usage": [{"totalUsage": 2000}]}, ] } ) got = parse_langfuse_daily(raw, days=14) assert got["total_traces"] == 30 mom = mom_from_daily(got["daily"]) assert mom["traces_wow_pct"] == 100.0 deck = { "title": "t", "org": "o", "period": "p", "presenter": "x", "core": { "total_requests": 1, "total_tokens": 2, "availability_pct": 99.9, "ttft_p99": 1.0, "full_p99": 6.0, "langfuse_source": "simulated", "sla_source": "simulated", "daily": simulated_langfuse(7)["daily"], "mom": mom, }, "business": {"cs_efficiency_pct": 32, "dev_efficiency_pct": 28, "kb_before_minutes": 15, "kb_after_seconds": 8}, "cost": {"saved_wan": 18, "quantize_pct": 40, "cache_pct": 35, "downgrade_pct": 25}, "next": {"goals": ["g"], "resources": ["r"], "risks": ["k"]}, } html = render_html(deck) assert "平台核心指标" in html and "业务价值" in html and "成本优化" in html and "下一步规划" in html print("[PASS] 作业9 解析自测") return 0 if __name__ == "__main__": sys.exit(main())