feat: 实现用户画像、占卜历史与后端用户管理模块

This commit is contained in:
ZL-Q
2026-04-06 01:28:10 +08:00
parent d87b2e1e3a
commit 8a18b3528b
77 changed files with 5850 additions and 2604 deletions
+13 -4
View File
@@ -135,6 +135,7 @@ class SqlAlchemyEventStore:
"result_type",
"suggested_actions",
"error",
"divination_derived",
"ui_hints",
)
worker_output_payload: dict[str, object] = {}
@@ -187,7 +188,9 @@ class SqlAlchemyEventStore:
content=content,
model_code=model_code if isinstance(model_code, str) else None,
tool_name=tool_name_value,
metadata=metadata_model.model_dump(mode="json", exclude_none=True),
metadata=metadata_model.model_dump(
mode="json", by_alias=True, exclude_none=True
),
input_tokens=input_tokens,
output_tokens=output_tokens,
cost=cost,
@@ -200,7 +203,9 @@ class SqlAlchemyEventStore:
visibility_mask=visibility_mask,
role=role.value,
content=content,
metadata=metadata_model.model_dump(mode="json", exclude_none=True),
metadata=metadata_model.model_dump(
mode="json", by_alias=True, exclude_none=True
),
timestamp=self._resolve_message_timestamp(persisted),
)
@@ -272,7 +277,9 @@ class SqlAlchemyEventStore:
role=AgentChatMessageRole.TOOL,
content=content,
tool_name=tool_output.tool_name,
metadata=metadata_model.model_dump(mode="json", exclude_none=True),
metadata=metadata_model.model_dump(
mode="json", by_alias=True, exclude_none=True
),
visibility_mask=visibility_mask,
)
await self._append_context_cache_message(
@@ -281,7 +288,9 @@ class SqlAlchemyEventStore:
visibility_mask=visibility_mask,
role=AgentChatMessageRole.TOOL.value,
content=content,
metadata=metadata_model.model_dump(mode="json", exclude_none=True),
metadata=metadata_model.model_dump(
mode="json", by_alias=True, exclude_none=True
),
timestamp=self._resolve_message_timestamp(persisted),
)
@@ -60,7 +60,7 @@ def _worker_rules(llm_config: SystemAgentLLMConfig | None) -> list[str]:
"[六爻分析流程]",
"- 第1步:准确复述用户问题,确认问题类型与诉求焦点。",
"- 第2步:围绕用神、世应、动爻、月建日辰、旺衰关系形成核心判断。",
"- 第3步:给出签级,仅允许 上上签 / 中上签 / 中下签。",
"- 第3步:给出签级,仅允许 上上签 / 中上签 / 中下签 / 下下签",
"- 第4步:输出结论与重点,解释外部阻力或有利转机出现条件。",
"- 第5步:给出可执行建议,避免空泛正确话。",
"- 第6步:提炼关键词,优先四字表达,简洁且可复述。",
@@ -232,8 +232,10 @@ class AgentScopeRunner:
pipeline=pipeline,
runtime_client_time=runtime_client_time,
runtime_mode=runtime_mode,
derived_divination=derived_divination,
)
worker_output = worker_output_model.model_validate(worker_result.payload)
worker_output.divination_derived = derived_divination
await self._emit_step_event(
pipeline=pipeline,
run_input=run_input,
@@ -255,6 +257,7 @@ class AgentScopeRunner:
pipeline: PipelineLike,
runtime_client_time: ClientTimeContext | None,
runtime_mode: RuntimeMode,
derived_divination: DerivedDivinationData,
) -> StageExecutionResult:
tracking_model = self._build_model(stage_config=stage_config)
formatter = OpenAIChatFormatter()
@@ -290,7 +293,12 @@ class AgentScopeRunner:
usage_summary=tracking_model.usage_summary(),
)
await emitter.emit_final_text_end(
worker_output=worker_payload.model_dump(mode="json", exclude_none=True),
worker_output={
**worker_payload.model_dump(mode="json", exclude_none=True),
"divination_derived": derived_divination.model_dump(
mode="json", by_alias=True, exclude_none=True
),
},
response_metadata=response_metadata,
)
return StageExecutionResult(
@@ -70,6 +70,7 @@ class PipelineStageEmitter:
"suggested_actions": worker_output.get("suggested_actions")
or worker_output.get("advice", []),
"error": worker_output.get("error"),
"divination_derived": worker_output.get("divination_derived"),
**response_metadata,
}
ui_hints = worker_output.get("ui_hints")
@@ -0,0 +1,962 @@
{
"111111": {
"name": "乾为天",
"binary": "111111",
"upper_name": "乾",
"lower_name": "乾",
"yao_relations": ["子孙", "妻财", "父母", "官鬼", "兄弟", "父母"],
"yao_tigan": ["子", "寅", "辰", "午", "申", "戌"],
"yao_elements": ["水", "木", "土", "火", "金", "土"],
"world_position": 6,
"response_position": 3,
"fushen_positions": [],
"fushen_relations": [],
"fushen_tigan": [],
"fushen_elements": []
},
"011111": {
"name": "天风姤",
"binary": "011111",
"upper_name": "乾",
"lower_name": "巽",
"yao_relations": ["父母", "子孙", "兄弟", "官鬼", "兄弟", "父母"],
"yao_tigan": ["丑", "亥", "酉", "午", "申", "戌"],
"yao_elements": ["土", "水", "金", "火", "金", "土"],
"world_position": 1,
"response_position": 4,
"fushen_positions": [1],
"fushen_relations": ["妻财"],
"fushen_tigan": ["寅"],
"fushen_elements": ["木"]
},
"001111": {
"name": "天山遁",
"binary": "001111",
"upper_name": "乾",
"lower_name": "艮",
"yao_relations": ["父母", "官鬼", "兄弟", "官鬼", "兄弟", "父母"],
"yao_tigan": ["辰", "午", "申", "午", "申", "戌"],
"yao_elements": ["土", "火", "金", "火", "金", "土"],
"world_position": 2,
"response_position": 5,
"fushen_positions": [0, 1],
"fushen_relations": ["子孙", "妻财"],
"fushen_tigan": ["子", "寅"],
"fushen_elements": ["水", "木"]
},
"000111": {
"name": "天地否",
"binary": "000111",
"upper_name": "乾",
"lower_name": "坤",
"yao_relations": ["父母", "官鬼", "妻财", "官鬼", "兄弟", "父母"],
"yao_tigan": ["未", "巳", "卯", "午", "申", "戌"],
"yao_elements": ["土", "火", "木", "火", "金", "土"],
"world_position": 3,
"response_position": 6,
"fushen_positions": [0],
"fushen_relations": ["子孙"],
"fushen_tigan": ["子"],
"fushen_elements": ["水"]
},
"000011": {
"name": "风地观",
"binary": "000011",
"upper_name": "巽",
"lower_name": "坤",
"yao_relations": ["父母", "官鬼", "妻财", "父母", "官鬼", "妻财"],
"yao_tigan": ["未", "巳", "卯", "未", "巳", "卯"],
"yao_elements": ["土", "火", "木", "土", "火", "木"],
"world_position": 4,
"response_position": 1,
"fushen_positions": [0, 4],
"fushen_relations": ["子孙", "兄弟"],
"fushen_tigan": ["子", "申"],
"fushen_elements": ["水", "金"]
},
"000001": {
"name": "山地剥",
"binary": "000001",
"upper_name": "艮",
"lower_name": "坤",
"yao_relations": ["父母", "官鬼", "妻财", "父母", "子孙", "妻财"],
"yao_tigan": ["未", "巳", "卯", "戌", "子", "寅"],
"yao_elements": ["土", "火", "木", "土", "水", "木"],
"world_position": 5,
"response_position": 2,
"fushen_positions": [4],
"fushen_relations": ["兄弟"],
"fushen_tigan": ["申"],
"fushen_elements": ["金"]
},
"000101": {
"name": "火地晋",
"binary": "000101",
"upper_name": "离",
"lower_name": "坤",
"yao_relations": ["父母", "官鬼", "妻财", "兄弟", "父母", "官鬼"],
"yao_tigan": ["未", "巳", "卯", "酉", "未", "巳"],
"yao_elements": ["土", "火", "木", "金", "土", "火"],
"world_position": 4,
"response_position": 1,
"fushen_positions": [0],
"fushen_relations": ["子孙"],
"fushen_tigan": ["子"],
"fushen_elements": ["水"]
},
"111101": {
"name": "火天大有",
"binary": "111101",
"upper_name": "离",
"lower_name": "乾",
"yao_relations": ["子孙", "妻财", "父母", "兄弟", "父母", "官鬼"],
"yao_tigan": ["子", "寅", "辰", "酉", "未", "巳"],
"yao_elements": ["水", "木", "土", "金", "土", "火"],
"world_position": 3,
"response_position": 6,
"fushen_positions": [],
"fushen_relations": [],
"fushen_tigan": [],
"fushen_elements": []
},
"010010": {
"name": "坎为水",
"binary": "010010",
"upper_name": "坎",
"lower_name": "坎",
"yao_relations": ["子孙", "官鬼", "妻财", "父母", "官鬼", "兄弟"],
"yao_tigan": ["寅", "辰", "午", "申", "戌", "子"],
"yao_elements": ["木", "土", "火", "金", "土", "水"],
"world_position": 6,
"response_position": 3,
"fushen_positions": [],
"fushen_relations": [],
"fushen_tigan": [],
"fushen_elements": []
},
"110010": {
"name": "水泽节",
"binary": "110010",
"upper_name": "坎",
"lower_name": "兑",
"yao_relations": ["妻财", "子孙", "官鬼", "父母", "官鬼", "兄弟"],
"yao_tigan": ["巳", "卯", "丑", "申", "戌", "子"],
"yao_elements": ["火", "木", "土", "金", "土", "水"],
"world_position": 1,
"response_position": 4,
"fushen_positions": [],
"fushen_relations": [],
"fushen_tigan": [],
"fushen_elements": []
},
"100010": {
"name": "水雷屯",
"binary": "100010",
"upper_name": "坎",
"lower_name": "震",
"yao_relations": ["兄弟", "子孙", "官鬼", "父母", "官鬼", "兄弟"],
"yao_tigan": ["子", "寅", "辰", "申", "戌", "子"],
"yao_elements": ["水", "木", "土", "金", "土", "水"],
"world_position": 2,
"response_position": 5,
"fushen_positions": [2],
"fushen_relations": ["妻财"],
"fushen_tigan": ["午"],
"fushen_elements": ["火"]
},
"101010": {
"name": "水火既济",
"binary": "101010",
"upper_name": "坎",
"lower_name": "离",
"yao_relations": ["子孙", "官鬼", "兄弟", "父母", "官鬼", "兄弟"],
"yao_tigan": ["卯", "丑", "亥", "申", "戌", "子"],
"yao_elements": ["木", "土", "水", "金", "土", "水"],
"world_position": 3,
"response_position": 6,
"fushen_positions": [2],
"fushen_relations": ["妻财"],
"fushen_tigan": ["午"],
"fushen_elements": ["火"]
},
"101110": {
"name": "泽火革",
"binary": "101110",
"upper_name": "兑",
"lower_name": "离",
"yao_relations": ["子孙", "官鬼", "兄弟", "兄弟", "父母", "官鬼"],
"yao_tigan": ["卯", "丑", "亥", "亥", "酉", "未"],
"yao_elements": ["木", "土", "水", "水", "金", "土"],
"world_position": 4,
"response_position": 1,
"fushen_positions": [2],
"fushen_relations": ["妻财"],
"fushen_tigan": ["午"],
"fushen_elements": ["火"]
},
"101100": {
"name": "雷火丰",
"binary": "101100",
"upper_name": "震",
"lower_name": "离",
"yao_relations": ["子孙", "官鬼", "兄弟", "妻财", "父母", "官鬼"],
"yao_tigan": ["卯", "丑", "亥", "午", "申", "戌"],
"yao_elements": ["木", "土", "水", "火", "金", "土"],
"world_position": 5,
"response_position": 2,
"fushen_positions": [],
"fushen_relations": [],
"fushen_tigan": [],
"fushen_elements": []
},
"101000": {
"name": "地火明夷",
"binary": "101000",
"upper_name": "坤",
"lower_name": "离",
"yao_relations": ["子孙", "官鬼", "兄弟", "官鬼", "兄弟", "父母"],
"yao_tigan": ["卯", "丑", "亥", "丑", "亥", "酉"],
"yao_elements": ["木", "土", "水", "土", "水", "金"],
"world_position": 4,
"response_position": 1,
"fushen_positions": [2],
"fushen_relations": ["妻财"],
"fushen_tigan": ["午"],
"fushen_elements": ["火"]
},
"010000": {
"name": "地水师",
"binary": "010000",
"upper_name": "坤",
"lower_name": "坎",
"yao_relations": ["子孙", "官鬼", "妻财", "官鬼", "兄弟", "父母"],
"yao_tigan": ["寅", "辰", "午", "丑", "亥", "酉"],
"yao_elements": ["木", "土", "火", "土", "水", "金"],
"world_position": 3,
"response_position": 6,
"fushen_positions": [],
"fushen_relations": [],
"fushen_tigan": [],
"fushen_elements": []
},
"001001": {
"name": "艮为山",
"binary": "001001",
"upper_name": "艮",
"lower_name": "艮",
"yao_relations": ["兄弟", "父母", "子孙", "兄弟", "妻财", "官鬼"],
"yao_tigan": ["辰", "午", "申", "戌", "子", "寅"],
"yao_elements": ["土", "火", "金", "土", "水", "木"],
"world_position": 6,
"response_position": 3,
"fushen_positions": [],
"fushen_relations": [],
"fushen_tigan": [],
"fushen_elements": []
},
"101001": {
"name": "山火贲",
"binary": "101001",
"upper_name": "艮",
"lower_name": "离",
"yao_relations": ["官鬼", "兄弟", "妻财", "兄弟", "妻财", "官鬼"],
"yao_tigan": ["卯", "丑", "亥", "戌", "子", "寅"],
"yao_elements": ["木", "土", "水", "土", "水", "木"],
"world_position": 1,
"response_position": 4,
"fushen_positions": [1, 2],
"fushen_relations": ["父母", "子孙"],
"fushen_tigan": ["午", "申"],
"fushen_elements": ["火", "金"]
},
"111001": {
"name": "山天大畜",
"binary": "111001",
"upper_name": "艮",
"lower_name": "乾",
"yao_relations": ["妻财", "官鬼", "兄弟", "兄弟", "妻财", "官鬼"],
"yao_tigan": ["子", "寅", "辰", "戌", "子", "寅"],
"yao_elements": ["水", "木", "土", "土", "水", "木"],
"world_position": 2,
"response_position": 5,
"fushen_positions": [1, 2],
"fushen_relations": ["父母", "子孙"],
"fushen_tigan": ["午", "申"],
"fushen_elements": ["火", "金"]
},
"110001": {
"name": "山泽损",
"binary": "110001",
"upper_name": "艮",
"lower_name": "兑",
"yao_relations": ["父母", "官鬼", "兄弟", "兄弟", "妻财", "官鬼"],
"yao_tigan": ["巳", "卯", "丑", "戌", "子", "寅"],
"yao_elements": ["火", "木", "土", "土", "水", "木"],
"world_position": 3,
"response_position": 6,
"fushen_positions": [2],
"fushen_relations": ["子孙"],
"fushen_tigan": ["申"],
"fushen_elements": ["金"]
},
"110101": {
"name": "火泽睽",
"binary": "110101",
"upper_name": "离",
"lower_name": "兑",
"yao_relations": ["父母", "官鬼", "兄弟", "子孙", "兄弟", "父母"],
"yao_tigan": ["巳", "卯", "丑", "酉", "未", "巳"],
"yao_elements": ["火", "木", "土", "金", "土", "火"],
"world_position": 4,
"response_position": 1,
"fushen_positions": [4],
"fushen_relations": ["妻财"],
"fushen_tigan": ["子"],
"fushen_elements": ["水"]
},
"110111": {
"name": "天泽履",
"binary": "110111",
"upper_name": "乾",
"lower_name": "兑",
"yao_relations": ["父母", "官鬼", "兄弟", "父母", "子孙", "兄弟"],
"yao_tigan": ["巳", "卯", "丑", "午", "申", "戌"],
"yao_elements": ["火", "木", "土", "火", "金", "土"],
"world_position": 5,
"response_position": 2,
"fushen_positions": [4],
"fushen_relations": ["妻财"],
"fushen_tigan": ["子"],
"fushen_elements": ["水"]
},
"110011": {
"name": "风泽中孚",
"binary": "110011",
"upper_name": "巽",
"lower_name": "兑",
"yao_relations": ["父母", "官鬼", "兄弟", "兄弟", "父母", "官鬼"],
"yao_tigan": ["巳", "卯", "丑", "未", "巳", "卯"],
"yao_elements": ["火", "木", "土", "土", "火", "木"],
"world_position": 4,
"response_position": 1,
"fushen_positions": [2, 4],
"fushen_relations": ["子孙", "妻财"],
"fushen_tigan": ["申", "子"],
"fushen_elements": ["金", "水"]
},
"001011": {
"name": "风山渐",
"binary": "001011",
"upper_name": "巽",
"lower_name": "艮",
"yao_relations": ["兄弟", "父母", "子孙", "兄弟", "父母", "官鬼"],
"yao_tigan": ["辰", "午", "申", "未", "巳", "卯"],
"yao_elements": ["土", "火", "金", "土", "火", "木"],
"world_position": 3,
"response_position": 6,
"fushen_positions": [4],
"fushen_relations": ["妻财"],
"fushen_tigan": ["子"],
"fushen_elements": ["水"]
},
"100100": {
"name": "震为雷",
"binary": "100100",
"upper_name": "震",
"lower_name": "震",
"yao_relations": ["父母", "兄弟", "妻财", "子孙", "官鬼", "妻财"],
"yao_tigan": ["子", "寅", "辰", "午", "申", "戌"],
"yao_elements": ["水", "木", "土", "火", "金", "土"],
"world_position": 6,
"response_position": 3,
"fushen_positions": [],
"fushen_relations": [],
"fushen_tigan": [],
"fushen_elements": []
},
"000100": {
"name": "雷地豫",
"binary": "000100",
"upper_name": "震",
"lower_name": "坤",
"yao_relations": ["妻财", "子孙", "兄弟", "子孙", "官鬼", "妻财"],
"yao_tigan": ["未", "巳", "卯", "午", "申", "戌"],
"yao_elements": ["土", "火", "木", "火", "金", "土"],
"world_position": 1,
"response_position": 4,
"fushen_positions": [0],
"fushen_relations": ["父母"],
"fushen_tigan": ["子"],
"fushen_elements": ["水"]
},
"010100": {
"name": "雷水解",
"binary": "010100",
"upper_name": "震",
"lower_name": "坎",
"yao_relations": ["兄弟", "妻财", "子孙", "子孙", "官鬼", "妻财"],
"yao_tigan": ["寅", "辰", "午", "午", "申", "戌"],
"yao_elements": ["木", "土", "火", "火", "金", "土"],
"world_position": 2,
"response_position": 5,
"fushen_positions": [0],
"fushen_relations": ["父母"],
"fushen_tigan": ["子"],
"fushen_elements": ["水"]
},
"011100": {
"name": "雷风恒",
"binary": "011100",
"upper_name": "震",
"lower_name": "巽",
"yao_relations": ["妻财", "父母", "官鬼", "子孙", "官鬼", "妻财"],
"yao_tigan": ["丑", "亥", "酉", "午", "申", "戌"],
"yao_elements": ["土", "水", "金", "火", "金", "土"],
"world_position": 3,
"response_position": 6,
"fushen_positions": [1],
"fushen_relations": ["兄弟"],
"fushen_tigan": ["寅"],
"fushen_elements": ["木"]
},
"011000": {
"name": "地风升",
"binary": "011000",
"upper_name": "坤",
"lower_name": "巽",
"yao_relations": ["妻财", "父母", "官鬼", "妻财", "父母", "官鬼"],
"yao_tigan": ["丑", "亥", "酉", "丑", "亥", "酉"],
"yao_elements": ["土", "水", "金", "土", "水", "金"],
"world_position": 4,
"response_position": 1,
"fushen_positions": [1, 3],
"fushen_relations": ["兄弟", "子孙"],
"fushen_tigan": ["寅", "午"],
"fushen_elements": ["木", "火"]
},
"011010": {
"name": "水风井",
"binary": "011010",
"upper_name": "坎",
"lower_name": "巽",
"yao_relations": ["妻财", "父母", "官鬼", "官鬼", "妻财", "父母"],
"yao_tigan": ["丑", "亥", "酉", "申", "戌", "子"],
"yao_elements": ["土", "水", "金", "金", "土", "水"],
"world_position": 5,
"response_position": 2,
"fushen_positions": [1, 3],
"fushen_relations": ["兄弟", "子孙"],
"fushen_tigan": ["寅", "午"],
"fushen_elements": ["木", "火"]
},
"011110": {
"name": "泽风大过",
"binary": "011110",
"upper_name": "兑",
"lower_name": "巽",
"yao_relations": ["妻财", "父母", "官鬼", "父母", "官鬼", "妻财"],
"yao_tigan": ["丑", "亥", "酉", "亥", "酉", "未"],
"yao_elements": ["土", "水", "金", "水", "金", "土"],
"world_position": 4,
"response_position": 1,
"fushen_positions": [1, 3],
"fushen_relations": ["兄弟", "子孙"],
"fushen_tigan": ["寅", "午"],
"fushen_elements": ["木", "火"]
},
"100110": {
"name": "泽雷随",
"binary": "100110",
"upper_name": "兑",
"lower_name": "震",
"yao_relations": ["父母", "兄弟", "妻财", "父母", "官鬼", "妻财"],
"yao_tigan": ["子", "寅", "辰", "亥", "酉", "未"],
"yao_elements": ["水", "木", "土", "水", "金", "土"],
"world_position": 3,
"response_position": 6,
"fushen_positions": [3],
"fushen_relations": ["子孙"],
"fushen_tigan": ["午"],
"fushen_elements": ["火"]
},
"011011": {
"name": "巽为风",
"binary": "011011",
"upper_name": "巽",
"lower_name": "巽",
"yao_relations": ["妻财", "父母", "官鬼", "妻财", "子孙", "兄弟"],
"yao_tigan": ["丑", "亥", "酉", "未", "巳", "卯"],
"yao_elements": ["土", "水", "金", "土", "火", "木"],
"world_position": 6,
"response_position": 3,
"fushen_positions": [],
"fushen_relations": [],
"fushen_tigan": [],
"fushen_elements": []
},
"111011": {
"name": "风天小畜",
"binary": "111011",
"upper_name": "巽",
"lower_name": "乾",
"yao_relations": ["父母", "兄弟", "妻财", "妻财", "子孙", "兄弟"],
"yao_tigan": ["子", "寅", "辰", "未", "巳", "卯"],
"yao_elements": ["水", "木", "土", "土", "火", "木"],
"world_position": 1,
"response_position": 4,
"fushen_positions": [2],
"fushen_relations": ["官鬼"],
"fushen_tigan": ["酉"],
"fushen_elements": ["金"]
},
"101011": {
"name": "风火家人",
"binary": "101011",
"upper_name": "巽",
"lower_name": "离",
"yao_relations": ["兄弟", "妻财", "父母", "妻财", "子孙", "兄弟"],
"yao_tigan": ["卯", "丑", "亥", "未", "巳", "卯"],
"yao_elements": ["木", "土", "水", "土", "火", "木"],
"world_position": 2,
"response_position": 5,
"fushen_positions": [2],
"fushen_relations": ["官鬼"],
"fushen_tigan": ["酉"],
"fushen_elements": ["金"]
},
"100011": {
"name": "风雷益",
"binary": "100011",
"upper_name": "巽",
"lower_name": "震",
"yao_relations": ["父母", "兄弟", "妻财", "妻财", "子孙", "兄弟"],
"yao_tigan": ["子", "寅", "辰", "未", "巳", "卯"],
"yao_elements": ["水", "木", "土", "土", "火", "木"],
"world_position": 3,
"response_position": 6,
"fushen_positions": [2],
"fushen_relations": ["官鬼"],
"fushen_tigan": ["酉"],
"fushen_elements": ["金"]
},
"100111": {
"name": "天雷无妄",
"binary": "100111",
"upper_name": "乾",
"lower_name": "震",
"yao_relations": ["父母", "兄弟", "妻财", "子孙", "官鬼", "妻财"],
"yao_tigan": ["子", "寅", "辰", "午", "申", "戌"],
"yao_elements": ["水", "木", "土", "火", "金", "土"],
"world_position": 4,
"response_position": 1,
"fushen_positions": [],
"fushen_relations": [],
"fushen_tigan": [],
"fushen_elements": []
},
"100101": {
"name": "火雷噬嗑",
"binary": "100101",
"upper_name": "离",
"lower_name": "震",
"yao_relations": ["父母", "兄弟", "妻财", "官鬼", "妻财", "子孙"],
"yao_tigan": ["子", "寅", "辰", "酉", "未", "巳"],
"yao_elements": ["水", "木", "土", "金", "土", "火"],
"world_position": 5,
"response_position": 2,
"fushen_positions": [],
"fushen_relations": [],
"fushen_tigan": [],
"fushen_elements": []
},
"100001": {
"name": "山雷颐",
"binary": "100001",
"upper_name": "艮",
"lower_name": "震",
"yao_relations": ["父母", "兄弟", "妻财", "妻财", "父母", "兄弟"],
"yao_tigan": ["子", "寅", "辰", "戌", "子", "寅"],
"yao_elements": ["水", "木", "土", "土", "水", "木"],
"world_position": 4,
"response_position": 1,
"fushen_positions": [2, 4],
"fushen_relations": ["官鬼", "子孙"],
"fushen_tigan": ["酉", "巳"],
"fushen_elements": ["金", "火"]
},
"011001": {
"name": "山风蛊",
"binary": "011001",
"upper_name": "艮",
"lower_name": "巽",
"yao_relations": ["妻财", "父母", "官鬼", "妻财", "父母", "兄弟"],
"yao_tigan": ["丑", "亥", "酉", "戌", "子", "寅"],
"yao_elements": ["土", "水", "金", "土", "水", "木"],
"world_position": 3,
"response_position": 6,
"fushen_positions": [4],
"fushen_relations": ["子孙"],
"fushen_tigan": ["巳"],
"fushen_elements": ["火"]
},
"101101": {
"name": "离为火",
"binary": "101101",
"upper_name": "离",
"lower_name": "离",
"yao_relations": ["父母", "子孙", "官鬼", "妻财", "子孙", "兄弟"],
"yao_tigan": ["卯", "丑", "亥", "酉", "未", "巳"],
"yao_elements": ["木", "土", "水", "金", "土", "火"],
"world_position": 6,
"response_position": 3,
"fushen_positions": [],
"fushen_relations": [],
"fushen_tigan": [],
"fushen_elements": []
},
"001101": {
"name": "火山旅",
"binary": "001101",
"upper_name": "离",
"lower_name": "艮",
"yao_relations": ["子孙", "兄弟", "妻财", "妻财", "子孙", "兄弟"],
"yao_tigan": ["辰", "午", "申", "酉", "未", "巳"],
"yao_elements": ["土", "火", "金", "金", "土", "火"],
"world_position": 1,
"response_position": 4,
"fushen_positions": [0, 2],
"fushen_relations": ["父母", "官鬼"],
"fushen_tigan": ["卯", "亥"],
"fushen_elements": ["木", "水"]
},
"011101": {
"name": "火风鼎",
"binary": "011101",
"upper_name": "离",
"lower_name": "巽",
"yao_relations": ["子孙", "官鬼", "妻财", "妻财", "子孙", "兄弟"],
"yao_tigan": ["丑", "亥", "酉", "酉", "未", "巳"],
"yao_elements": ["土", "水", "金", "金", "土", "火"],
"world_position": 2,
"response_position": 5,
"fushen_positions": [0],
"fushen_relations": ["父母"],
"fushen_tigan": ["卯"],
"fushen_elements": ["木"]
},
"010101": {
"name": "火水未济",
"binary": "010101",
"upper_name": "离",
"lower_name": "坎",
"yao_relations": ["父母", "子孙", "兄弟", "妻财", "子孙", "兄弟"],
"yao_tigan": ["寅", "辰", "午", "酉", "未", "巳"],
"yao_elements": ["木", "土", "火", "金", "土", "火"],
"world_position": 3,
"response_position": 6,
"fushen_positions": [2],
"fushen_relations": ["官鬼"],
"fushen_tigan": ["亥"],
"fushen_elements": ["水"]
},
"010001": {
"name": "山水蒙",
"binary": "010001",
"upper_name": "艮",
"lower_name": "坎",
"yao_relations": ["父母", "子孙", "兄弟", "子孙", "官鬼", "父母"],
"yao_tigan": ["寅", "辰", "午", "戌", "子", "寅"],
"yao_elements": ["木", "土", "火", "土", "水", "木"],
"world_position": 4,
"response_position": 1,
"fushen_positions": [3],
"fushen_relations": ["妻财"],
"fushen_tigan": ["酉"],
"fushen_elements": ["金"]
},
"010011": {
"name": "风水涣",
"binary": "010011",
"upper_name": "巽",
"lower_name": "坎",
"yao_relations": ["父母", "子孙", "兄弟", "子孙", "兄弟", "父母"],
"yao_tigan": ["寅", "辰", "午", "未", "巳", "卯"],
"yao_elements": ["木", "土", "火", "土", "火", "木"],
"world_position": 5,
"response_position": 2,
"fushen_positions": [2, 3],
"fushen_relations": ["官鬼", "妻财"],
"fushen_tigan": ["亥", "酉"],
"fushen_elements": ["水", "金"]
},
"010111": {
"name": "天水讼",
"binary": "010111",
"upper_name": "乾",
"lower_name": "坎",
"yao_relations": ["父母", "子孙", "兄弟", "兄弟", "妻财", "子孙"],
"yao_tigan": ["寅", "辰", "午", "午", "申", "戌"],
"yao_elements": ["木", "土", "火", "火", "金", "土"],
"world_position": 4,
"response_position": 1,
"fushen_positions": [2],
"fushen_relations": ["官鬼"],
"fushen_tigan": ["亥"],
"fushen_elements": ["水"]
},
"101111": {
"name": "天火同人",
"binary": "101111",
"upper_name": "乾",
"lower_name": "离",
"yao_relations": ["父母", "子孙", "官鬼", "兄弟", "妻财", "子孙"],
"yao_tigan": ["卯", "丑", "亥", "午", "申", "戌"],
"yao_elements": ["木", "土", "水", "火", "金", "土"],
"world_position": 3,
"response_position": 6,
"fushen_positions": [],
"fushen_relations": [],
"fushen_tigan": [],
"fushen_elements": []
},
"000000": {
"name": "坤为地",
"binary": "000000",
"upper_name": "坤",
"lower_name": "坤",
"yao_relations": ["兄弟", "父母", "官鬼", "兄弟", "妻财", "子孙"],
"yao_tigan": ["未", "巳", "卯", "丑", "亥", "酉"],
"yao_elements": ["土", "火", "木", "土", "水", "金"],
"world_position": 6,
"response_position": 3,
"fushen_positions": [],
"fushen_relations": [],
"fushen_tigan": [],
"fushen_elements": []
},
"100000": {
"name": "地雷复",
"binary": "100000",
"upper_name": "坤",
"lower_name": "震",
"yao_relations": ["妻财", "官鬼", "兄弟", "兄弟", "妻财", "子孙"],
"yao_tigan": ["子", "寅", "辰", "丑", "亥", "酉"],
"yao_elements": ["水", "木", "土", "土", "水", "金"],
"world_position": 1,
"response_position": 4,
"fushen_positions": [1],
"fushen_relations": ["父母"],
"fushen_tigan": ["巳"],
"fushen_elements": ["火"]
},
"110000": {
"name": "地泽临",
"binary": "110000",
"upper_name": "坤",
"lower_name": "兑",
"yao_relations": ["父母", "官鬼", "兄弟", "兄弟", "妻财", "子孙"],
"yao_tigan": ["巳", "卯", "丑", "丑", "亥", "酉"],
"yao_elements": ["火", "木", "土", "土", "水", "金"],
"world_position": 2,
"response_position": 5,
"fushen_positions": [],
"fushen_relations": [],
"fushen_tigan": [],
"fushen_elements": []
},
"111000": {
"name": "地天泰",
"binary": "111000",
"upper_name": "坤",
"lower_name": "乾",
"yao_relations": ["妻财", "官鬼", "兄弟", "兄弟", "妻财", "子孙"],
"yao_tigan": ["子", "寅", "辰", "丑", "亥", "酉"],
"yao_elements": ["水", "木", "土", "土", "水", "金"],
"world_position": 3,
"response_position": 6,
"fushen_positions": [1],
"fushen_relations": ["父母"],
"fushen_tigan": ["巳"],
"fushen_elements": ["火"]
},
"111100": {
"name": "雷天大壮",
"binary": "111100",
"upper_name": "震",
"lower_name": "乾",
"yao_relations": ["妻财", "官鬼", "兄弟", "父母", "子孙", "兄弟"],
"yao_tigan": ["子", "寅", "辰", "午", "申", "戌"],
"yao_elements": ["水", "木", "土", "火", "金", "土"],
"world_position": 4,
"response_position": 1,
"fushen_positions": [],
"fushen_relations": [],
"fushen_tigan": [],
"fushen_elements": []
},
"111110": {
"name": "泽天夬",
"binary": "111110",
"upper_name": "兑",
"lower_name": "乾",
"yao_relations": ["妻财", "官鬼", "兄弟", "妻财", "子孙", "兄弟"],
"yao_tigan": ["子", "寅", "辰", "亥", "酉", "未"],
"yao_elements": ["水", "木", "土", "水", "金", "土"],
"world_position": 5,
"response_position": 2,
"fushen_positions": [1],
"fushen_relations": ["父母"],
"fushen_tigan": ["巳"],
"fushen_elements": ["火"]
},
"111010": {
"name": "水天需",
"binary": "111010",
"upper_name": "坎",
"lower_name": "乾",
"yao_relations": ["妻财", "官鬼", "兄弟", "子孙", "兄弟", "妻财"],
"yao_tigan": ["子", "寅", "辰", "申", "戌", "子"],
"yao_elements": ["水", "木", "土", "金", "土", "水"],
"world_position": 4,
"response_position": 1,
"fushen_positions": [1],
"fushen_relations": ["父母"],
"fushen_tigan": ["巳"],
"fushen_elements": ["火"]
},
"000010": {
"name": "水地比",
"binary": "000010",
"upper_name": "坎",
"lower_name": "坤",
"yao_relations": ["兄弟", "父母", "官鬼", "子孙", "兄弟", "妻财"],
"yao_tigan": ["未", "巳", "卯", "申", "戌", "子"],
"yao_elements": ["土", "火", "木", "金", "土", "水"],
"world_position": 3,
"response_position": 6,
"fushen_positions": [],
"fushen_relations": [],
"fushen_tigan": [],
"fushen_elements": []
},
"110110": {
"name": "兑为泽",
"binary": "110110",
"upper_name": "兑",
"lower_name": "兑",
"yao_relations": ["官鬼", "妻财", "父母", "子孙", "兄弟", "父母"],
"yao_tigan": ["巳", "卯", "丑", "亥", "酉", "未"],
"yao_elements": ["火", "木", "土", "水", "金", "土"],
"world_position": 6,
"response_position": 3,
"fushen_positions": [],
"fushen_relations": [],
"fushen_tigan": [],
"fushen_elements": []
},
"010110": {
"name": "泽水困",
"binary": "010110",
"upper_name": "兑",
"lower_name": "坎",
"yao_relations": ["妻财", "父母", "官鬼", "子孙", "兄弟", "父母"],
"yao_tigan": ["寅", "辰", "午", "亥", "酉", "未"],
"yao_elements": ["木", "土", "火", "水", "金", "土"],
"world_position": 1,
"response_position": 4,
"fushen_positions": [],
"fushen_relations": [],
"fushen_tigan": [],
"fushen_elements": []
},
"000110": {
"name": "泽地萃",
"binary": "000110",
"upper_name": "兑",
"lower_name": "坤",
"yao_relations": ["父母", "官鬼", "妻财", "子孙", "兄弟", "父母"],
"yao_tigan": ["未", "巳", "卯", "亥", "酉", "未"],
"yao_elements": ["土", "火", "木", "水", "金", "土"],
"world_position": 2,
"response_position": 5,
"fushen_positions": [],
"fushen_relations": [],
"fushen_tigan": [],
"fushen_elements": []
},
"001110": {
"name": "泽山咸",
"binary": "001110",
"upper_name": "兑",
"lower_name": "艮",
"yao_relations": ["父母", "官鬼", "兄弟", "子孙", "兄弟", "父母"],
"yao_tigan": ["辰", "午", "申", "亥", "酉", "未"],
"yao_elements": ["土", "火", "金", "水", "金", "土"],
"world_position": 3,
"response_position": 6,
"fushen_positions": [1],
"fushen_relations": ["妻财"],
"fushen_tigan": ["卯"],
"fushen_elements": ["木"]
},
"001010": {
"name": "水山蹇",
"binary": "001010",
"upper_name": "坎",
"lower_name": "艮",
"yao_relations": ["父母", "官鬼", "兄弟", "兄弟", "父母", "子孙"],
"yao_tigan": ["辰", "午", "申", "申", "戌", "子"],
"yao_elements": ["土", "火", "金", "金", "土", "水"],
"world_position": 4,
"response_position": 1,
"fushen_positions": [1],
"fushen_relations": ["妻财"],
"fushen_tigan": ["卯"],
"fushen_elements": ["木"]
},
"001000": {
"name": "地山谦",
"binary": "001000",
"upper_name": "坤",
"lower_name": "艮",
"yao_relations": ["父母", "官鬼", "兄弟", "父母", "子孙", "兄弟"],
"yao_tigan": ["辰", "午", "申", "丑", "亥", "酉"],
"yao_elements": ["土", "火", "金", "土", "水", "金"],
"world_position": 5,
"response_position": 2,
"fushen_positions": [1],
"fushen_relations": ["妻财"],
"fushen_tigan": ["卯"],
"fushen_elements": ["木"]
},
"001100": {
"name": "雷山小过",
"binary": "001100",
"upper_name": "震",
"lower_name": "艮",
"yao_relations": ["父母", "官鬼", "兄弟", "官鬼", "兄弟", "父母"],
"yao_tigan": ["辰", "午", "申", "午", "申", "戌"],
"yao_elements": ["土", "火", "金", "火", "金", "土"],
"world_position": 4,
"response_position": 1,
"fushen_positions": [1, 3],
"fushen_relations": ["妻财", "子孙"],
"fushen_tigan": ["卯", "亥"],
"fushen_elements": ["木", "水"]
},
"110100": {
"name": "雷泽归妹",
"binary": "110100",
"upper_name": "震",
"lower_name": "兑",
"yao_relations": ["官鬼", "妻财", "父母", "官鬼", "兄弟", "父母"],
"yao_tigan": ["巳", "卯", "丑", "午", "申", "戌"],
"yao_elements": ["火", "木", "土", "火", "金", "土"],
"world_position": 3,
"response_position": 6,
"fushen_positions": [3],
"fushen_relations": ["子孙"],
"fushen_tigan": ["亥"],
"fushen_elements": ["水"]
}
}
+30 -104
View File
@@ -2,8 +2,8 @@ from __future__ import annotations
from dataclasses import dataclass
from functools import lru_cache
import json
from pathlib import Path
import re
@dataclass(frozen=True)
@@ -23,116 +23,42 @@ class GuaCatalogItem:
fushen_elements: tuple[str, ...]
_ENTRY_HEAD_RE = re.compile(r'put\("([01]{6})",\s*GuaInfo\(', re.MULTILINE)
_STRING_FIELD_RE = re.compile(r'\b%s\s*=\s*"([^"]*)"')
_INT_FIELD_RE = re.compile(r"\b%s\s*=\s*(\d+)")
_LIST_STRING_FIELD_RE = re.compile(r"\b%s\s*=\s*listOf\((.*?)\)", re.DOTALL)
_LIST_INT_FIELD_RE = re.compile(r"\b%s\s*=\s*listOf\((.*?)\)", re.DOTALL)
def _extract_gua_body(source: str, start_idx: int) -> tuple[str, int]:
depth = 1
idx = start_idx
while idx < len(source):
ch = source[idx]
if ch == "(":
depth += 1
elif ch == ")":
depth -= 1
if depth == 0:
return source[start_idx:idx], idx
idx += 1
raise ValueError("invalid Guaxiang.kt structure: unmatched parenthesis")
def _parse_string_field(body: str, field_name: str) -> str:
match = _STRING_FIELD_RE.pattern % re.escape(field_name)
found = re.search(match, body)
if found is None:
raise ValueError(f"missing field: {field_name}")
return found.group(1)
def _parse_int_field(body: str, field_name: str) -> int:
match = _INT_FIELD_RE.pattern % re.escape(field_name)
found = re.search(match, body)
if found is None:
raise ValueError(f"missing field: {field_name}")
return int(found.group(1))
def _parse_list_of_strings(
body: str, field_name: str, *, optional: bool = False
) -> tuple[str, ...]:
if f"{field_name} = emptyList()" in body:
return ()
match = _LIST_STRING_FIELD_RE.pattern % re.escape(field_name)
found = re.search(match, body)
if found is None:
if optional:
return ()
raise ValueError(f"missing list field: {field_name}")
inner = found.group(1)
values = re.findall(r'"([^"]+)"', inner)
return tuple(values)
def _parse_list_of_ints(
body: str, field_name: str, *, optional: bool = False
) -> tuple[int, ...]:
if f"{field_name} = emptyList()" in body:
return ()
match = _LIST_INT_FIELD_RE.pattern % re.escape(field_name)
found = re.search(match, body)
if found is None:
if optional:
return ()
raise ValueError(f"missing list field: {field_name}")
inner = found.group(1)
values = [int(item.strip()) for item in inner.split(",") if item.strip()]
return tuple(values)
def _resolve_guaxiang_file() -> Path:
def _resolve_catalog_file() -> Path:
current = Path(__file__).resolve()
root = current.parents[4]
target = (
root / "old/app/src/main/java/com/example/eryaoapp/screens/result/Guaxiang.kt"
)
target = current.parent / "data/gua_catalog.json"
if not target.exists():
raise FileNotFoundError(f"Guaxiang.kt not found: {target}")
raise FileNotFoundError(f"gua_catalog.json not found: {target}")
return target
def _to_item(raw: object) -> GuaCatalogItem:
if not isinstance(raw, dict):
raise ValueError("invalid gua catalog item: expected object")
return GuaCatalogItem(
name=str(raw["name"]),
binary=str(raw["binary"]),
upper_name=str(raw["upper_name"]),
lower_name=str(raw["lower_name"]),
yao_relations=tuple(str(v) for v in raw["yao_relations"]),
yao_tigan=tuple(str(v) for v in raw["yao_tigan"]),
yao_elements=tuple(str(v) for v in raw["yao_elements"]),
world_position=int(raw["world_position"]),
response_position=int(raw["response_position"]),
fushen_positions=tuple(int(v) for v in raw["fushen_positions"]),
fushen_relations=tuple(str(v) for v in raw["fushen_relations"]),
fushen_tigan=tuple(str(v) for v in raw["fushen_tigan"]),
fushen_elements=tuple(str(v) for v in raw["fushen_elements"]),
)
@lru_cache(maxsize=1)
def load_gua_catalog() -> dict[str, GuaCatalogItem]:
source = _resolve_guaxiang_file().read_text(encoding="utf-8")
result: dict[str, GuaCatalogItem] = {}
for head in _ENTRY_HEAD_RE.finditer(source):
binary = head.group(1)
body, _ = _extract_gua_body(source, head.end())
item = GuaCatalogItem(
name=_parse_string_field(body, "name"),
binary=_parse_string_field(body, "binary"),
upper_name=_parse_string_field(body, "upperName"),
lower_name=_parse_string_field(body, "lowerName"),
yao_relations=_parse_list_of_strings(body, "yaoRelations"),
yao_tigan=_parse_list_of_strings(body, "yaoTiGan"),
yao_elements=_parse_list_of_strings(body, "yaoElements"),
world_position=_parse_int_field(body, "worldPosition"),
response_position=_parse_int_field(body, "responsePosition"),
fushen_positions=_parse_list_of_ints(
body, "fushenPositions", optional=True
),
fushen_relations=_parse_list_of_strings(
body, "fushenRelations", optional=True
),
fushen_tigan=_parse_list_of_strings(body, "fushenTiGan", optional=True),
fushen_elements=_parse_list_of_strings(
body, "fushenElements", optional=True
),
)
result[binary] = item
source = _resolve_catalog_file().read_text(encoding="utf-8")
raw_data = json.loads(source)
if not isinstance(raw_data, dict):
raise ValueError("invalid gua catalog payload")
result = {str(binary): _to_item(item) for binary, item in raw_data.items()}
if len(result) != 64:
raise ValueError(f"invalid gua catalog size: {len(result)}")