feat: 사주 명식 카드 — 오행 세력 막대·가장 센 오행 그림, 신강·신약, 기둥별 십성·일간 '나'·월령, 용어 풀이 (API me.elements·strong·십성 추가, GA saju_view 에 strength·top_element)
This commit is contained in:
1 parent
63db0b725b
commit
d7f891fddb
14 files changed
+131
-15
No files matched your search
@@ -37,6 +37,8 @@ class SajuPillar(WebPacketProtocol):
|
||||
branch_ko: str
|
||||
stem_element: str = Field(description="木火土金水")
|
||||
branch_element: str
|
||||
stem_ten_god: Optional[str] = Field(None, description="천간 십성 (일간은 없음)")
|
||||
branch_ten_god: str = Field(description="지지 십성 (정기 기준)")
|
||||
|
||||
|
||||
class SajuMe(WebPacketProtocol):
|
||||
@@ -49,6 +51,10 @@ class SajuMe(WebPacketProtocol):
|
||||
season: Optional[str] = None
|
||||
climate: Optional[str] = Field(None, description="따뜻·마름 / 따뜻·촉촉 / 서늘·마름 / 서늘·촉촉")
|
||||
need: list[str] = Field([], description="내 기운에 필요한 것 (따뜻함·마른 공기 등)")
|
||||
elements: dict[str, float] = Field({}, description="오행 세력 점수 木火土金水 (월지 30·일지 20·나머지 10, 지지는 지장간 날 수로 나눔)")
|
||||
top_element: Optional[str] = Field(None, description="가장 센 오행")
|
||||
strong: Optional[bool] = Field(None, description="신강이면 true, 신약이면 false")
|
||||
support: Optional[float] = Field(None, description="일간을 뺀 점수 중 일간을 돕는 기운 몫 0~1")
|
||||
|
||||
|
||||
class SajuCard(WebPacketProtocol):
|
||||
|
||||
@@ -11,6 +11,8 @@ from router.v1.saju.protocol import Req_Saju, Req_SajuBirth, Req_SajuMatch, Res_
|
||||
from services import saju_text as T
|
||||
from services.level_service import UNLOCKS
|
||||
from services.saju.ganji import branch_element, ko, stem_element
|
||||
from services.saju.rules import chart_ten_gods
|
||||
from services.saju.strength import chart_strength
|
||||
from services.saju_service import Reading, SajuService, shown_saju, weather_points
|
||||
|
||||
router = APIRouter(prefix="/v1/saju", tags=["saju"])
|
||||
@@ -20,12 +22,16 @@ _WEEKDAY = "월화수목금토일"
|
||||
def _res(r: Reading) -> Res_Saju:
|
||||
c = r.chart
|
||||
pillars = [("year", c.year), ("month", c.month), ("day", c.day)] + ([("hour", c.hour)] if c.hour else [])
|
||||
gods = chart_ten_gods(c.day_stem, dict(pillars))
|
||||
strength = chart_strength(c)
|
||||
today = r.today
|
||||
best = max(r.week, key=lambda d: d.score).day if r.week else None
|
||||
return Res_Saju(
|
||||
me=SajuMe(
|
||||
pillars=[SajuPillar(position=pos, stem=p.stem, branch=p.branch, stem_ko=ko(p.stem), branch_ko=ko(p.branch), stem_element=stem_element(p.stem), branch_element=branch_element(p.branch)) for pos, p in pillars],
|
||||
pillars=[SajuPillar(position=pos, stem=p.stem, branch=p.branch, stem_ko=ko(p.stem), branch_ko=ko(p.branch), stem_element=stem_element(p.stem), branch_element=branch_element(p.branch),
|
||||
stem_ten_god=gods[pos]["stem"], branch_ten_god=gods[pos]["branch"]) for pos, p in pillars],
|
||||
hour_known=c.hour is not None, jeol_warning=c.jeol_on_birth_day, scene=r.scene[0], scene_desc=r.scene[1], scene_icon=r.scene_icon, need=r.need,
|
||||
elements=strength.elements, top_element=strength.top, strong=strength.strong, support=strength.support,
|
||||
),
|
||||
today=SajuToday(
|
||||
day=today.day, pillar=ko(today.facts.pillar.stem + today.facts.pillar.branch), ten_god=today.facts.stem_ten_god, title=T.TEN_GOD_TEXT[today.facts.stem_ten_god][0],
|
||||
|
||||
@@ -35,6 +35,8 @@ async def test_reading_for_anyone_gives_me_today_and_cards(offline):
|
||||
r = (await c.post("/v1/saju/reading", json=BIRTH)).json()
|
||||
assert [p["stem"] + p["branch"] for p in r["me"]["pillars"]] == ["乙亥", "己卯", "甲辰"] and r["me"]["hour_known"] is False
|
||||
assert r["me"]["scene"].endswith("기운") and r["today"]["title"] and 0 <= r["today"]["score"] <= 100
|
||||
assert [(p.get("stem_ten_god"), p["branch_ten_god"]) for p in r["me"]["pillars"]] == [("겁재", "편인"), ("정재", "겁재"), (None, "편재")]
|
||||
assert r["me"]["top_element"] == "木" and r["me"]["strong"] is True and r["me"]["elements"]["木"] == 58.3
|
||||
kinds = [x["kind"] for x in r["today"]["cards"]]
|
||||
assert "when" in kinds and "do" in kinds and "wear" in kinds
|
||||
# 근거 줄은 쉬운 말 + 괄호 용어, 숫자 없이
|
||||
|
||||
Reference in new issue
Block a user