Format the weekly report card with a drift-awareness section.
(report: Dict)
| 492 | |
| 493 | def format_report_card(report: Dict) -> str: |
| 494 | """Format the weekly report card with a drift-awareness section.""" |
| 495 | lines = [] |
| 496 | lines.append("=" * 60) |
| 497 | lines.append(f"📋 你的学术画像周度报告 | {report.get('period', 'N/A')}") |
| 498 | lines.append("=" * 60) |
| 499 | lines.append("") |
| 500 | |
| 501 | drift_summary = report.get("drift_summary", {}) |
| 502 | if drift_summary: |
| 503 | lines.append("━━━ 兴趣迁移状态 ━━━") |
| 504 | lines.append(f"当前状态:{drift_summary.get('status_label', '稳定')}") |
| 505 | lines.append(f"本周最高漂移分数:{drift_summary.get('max_score', 0.0):.2f}") |
| 506 | if drift_summary.get("detected_at"): |
| 507 | lines.append(f"最近一次检测时间:{drift_summary.get('detected_at')}") |
| 508 | if drift_summary.get("top_shift_topics"): |
| 509 | topic_labels = [translate_direction(topic) for topic in drift_summary.get("top_shift_topics", [])[:3]] |
| 510 | lines.append(f"最近漂移主题:{', '.join(topic_labels)}") |
| 511 | lines.append(f"更新器解释:{drift_summary.get('explanation', '')}") |
| 512 | lines.append("") |
| 513 | |
| 514 | direction_changes = report.get("direction_changes", []) |
| 515 | if direction_changes: |
| 516 | lines.append("━━━ 方向权重变化 ━━━") |
| 517 | for change in direction_changes[:7]: |
| 518 | direction_cn = translate_direction(change["direction"]) |
| 519 | current = change["current_weight"] |
| 520 | previous = change["previous_weight"] |
| 521 | delta = change["delta"] |
| 522 | trend = change["trend"] |
| 523 | bar_len = int(current * 20) |
| 524 | bar = "█" * bar_len + "░" * (20 - bar_len) |
| 525 | if trend == "up": |
| 526 | trend_str = f"{previous:.2f} → {current:.2f}" |
| 527 | elif trend == "down": |
| 528 | trend_str = f"{previous:.2f} → {current:.2f}" |
| 529 | else: |
| 530 | trend_str = "不变" |
| 531 | if previous == 0 and current > 0: |
| 532 | lines.append(f"【新增】{direction_cn} [{bar}] {current:.2f} → 新出现的兴趣") |
| 533 | else: |
| 534 | text = f"{direction_cn} [{bar}] {current:.2f} ({trend_str})" |
| 535 | if trend == "down" and delta < -0.05: |
| 536 | text += " → 权重下降" |
| 537 | lines.append(text) |
| 538 | lines.append("") |
| 539 | |
| 540 | stats = report.get("stats", {}) |
| 541 | lines.append("━━━ 本周阅读统计 ━━━") |
| 542 | lines.append(f"推送论文总数:{stats.get('total', 0)}") |
| 543 | lines.append(f"你选择精读:{stats.get('selected', 0)}(选择率 {stats.get('selection_rate', 0):.1%})") |
| 544 | doc_engagement = report.get("doc_engagement", {}) or {} |
| 545 | if doc_engagement.get("total_doc_opens"): |
| 546 | lines.append( |
| 547 | f"精读文档打开:{doc_engagement.get('total_doc_opens', 0)} 次" |
| 548 | f"(去重后 {doc_engagement.get('unique_doc_opens', 0)} 篇)" |
| 549 | ) |
| 550 | if doc_engagement.get("dwell_proxy_count"): |
| 551 | lines.append( |
no test coverage detected