feat: 사주 금전·일은 이번 주에 정할 날로, 올해 운에 잘 맞는 달, 레벨업 창에서 열린 칸으로 바로 가기
- 금전·일: 오늘 카드를 되풀이하지 않고 이번 주 중 결제·계약할 날, 돈 빌려주기 피할 날, 보고·면접 잡을 날 - 올해 운: 잘 맞는 달 3개, 11월부터는 다음 해 미리 보기 - 레벨업 창 '…보러 가기' → /saju#칸, 내 레벨 창의 각 모으는 일 줄을 누르면 그 화면으로 - 궁합 결과에 상대 생일과 다른 사람 보기
This commit is contained in:
1 parent
e4834fd24e
commit
cb013fcc9a
7 files changed
+121
-28
No files matched your search
@@ -90,6 +90,7 @@ class SajuPeriod(WebPacketProtocol):
|
||||
title: str
|
||||
body: str
|
||||
notes: list[str] = []
|
||||
months: list[int] = Field([], description="올해: 잘 맞는 달 (양력 달)")
|
||||
|
||||
|
||||
class SajuLock(WebPacketProtocol):
|
||||
@@ -103,8 +104,8 @@ class Res_Saju(Res_WebPacketProtocol):
|
||||
me: Optional[SajuMe] = None
|
||||
today: Optional[SajuToday] = None
|
||||
week: Optional[list[SajuDay]] = Field(None, description="레벨 2부터")
|
||||
money: Optional[str] = Field(None, description="레벨 3부터")
|
||||
work: Optional[str] = None
|
||||
money: Optional[list[str]] = Field(None, description="레벨 3부터: 이번 주 돈을 정할 날·피할 날")
|
||||
work: Optional[list[str]] = None
|
||||
love: Optional[SajuLove] = Field(None, description="레벨 4부터")
|
||||
month: Optional[SajuPeriod] = Field(None, description="레벨 6부터")
|
||||
year: Optional[SajuPeriod] = Field(None, description="레벨 7부터")
|
||||
|
||||
@@ -42,7 +42,7 @@ def _res(r: Reading) -> Res_Saju:
|
||||
love=SajuLove(good=SajuLoveDay(**r.love["good"]) if r.love.get("good") else None, caution=SajuLoveDay(**r.love["caution"]) if r.love.get("caution") else None,
|
||||
gender_known=r.love.get("gender") is not None) if r.love else None,
|
||||
month=SajuPeriod(label=f"이달 · {r.month['from']:%-m/%-d} {r.month['jeol']} ~ {r.month['until']:%-m/%-d}", **{k: r.month[k] for k in ("pillar", "ten_god", "title", "body", "notes")}) if r.month else None,
|
||||
year=SajuPeriod(label=f"{r.year['year']}년", **{k: r.year[k] for k in ("pillar", "ten_god", "title", "body", "notes")}) if r.year else None,
|
||||
year=SajuPeriod(label=f"{r.year['year']}년" + (" 미리 보기" if r.year["preview"] else ""), months=r.year["months"], **{k: r.year[k] for k in ("pillar", "ten_god", "title", "body", "notes")}) if r.year else None,
|
||||
level=r.level, logged_in=r.logged_in,
|
||||
locks=[SajuLock(key=k, name=n, level=lv, unlocked=r.logged_in and r.level >= lv) for lv, items in UNLOCKS.items() for k, n in items],
|
||||
)
|
||||
|
||||
@@ -14,7 +14,7 @@ from crud.week_crud import WeekCRUD
|
||||
from services import saju_text as T
|
||||
from services.level_service import award, level_of, unlock_level
|
||||
from services.saju.climate import HourWeather, chart_climate, climate_match
|
||||
from services.saju.daily import DailyFacts, daily_facts, interactions
|
||||
from services.saju.daily import DailyFacts, daily_facts, interactions, score as pillar_score
|
||||
from services.saju.ganji import branch_element, ko, stem_element
|
||||
from services.saju.pillars import Chart, Pillar, make_chart
|
||||
from services.saju.rules import branch_relations, stem_relations, ten_god
|
||||
@@ -254,6 +254,42 @@ def love_week(chart: Chart, week: list[DayReading], gender: Optional[Gender]) ->
|
||||
return out
|
||||
|
||||
|
||||
MONEY_GOOD, MONEY_BAD, WORK_GOOD = ("편재", "정재"), ("비견", "겁재"), ("정관", "편관", "정인", "상관")
|
||||
|
||||
|
||||
def _day_word(r: DayReading) -> str:
|
||||
return f"{_WEEKDAY[r.day.weekday()]} {r.day.day}일({T.TEN_GOD_TEXT[r.facts.stem_ten_god][0]})"
|
||||
|
||||
|
||||
def money_work(week: list[DayReading]) -> tuple[list[str], list[str]]:
|
||||
"""금전·일: 이번 주에 정할 날과 피할 날 (오늘 카드를 되풀이하지 않는다)"""
|
||||
def pick(gods: tuple[str, ...]) -> Optional[DayReading]:
|
||||
return next((r for r in week if r.facts.stem_ten_god in gods), None)
|
||||
|
||||
money, work = [], []
|
||||
if (g := pick(MONEY_GOOD)) is not None:
|
||||
money.append(f"큰 결제·계약은 {_day_word(g)}에 하세요.")
|
||||
if (b := pick(MONEY_BAD)) is not None:
|
||||
money.append(f"돈 빌려주기·공동 지출은 {_day_word(b)}엔 피하세요.")
|
||||
if (w := pick(WORK_GOOD)) is not None:
|
||||
work.append(f"보고·발표·면접은 {_day_word(w)}에 잡으세요.")
|
||||
if not money:
|
||||
money.append("이번 주는 돈이 크게 움직이는 날이 없어요. 평소대로 쓰세요.")
|
||||
if not work:
|
||||
work.append("이번 주는 하던 일을 마무리하기 좋아요.")
|
||||
return money, work
|
||||
|
||||
|
||||
def year_months(chart: Chart, year: int) -> list[int]:
|
||||
"""그해 열두 달(절 기준) 중 내 사주와 잘 맞는 달 셋 (달 번호는 그 절이 드는 양력 달)"""
|
||||
scored = []
|
||||
for m in range(1, 13):
|
||||
mp = make_chart(date(year, m, 15), time(12, 0)).month
|
||||
found = interactions(chart, mp)
|
||||
scored.append((pillar_score(chart, mp, found, [], False)[0], m))
|
||||
return sorted(m for _, m in sorted(scored, reverse=True)[:3])
|
||||
|
||||
|
||||
def period(chart: Chart, p: Pillar, unit: str) -> dict:
|
||||
"""이달·올해: 그 간지 천간 십성 + 원국과의 관계"""
|
||||
god = ten_god(chart.day.stem, p.stem)
|
||||
@@ -338,6 +374,12 @@ class SajuService:
|
||||
m = climate_match(chart, w.hours)
|
||||
return DayReading(day=d, facts=facts, weather=w, climate_score=m.score, best_hours=m.best_hours, reasons=m.reasons, score=total_score(facts.score, m.score))
|
||||
|
||||
def _year(self, chart: Chart, today: date) -> dict:
|
||||
"""올해 운. 11월부터는 다음 해 미리 보기 (입춘 뒤 날짜로 그해 간지)"""
|
||||
y = today.year + 1 if today.month >= 11 else today.year
|
||||
p = make_chart(date(y, 6, 1), time(12, 0)).year
|
||||
return {**period(chart, p, "해"), "year": y, "preview": y != today.year, "months": year_months(chart, y)}
|
||||
|
||||
async def match(
|
||||
self, me: tuple[date, Optional[time], float], friend: tuple[date, Optional[time], float], region_code: str, user: Optional[User],
|
||||
) -> tuple[ErrorType, Optional[Match]]:
|
||||
@@ -390,10 +432,10 @@ class SajuService:
|
||||
chart=chart, scene=scene, scene_icon=T.SCENE_ICON.get(chart_climate.label, "sun") if chart_climate else "sun",
|
||||
need=[T.NEED_WORD[n] for n in needs], today=r0, cards=cards, why=why_words(r0.facts), level=level, logged_in=user is not None,
|
||||
week=days if unlocked("saju_week") else None,
|
||||
money=T.MONEY_TEXT[r0.facts.stem_ten_god] if unlocked("saju_money") else None,
|
||||
work=T.WORK_TEXT[r0.facts.stem_ten_god] if unlocked("saju_money") else None,
|
||||
money=money_work(days)[0] if unlocked("saju_money") else None,
|
||||
work=money_work(days)[1] if unlocked("saju_money") else None,
|
||||
love=love_week(chart, days, gender) if unlocked("saju_love") else None,
|
||||
month={**period(chart, now_chart.month, "달"), "from": now_chart.jeol.at.date(), "until": now_chart.next_jeol.at.date(), "jeol": now_chart.jeol.name} if unlocked("saju_month") else None,
|
||||
year={**period(chart, now_chart.year, "해"), "year": today.year} if unlocked("saju_year") else None,
|
||||
year=self._year(chart, today) if unlocked("saju_year") else None,
|
||||
)
|
||||
|
||||
@@ -61,14 +61,14 @@ async def test_level_unlocks_sections_and_awards_once(offline):
|
||||
r = (await c.post("/v1/saju/reading", json={**BIRTH, "gender": "male"}, headers=h4)).json()
|
||||
assert r["level"] == 4
|
||||
assert len(r["week"]) == 7 and sum(d["best"] for d in r["week"]) == 1
|
||||
assert r["money"] and r["work"] and r["love"]["gender_known"] is True
|
||||
assert r["money"] and r["work"] and all(isinstance(x, str) for x in r["money"]) and r["love"]["gender_known"] is True
|
||||
assert "month" not in r and "year" not in r
|
||||
unlocked = {x["key"]: x["unlocked"] for x in r["locks"]}
|
||||
assert unlocked["saju_love"] and not unlocked["saju_match"]
|
||||
|
||||
h7 = await _login(c, "saju_07", points=1000)
|
||||
r = (await c.post("/v1/saju/reading", json=BIRTH, headers=h7)).json()
|
||||
assert r["month"]["title"].endswith("달") and r["year"]["label"].endswith("년")
|
||||
assert r["month"]["title"].endswith("달") and "년" in r["year"]["label"] and len(r["year"]["months"]) == 3
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
|
||||
Reference in new issue
Block a user