Owner 2026-11-23 overrides the BUG-2132 structure-only copy for this page: each card asks e.g. 「工作上你更像哪一种?」, each side gets a short label and one or two tendency sentences from the fixed tables in scripts/chart_choice/portraits.py (phrase table drafted by jyotisha-ac), built only from the positions that differ; never two identical portraits. Positions move to a folded 「依据」 as 「金星在第 10 宫(事业)」. Old lines without a portrait still list their differences. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
337 lines
18 KiB
Python
337 lines
18 KiB
Python
"""BUG-2272 (产品负责人 2026-11-23, overriding the astrologer's 11-21 structure-only ruling for this page):
|
||
each self-choice card asks a life question and shows, for each side of the line, a short everyday
|
||
portrait — a bold label of four to eight characters and one or two plain sentences of tendency.
|
||
|
||
Every phrase comes from the fixed tables below and is combined deterministically from the chart
|
||
positions that differ between the two sides; no model writes any of it at run time. The voice is
|
||
tendency only (更偏向 / 通常 / 往往): no 一定, no good or bad, no timing. The positions themselves
|
||
stay available behind a folded 「依据」, in plain words (``plain_fact``).
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
from typing import Any, Final
|
||
|
||
# The question each domain card asks.
|
||
QUESTION: Final = {
|
||
"self": "整体上你更像哪一种?",
|
||
"relationship": "感情里你更像哪一种?",
|
||
"career": "工作上你更像哪一种?",
|
||
"money": "对钱你更像哪一种?",
|
||
"pressure": "平时生活你更像哪一种?",
|
||
"change": "遇到大变化你更像哪一种?",
|
||
"home": "在住的方面你更像哪一种?",
|
||
"parents": "和父母相处你更像哪一种?",
|
||
"study": "学习上你更像哪一种?",
|
||
}
|
||
|
||
# Short label when a planet sits in the domain's own place (or in the place that stands for you).
|
||
PLANET_LABEL: Final = {
|
||
"Sun": "爱出头、担大梁", "Moon": "重感受、讲人情", "Mars": "行动快、敢去拼", "Mercury": "脑子快、会沟通",
|
||
"Jupiter": "讲分寸、有人帮", "Venus": "重人缘和品味", "Saturn": "能扛事、慢慢来", "Rahu": "不走寻常路",
|
||
"Ketu": "专注一门、不凑热闹",
|
||
}
|
||
|
||
# What that planet's presence looks like in each domain. One sentence, tendency voice.
|
||
PLANET_IN_DOMAIN: Final = {
|
||
"career": {
|
||
"Sun": "工作上更愿意站到前面拿主意,看重职位和别人的认可。",
|
||
"Moon": "工作上常和人打交道,情绪投入多,做的事也容易跟着变化走。",
|
||
"Mars": "工作上动作快、愿意竞争,更偏向技术活或需要拼一把的岗位。",
|
||
"Mercury": "工作上靠沟通、文字、数据或买卖,脑子转得快。",
|
||
"Jupiter": "工作上容易遇到愿意带你的人,更偏向大平台和讲专业的地方。",
|
||
"Venus": "喜欢和人打交道,做事讲究体面好看,机会常常从人际关系里来。",
|
||
"Saturn": "习惯自己顶上去,规矩和责任感重,起步慢一些但越做越稳。",
|
||
"Rahu": "工作上野心大,常选新兴的、少有人走的路。",
|
||
"Ketu": "工作上更愿意钻一门手艺,不太在意外面的掌声。",
|
||
},
|
||
"relationship": {
|
||
"Sun": "感情里比较有主见,希望对方尊重自己。",
|
||
"Moon": "感情里投入深,很在意被照顾、被理解。",
|
||
"Mars": "感情来得直接,有热度,也容易起争执。",
|
||
"Mercury": "感情从聊得来开始,重视交流和默契。",
|
||
"Jupiter": "感情里讲分寸和信任,看重对方的品格。",
|
||
"Venus": "感情里重浪漫和相处的舒服,在意生活的品味。",
|
||
"Saturn": "感情慢热,一旦认定就很认真,责任感重。",
|
||
"Rahu": "容易被和自己很不一样的人吸引。",
|
||
"Ketu": "感情里保留自己的空间,不太黏人。",
|
||
},
|
||
"self": {
|
||
"Sun": "做事有主见,愿意出头,也要面子。",
|
||
"Moon": "心思细,跟着感受走,和人亲近。",
|
||
"Mars": "性子急,说做就做,不服输。",
|
||
"Mercury": "脑子快,爱琢磨,说话有条理。",
|
||
"Jupiter": "为人宽厚,讲道理,愿意帮人。",
|
||
"Venus": "随和,爱美,在意相处舒不舒服。",
|
||
"Saturn": "稳重,能吃苦,做事一板一眼。",
|
||
"Rahu": "好奇心重,想法常常和别人不一样。",
|
||
"Ketu": "安静内敛,不太在乎外人怎么看。",
|
||
},
|
||
"home": {
|
||
"Sun": "对住的地方有主见,喜欢自己说了算。",
|
||
"Moon": "很恋家,住得舒不舒服对心情影响大。",
|
||
"Mars": "住处容易有变动,也愿意自己动手折腾。",
|
||
"Mercury": "住处常常跟着学习或工作调整,搬动不少。",
|
||
"Jupiter": "住得比较宽敞安稳,家里常有长辈照应。",
|
||
"Venus": "讲究住得好看、舒服,愿意在家上花心思。",
|
||
"Saturn": "住处变化少,一住就是很久,也比较朴素。",
|
||
"Rahu": "常住在离老家较远或不太常规的地方。",
|
||
"Ketu": "对住处要求不高,住哪里都能过。",
|
||
},
|
||
"parents": {
|
||
"Sun": "和父母之间讲规矩,父亲那边的影响比较明显。",
|
||
"Moon": "和父母情感上亲,母亲那边的影响比较明显。",
|
||
"Mars": "和父母说话直接,偶尔会顶撞。",
|
||
"Mercury": "和父母聊得来,常一起商量事情。",
|
||
"Jupiter": "父母像老师,给你见识和道理。",
|
||
"Venus": "家里气氛温和,父母重视生活的舒适。",
|
||
"Saturn": "父母要求严,家里的责任担得早。",
|
||
"Rahu": "和父母的想法差别大,各走各的路。",
|
||
"Ketu": "和父母之间有距离,不太黏家。",
|
||
},
|
||
"study": {
|
||
"Sun": "学习上要强,想在班里排在前面。",
|
||
"Moon": "学习看心情和环境,喜欢的就学得好。",
|
||
"Mars": "学习靠拼劲,考试前冲得猛。",
|
||
"Mercury": "学得快,读写和表达好。",
|
||
"Jupiter": "愿意往深里学,容易遇到好老师。",
|
||
"Venus": "偏向艺术、设计或和人相关的科目。",
|
||
"Saturn": "学习慢而扎实,一步一步积累。",
|
||
"Rahu": "爱学新东西,常换方向。",
|
||
"Ketu": "喜欢一个人钻研,偏冷门的东西。",
|
||
},
|
||
}
|
||
|
||
# Short label when the domain's own planet goes to place 1..12.
|
||
HOUSE_LABEL: Final = (
|
||
"自己拿主意", "看重收入和家", "靠自己闯", "离不开家", "靠专长和兴趣", "在竞争里磨",
|
||
"靠合作和人", "起伏多、爱深挖", "往远处走", "冲着位置去", "靠圈子和机会", "常在外面、偏幕后",
|
||
)
|
||
|
||
# Where the domain's own planet goes, read for that domain. Index = place 1..12. {who}: 母亲 / 父亲.
|
||
LORD_IN_HOUSE: Final = {
|
||
"career": (
|
||
"工作和自己绑在一起,更偏向靠个人特色、自己做主。",
|
||
"工作常和钱、家里或口才有关,看重收入稳不稳。",
|
||
"路多半靠自己闯出来,常要主动、表达、写写说说。",
|
||
"工作和家、生活方式分不太开,喜欢离家近或能顾家的安排。",
|
||
"更偏向靠专长、兴趣和脑子吃饭,技术、研究、创作或教育一类。",
|
||
"常在竞争和解决问题里成长,服务、专业技术或要拼的岗位更合适。",
|
||
"工作靠合作、客户和对外打交道推动。",
|
||
"工作里转折不少,更偏向幕后、研究或要往深处挖的事。",
|
||
"老师、远方或更高的学历常常推着工作往前走。",
|
||
"事业心重,愿意站到显眼的位置上。",
|
||
"机会多从人脉和圈子里来,很看重实际收获。",
|
||
"工作常和外地、外企或幕后有关,常要离开熟悉的环境。",
|
||
),
|
||
"home": (
|
||
"住哪里跟着自己的选择走。",
|
||
"住处常和家里的钱或家族的安排有关。",
|
||
"搬动多,但多半在熟悉的范围里。",
|
||
"住处安稳,和老家、家人牵连深。",
|
||
"住的地方常跟着兴趣、学习或孩子走。",
|
||
"住处的琐事多,要花心思打理。",
|
||
"住处的变化常和伴侣或合作的人有关。",
|
||
"住处偶尔会有突然的变动。",
|
||
"可能为了读书或去远方而搬家。",
|
||
"人跟着工作走,为了工作定在一个地方。",
|
||
"住得热闹,周围常有朋友。",
|
||
"常年住在出生地以外,心里有离乡的感觉。",
|
||
),
|
||
"relationship": (
|
||
"感情里很看重自己,伴侣往往和你性格相近。",
|
||
"感情和家庭、钱的观念绑得紧。",
|
||
"感情常从交流开始,对方可能是同学、同事或身边的人。",
|
||
"感情和家庭分不开,看重安稳。",
|
||
"感情从兴趣和心动开始,重视浪漫的感觉。",
|
||
"感情里磨合多,有事要一起处理。",
|
||
"很看重伴侣本身,关系是生活的重心。",
|
||
"感情有深度,也有起伏和转折。",
|
||
"伴侣可能来自远方,或在见识、信念上影响你。",
|
||
"伴侣常和工作、社会身份有关。",
|
||
"感情常从朋友圈里来,看重共同的圈子。",
|
||
"感情里有私密或异地的一面。",
|
||
),
|
||
"parents": (
|
||
"和{who}性格相近,{who}的影响很直接。",
|
||
"{who}和家里的钱、家族的事关系大。",
|
||
"{who}更鼓励你自己出去闯。",
|
||
"{who}和家、住处的牵连深。",
|
||
"{who}很看重你的学习和兴趣。",
|
||
"和{who}之间有要磨合的地方。",
|
||
"{who}的影响常通过对外的事情体现。",
|
||
"和{who}的关系有深度,也有变化。",
|
||
"{who}像老师,带给你见识和信念。",
|
||
"{who}在工作或社会上有分量。",
|
||
"{who}给你实际的帮助多。",
|
||
"和{who}之间有距离,可能分开生活。",
|
||
),
|
||
"study": (
|
||
"学习靠自己,主动性强。",
|
||
"学的东西偏实用,和挣钱有关。",
|
||
"靠多说多练学得好,读写表达是长处。",
|
||
"需要安稳的环境,家里的支持很重要。",
|
||
"从兴趣出发,专长明显。",
|
||
"在考试和竞争里出成绩。",
|
||
"和老师、同学一起学效果更好。",
|
||
"学业有停顿或转向,偏向深的东西。",
|
||
"愿意去远方读书,往高处学。",
|
||
"学的东西后来直接用在工作上。",
|
||
"学习带来实际的收获和人脉。",
|
||
"更愿意到外地去深造。",
|
||
),
|
||
"self": (
|
||
"很有主见,凡事自己拿主意。",
|
||
"看重钱和家,说话有分量。",
|
||
"主动、爱表达,喜欢靠自己闯。",
|
||
"恋家,心里很需要安全感。",
|
||
"重兴趣和创造,脑子活。",
|
||
"能吃苦,在磨炼里长本事。",
|
||
"很看重身边的伴侣和合作的人。",
|
||
"经历的转折多,喜欢琢磨深的东西。",
|
||
"有信念,常有人愿意帮你。",
|
||
"事业心重,看重地位。",
|
||
"重视朋友圈,在意实际的收获。",
|
||
"向往远方,也有喜欢独处的一面。",
|
||
),
|
||
}
|
||
|
||
# 钱财盘 D2: which half the ascendant falls in.
|
||
HORA_PORTRAIT: Final = {
|
||
4: ("靠位置和责任挣钱", "钱更多来自自己出头、担责任,在一个体系里往上走,来得慢一些,也比较稳。"),
|
||
3: ("靠人和买卖挣钱", "钱更多来自和人打交道、做买卖或做内容,来得灵活,也比较零散。"),
|
||
}
|
||
|
||
# 日常 D6 / 突变 D8: by the element of the chart's rising sign (fire, earth, air, water).
|
||
ELEMENT_PORTRAIT: Final = {
|
||
"pressure": (
|
||
("先顶上去再说", "平时事情一多,通常先处理眼前最紧的一件,忙起来顾不上别的。"),
|
||
("按部就班地来", "平时事情一多,通常还是按原来的节奏,把事情一件件做完。"),
|
||
("先把话说开", "平时事情一多,通常先和人说开,一起把头绪理清楚。"),
|
||
("先缓一缓", "平时事情一多,通常先给自己一点时间,心里顺了再安排下一步。"),
|
||
),
|
||
"change": (
|
||
("先试新办法", "遇到大变化,通常先动手试一个新办法,边做边调。"),
|
||
("先稳住能用的", "遇到大变化,通常先留住还能用的安排,再慢慢改。"),
|
||
("多看多比", "遇到大变化,通常先打听消息,多比较几条路再定。"),
|
||
("找熟人商量", "遇到大变化,通常先找熟悉的人商量下一步。"),
|
||
),
|
||
}
|
||
|
||
# Place names for the folded 「依据」 (BUG-2272, the house gloss the owner saw on 2026-11-23).
|
||
HOUSE_PLAIN: Final = (
|
||
"自己", "钱和家人", "兄弟和表达", "家和住处", "兴趣、专长和子女", "日常工作和身体",
|
||
"伴侣和合作", "变动和别人的钱", "远方、读书和贵人", "事业", "收获和朋友圈", "离乡、开销和独处",
|
||
)
|
||
|
||
|
||
def _who(label: str) -> str:
|
||
return "父亲" if "父亲" in label else "母亲"
|
||
|
||
|
||
def point_portrait(domain: str, point: dict[str, Any]) -> tuple[str, str] | None:
|
||
"""(label, sentence) for one structural point, from the tables only."""
|
||
kind = point.get("kind")
|
||
if kind == "occupant":
|
||
planet = point.get("planet")
|
||
sentence = PLANET_IN_DOMAIN.get(domain, {}).get(planet)
|
||
return (PLANET_LABEL[planet], sentence) if sentence else None
|
||
if kind == "lord":
|
||
house = point.get("house")
|
||
rows = LORD_IN_HOUSE.get(domain)
|
||
if not rows or not isinstance(house, int) or not 1 <= house <= 12:
|
||
return None
|
||
return HOUSE_LABEL[house - 1], rows[house - 1].format(who=_who(str(point.get("role") or "")))
|
||
if kind == "hora":
|
||
found = HORA_PORTRAIT.get(point.get("half"))
|
||
return found
|
||
if kind == "ascendant":
|
||
rows = ELEMENT_PORTRAIT.get(domain)
|
||
sign = point.get("sign_index")
|
||
return rows[sign % 4] if rows and isinstance(sign, int) else None
|
||
return None
|
||
|
||
|
||
def _key(point: dict[str, Any]) -> tuple:
|
||
return (point.get("kind"), point.get("planet"), point.get("house"), point.get("role"), point.get("half"), point.get("sign_index"))
|
||
|
||
|
||
def side_portrait(domain: str, own: dict[str, Any], other: dict[str, Any]) -> dict[str, Any]:
|
||
"""The portrait of one side: only points that differ from the other side; the domain's own planet first."""
|
||
other_keys = {_key(point) for point in other.get("points") or []}
|
||
differing = [point for point in own.get("points") or [] if _key(point) not in other_keys]
|
||
order = {"lord": 0, "hora": 0, "ascendant": 0, "occupant": 1}
|
||
differing.sort(key=lambda point: (order.get(point.get("kind"), 2), 0 if point.get("primary") else 1))
|
||
pieces = [found for point in differing if (found := point_portrait(domain, point))]
|
||
if not pieces:
|
||
return {"label": "", "sentences": []}
|
||
sentences: list[str] = []
|
||
for _, sentence in pieces:
|
||
if sentence not in sentences:
|
||
sentences.append(sentence)
|
||
if len(sentences) == 2:
|
||
break
|
||
return {"label": pieces[0][0], "sentences": sentences}
|
||
|
||
|
||
def plain_fact(point: dict[str, Any]) -> str:
|
||
"""The position for the folded 「依据」, as the owner approved: 「金星在第 10 宫(事业)」."""
|
||
from scripts.chart_choice.readings import PLANET_CN, SIGN_CN # noqa: PLC0415 - avoid an import cycle
|
||
kind = point.get("kind")
|
||
house = point.get("house")
|
||
place = f"第 {house} 宫({HOUSE_PLAIN[house - 1]})" if isinstance(house, int) and 1 <= house <= 12 else ""
|
||
if kind == "occupant" and place:
|
||
return f"{PLANET_CN.get(point.get('planet'), '')}在{place}"
|
||
if kind == "lord" and place:
|
||
return f"{point.get('role')}是{PLANET_CN.get(point.get('planet'), '')},在{place}"
|
||
if kind == "hora":
|
||
return "钱财盘只分太阳、月亮两半,这一边在" + ("太阳那一半" if point.get("half") == 4 else "月亮那一半")
|
||
if kind == "ascendant" and isinstance(point.get("sign_index"), int):
|
||
return f"这张盘从{SIGN_CN[point['sign_index'] % 12]}座起头"
|
||
return str(point.get("fact") or "")
|
||
|
||
|
||
# Last resort so the two sides never read the same: the element of the side's own starting sign
|
||
# (fire, earth, air, water). Neighbouring signs always differ in element, so the two sides of a line differ.
|
||
ELEMENT_STYLE: Final = (
|
||
("先动手再说", "做这件事通常先动起来,边做边看。"),
|
||
("求稳、看实际", "做这件事通常先求稳,看重实实在在的结果。"),
|
||
("多想几种办法", "做这件事通常多打听、多比较,想好几种办法。"),
|
||
("跟着感受走", "做这件事通常跟着感受走,很顾及身边的人。"),
|
||
)
|
||
|
||
|
||
def _basis(side: dict[str, Any]) -> list[str]:
|
||
lines: list[str] = []
|
||
asc = side.get("ascendant_index")
|
||
if isinstance(asc, int) and not any(point.get("kind") == "ascendant" for point in side.get("points") or []):
|
||
lines.append(plain_fact({"kind": "ascendant", "sign_index": asc}))
|
||
for point in side.get("points") or []:
|
||
text = plain_fact(point)
|
||
if text and text not in lines:
|
||
lines.append(text)
|
||
return lines
|
||
|
||
|
||
def _fallback(side: dict[str, Any]) -> dict[str, Any]:
|
||
asc = side.get("ascendant_index")
|
||
label, sentence = ELEMENT_STYLE[(asc if isinstance(asc, int) else 0) % 4]
|
||
return {"label": label, "sentences": [sentence]}
|
||
|
||
|
||
def comparison_portraits(domain: str, before: dict[str, Any], after: dict[str, Any]) -> dict[str, Any]:
|
||
"""The card question plus both sides' portraits and plain 「依据」; the two portraits never read the same."""
|
||
portraits = {"before": side_portrait(domain, before, after), "after": side_portrait(domain, after, before)}
|
||
sides = {"before": before, "after": after}
|
||
for side in ("before", "after"):
|
||
if not portraits[side]["sentences"]:
|
||
portraits[side] = _fallback(sides[side])
|
||
if portraits["before"]["label"] == portraits["after"]["label"] or portraits["before"]["sentences"] == portraits["after"]["sentences"]:
|
||
fallback = {side: _fallback(sides[side]) for side in ("before", "after")}
|
||
if fallback["before"] != fallback["after"]:
|
||
portraits = fallback
|
||
return {
|
||
"question": QUESTION.get(domain, "你更像哪一种?"),
|
||
"before": {**portraits["before"], "basis": _basis(before)},
|
||
"after": {**portraits["after"], "basis": _basis(after)},
|
||
}
|