将 profile 记录扁平化
(record: Dict)
| 91 | |
| 92 | |
| 93 | def flatten_profile(record: Dict) -> Dict: |
| 94 | """将 profile 记录扁平化""" |
| 95 | profile_json = record.get("profile_json", {}) |
| 96 | |
| 97 | return { |
| 98 | "date": record.get("date", ""), |
| 99 | "user_id": record.get("user_id", ""), |
| 100 | "role_name": record.get("role_name", ""), |
| 101 | "version": record.get("version", ""), |
| 102 | "core_directions": json.dumps(profile_json.get("core_directions", {}), ensure_ascii=False), |
| 103 | "topic_weights": json.dumps(profile_json.get("topic_weights", {}), ensure_ascii=False), |
| 104 | "must_read_authors": json.dumps(profile_json.get("must_read", {}).get("authors", []), ensure_ascii=False), |
| 105 | "must_read_institutions": json.dumps(profile_json.get("must_read", {}).get("institutions", []), ensure_ascii=False), |
| 106 | "must_read_keywords": json.dumps(profile_json.get("must_read", {}).get("keywords", []), ensure_ascii=False), |
| 107 | "drift_status": profile_json.get("drift_state", {}).get("status", ""), |
| 108 | "drift_score": profile_json.get("drift_state", {}).get("score", 0), |
| 109 | "drift_top_topics": json.dumps(profile_json.get("drift_state", {}).get("top_shift_topics", []), ensure_ascii=False), |
| 110 | } |
| 111 | |
| 112 | |
| 113 | def flatten_episode(record: Dict) -> Dict: |