Format profile for display
(profile: dict)
| 19 | |
| 20 | |
| 21 | def format_profile(profile: dict) -> str: |
| 22 | """Format profile for display""" |
| 23 | |
| 24 | lines = [] |
| 25 | lines.append("=" * 60) |
| 26 | lines.append("你的学术画像") |
| 27 | lines.append("=" * 60) |
| 28 | lines.append(f"User ID: {profile['user_id']}") |
| 29 | lines.append(f"Version: {profile['version']}") |
| 30 | lines.append(f"Updated: {profile.get('updated_at', 'N/A')}") |
| 31 | lines.append("") |
| 32 | |
| 33 | # Core directions |
| 34 | lines.append("--- 核心方向 ---") |
| 35 | for direction, weight in profile.get('core_directions', {}).items(): |
| 36 | bar_len = int(weight * 20) |
| 37 | bar = "#" * bar_len + "-" * (20 - bar_len) |
| 38 | lines.append(f"{direction:40} {bar} {weight:.2f}") |
| 39 | lines.append("") |
| 40 | |
| 41 | # Methodology preferences |
| 42 | lines.append("--- 方法论偏好 ---") |
| 43 | prefs = profile.get('methodology_preferences', {}) |
| 44 | pref_labels = { |
| 45 | 'preference_data_driven_over_theory': '数据驱动 > 纯理论', |
| 46 | 'preference_systematic_work_over_incremental': '系统性工作 > 单点改进', |
| 47 | 'preference_open_source_code': '有开源代码', |
| 48 | 'preference_multimodal_application': '多模态应用场景' |
| 49 | } |
| 50 | for key, label in pref_labels.items(): |
| 51 | status = "Y" if prefs.get(key, False) else " " |
| 52 | lines.append(f" [{status}] {label}") |
| 53 | lines.append("") |
| 54 | |
| 55 | # Must read |
| 56 | lines.append("--- 必读清单 ---") |
| 57 | must_read = profile.get('must_read', {}) |
| 58 | |
| 59 | authors = must_read.get('authors', []) |
| 60 | if authors: |
| 61 | lines.append(f"作者:{', '.join(authors)}") |
| 62 | else: |
| 63 | lines.append("作者:(空)") |
| 64 | |
| 65 | institutions = must_read.get('institutions', []) |
| 66 | if institutions: |
| 67 | lines.append(f"机构:{', '.join(institutions)}") |
| 68 | else: |
| 69 | lines.append("机构:(空)") |
| 70 | |
| 71 | keywords = must_read.get('keywords', []) |
| 72 | if keywords: |
| 73 | lines.append(f"关键词:{', '.join(keywords)}") |
| 74 | else: |
| 75 | lines.append("关键词:(空)") |
| 76 | lines.append("") |
| 77 | |
| 78 | # Topic weights |