Render the profile using the PDF-style section layout.
(profile: Dict[str, Any])
| 282 | |
| 283 | |
| 284 | def format_profile_message(profile: Dict[str, Any]) -> str: |
| 285 | """Render the profile using the PDF-style section layout.""" |
| 286 | version = profile.get("version", "0.1") |
| 287 | reading_history = profile.get("reading_history", []) |
| 288 | stage = "持续学习" if reading_history else "冷启动" |
| 289 | |
| 290 | lines = [f"📋 你的学术画像(v{version} - {stage})", ""] |
| 291 | |
| 292 | lines.append("━━━ 核心方向 ━━━") |
| 293 | core_directions = profile.get("core_directions", {}) or {} |
| 294 | if core_directions: |
| 295 | for direction, weight in sorted(core_directions.items(), key=lambda item: -item[1]): |
| 296 | label = format_direction_label(direction) |
| 297 | normalized_weight = max(0.0, min(float(weight), 1.0)) |
| 298 | bar_length = max(1, int(round(normalized_weight * 10))) |
| 299 | bar = "█" * bar_length + "░" * (10 - bar_length) |
| 300 | lines.append(f"{label} [{bar}] 权重:{normalized_weight:.2f}") |
| 301 | else: |
| 302 | lines.append("(当前还没有稳定的方向标签,建议补一句研究方向或重新冷启动)") |
| 303 | lines.append("") |
| 304 | |
| 305 | lines.append("━━━ 方法论偏好 ━━━") |
| 306 | method_prefs = profile.get("methodology_preferences", {}) or {} |
| 307 | if method_prefs: |
| 308 | data_pref = method_prefs.get("preference_data_driven_over_theory") |
| 309 | if data_pref is True: |
| 310 | lines.append("├── 偏好数据驱动 > 纯理论") |
| 311 | elif data_pref is False: |
| 312 | lines.append("├── 偏好纯理论 > 数据驱动") |
| 313 | else: |
| 314 | lines.append("├── 数据驱动 / 纯理论:暂无明确信号") |
| 315 | |
| 316 | systematic_pref = method_prefs.get("preference_systematic_work_over_incremental") |
| 317 | if systematic_pref is True: |
| 318 | lines.append("├── 偏好系统性工作 > 单点改进") |
| 319 | elif systematic_pref is False: |
| 320 | lines.append("├── 偏好单点改进 > 系统性工作") |
| 321 | else: |
| 322 | lines.append("├── 系统性工作 / 单点改进:暂无明确信号") |
| 323 | |
| 324 | lines.append( |
| 325 | "├── 偏好有开源代码的工作" |
| 326 | if method_prefs.get("preference_open_source_code") |
| 327 | else "├── 对开源代码暂无明显偏好" |
| 328 | ) |
| 329 | lines.append( |
| 330 | "└── 偏好有生物/科学应用场景的工作" |
| 331 | if method_prefs.get("preference_bio_science_application") |
| 332 | else "└── 当前偏向通用研究场景" |
| 333 | ) |
| 334 | else: |
| 335 | lines.append("(暂无方法论偏好信号)") |
| 336 | lines.append("") |
| 337 | |
| 338 | lines.append("━━━ 必读清单 ━━━") |
| 339 | must_read = profile.get("must_read", {}) or {} |
| 340 | lines.append(f"作者:{', '.join(must_read.get('authors', [])) or '(空,待你添加)'}") |
| 341 | lines.append(f"机构:{', '.join(must_read.get('institutions', [])) or '(空,待你添加)'}") |
no test coverage detected