feat(supporters): 회복 일정 플래너 /plan · /en/plan · 시술별 회복 규칙표, 큐레이션 장소, 예약 딥링크, 헤더 내비 연결
- src/pages/plan.astro, src/pages/en/plan.astro: 한국어·영어 페이지, hreflang 상호 연결 - src/components/Planner.astro: 5단계 흐름(언어·국적 → 시술·수술일 → 선호 → 일정표 → 예약·저장), 브라우저 안 계산, URL 해시 공유, ICS 저장 - src/lib/plan.ts: 입국 권장일·출국 가능 최소일·외출 등급·식사 단계·추천 점수·딥링크·ICS 순수 함수 - src/data/procedures.json: 시술 8종 규칙표. 값마다 clinic/provisional 표시, 병원 확인 전 잠정값은 화면 배지 - src/data/places.json: 신논현역 기준 큐레이션 31곳 (구글 지도·예약 사이트 검색 링크만) - src/data/planStrings.json: UI 문자열 ko/en - scripts/gate/plan.test.mjs: 계산·데이터 정합성 검증 11건 - Base.astro: lang·alternates prop, 내비 '회복 일정', 푸터 링크. 구조 기준선 갱신(haewon 승인) - visit.astro: 플래너 진입 CTA 카드. sitemap에 /plan, /en/plan 추가 - 설계 근거: docs/INFINITH_Viewclinic_Supporters_Site_Design_v0.2.md §13 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
2eb3d5cd06
commit
e40f9ceb94
13 files changed
+1894
-4
No files matched your search
@@ -0,0 +1,173 @@
|
||||
// 회복기 스케줄러 계산 로직 (설계 v0.2 §13.3·§13.7·§13.8). 화면과 분리된 순수 함수만 둔다.
|
||||
// 입력: 시술 id, 수술일, 국적, 선호. 출력: 날짜별 외출 등급·식사·추천과 예약 링크. 서버 호출 없음.
|
||||
// 검증: node --experimental-strip-types scripts/gate/plan.test.mjs
|
||||
|
||||
export type Lang = 'ko' | 'en';
|
||||
export type L10n = Record<Lang, string>;
|
||||
export type Status = 'clinic' | 'provisional';
|
||||
export interface Valued { value: number | null; range?: [number, number]; status: Status; source?: string; note?: L10n }
|
||||
export interface LevelStep { fromDay: number; level: number; status: Status; source?: string; note?: L10n }
|
||||
export interface DietStep { fromDay: number; type: 'liquid' | 'soft' | 'mild' | 'normal'; status: Status; source?: string }
|
||||
export interface Procedure {
|
||||
id: string; label: L10n; group: L10n; readMore: string | null;
|
||||
preOpDays: Valued; hospitalNights: Valued; stitchRemovalDay: Valued; earliestDepartureDay: Valued;
|
||||
outingLevels: LevelStep[]; diet: DietStep[]; constraints: string[]; sources: string[];
|
||||
}
|
||||
export interface Place {
|
||||
id: string; name: L10n; category: string; minLevel: number; dietOk?: string[]; distanceKm: number; indoor: boolean;
|
||||
area: L10n; note: L10n; mapQuery: string | null; bookingQuery?: string; verify: boolean;
|
||||
}
|
||||
export interface Nationality { code: string; label: L10n; visaFreeDays: number | null; longHaul: boolean }
|
||||
|
||||
export interface PlanInput { procedure: Procedure; surgeryDate: string; nationality?: Nationality | null; prefs: string[] }
|
||||
export interface PlanDay { date: string; offset: number; level: number; diet: DietStep['type']; picks: Place[]; isSurgery: boolean; isHospital: boolean; isStitch: boolean; isArrival: boolean; isDeparture: boolean }
|
||||
export interface Plan {
|
||||
arriveBy: string; surgeryDate: string; dischargeDate: string | null; stitchDate: string | null; earliestDeparture: string | null;
|
||||
stayNights: number | null; preOpDays: number; days: PlanDay[];
|
||||
}
|
||||
|
||||
const DAY = 86_400_000;
|
||||
export const addDays = (iso: string, n: number): string => {
|
||||
const d = new Date(`${iso}T00:00:00Z`);
|
||||
return new Date(d.getTime() + n * DAY).toISOString().slice(0, 10);
|
||||
};
|
||||
export const isIsoDate = (s: unknown): s is string => typeof s === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(s) && !Number.isNaN(Date.parse(`${s}T00:00:00Z`));
|
||||
|
||||
/** fromDay 오름차순 단계표에서 offset 에 해당하는 단계. 첫 단계 이전이면 첫 단계. */
|
||||
function stepAt<T extends { fromDay: number }>(steps: T[], offset: number): T {
|
||||
const sorted = [...steps].sort((a, b) => a.fromDay - b.fromDay);
|
||||
let cur = sorted[0];
|
||||
for (const s of sorted) if (offset >= s.fromDay) cur = s;
|
||||
return cur;
|
||||
}
|
||||
|
||||
/** 장거리 국적은 시차 회복으로 준비일에 1일을 더한다 (§13.3). */
|
||||
export function effectivePreOpDays(p: Procedure, nat?: Nationality | null): number {
|
||||
const base = p.preOpDays.value ?? 2;
|
||||
return base + (nat?.longHaul ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 장소 점수. 선호 일치가 가장 크고, 등급이 딱 맞을수록, 가까울수록 높다.
|
||||
* 선호가 비어 있으면 카테고리 무관하게 거리와 등급만 본다.
|
||||
*/
|
||||
export function scorePlace(place: Place, level: number, diet: DietStep['type'], prefs: string[]): number {
|
||||
if (place.category === 'hotel') return -1;
|
||||
if (place.minLevel > level) return -1;
|
||||
if (place.category === 'food' && place.dietOk && !place.dietOk.includes(diet)) return -1;
|
||||
let s = 0;
|
||||
if (prefs.length === 0 || prefs.includes(place.category)) s += 3;
|
||||
if (place.category === 'essentials' || place.category === 'care') s += 1; // 회복에 직접 필요한 것은 기본 가점
|
||||
s += 2 - Math.min(2, level - place.minLevel); // 오늘 등급에 맞는 곳을 우선
|
||||
s += Math.max(0, 1.5 - place.distanceKm / 4); // 가까울수록 가점(최대 1.5)
|
||||
return s;
|
||||
}
|
||||
|
||||
/** 하루에 최대 3곳. 직전 2일에 나온 곳은 뒤로 미뤄 날마다 다른 곳이 나오게 한다. */
|
||||
export function pickForDay(places: Place[], level: number, diet: DietStep['type'], prefs: string[], recent: Set<string>, max = 3): Place[] {
|
||||
return places
|
||||
.map((p) => ({ p, s: scorePlace(p, level, diet, prefs) - (recent.has(p.id) ? 2.5 : 0) }))
|
||||
.filter((x) => x.s >= 0)
|
||||
.sort((a, b) => b.s - a.s || a.p.distanceKm - b.p.distanceKm)
|
||||
.slice(0, max)
|
||||
.map((x) => x.p);
|
||||
}
|
||||
|
||||
export function buildPlan(input: PlanInput, places: Place[]): Plan {
|
||||
const { procedure: p, surgeryDate, nationality, prefs } = input;
|
||||
const preOp = effectivePreOpDays(p, nationality);
|
||||
const arriveBy = addDays(surgeryDate, -preOp);
|
||||
const nights = p.hospitalNights.value;
|
||||
const dischargeDate = nights === null ? null : addDays(surgeryDate, nights);
|
||||
const stitchDate = p.stitchRemovalDay.value === null ? null : addDays(surgeryDate, p.stitchRemovalDay.value);
|
||||
const dep = p.earliestDepartureDay.value;
|
||||
const earliestDeparture = dep === null ? null : addDays(surgeryDate, dep);
|
||||
const lastOffset = dep ?? Math.max(14, ...p.outingLevels.map((l) => l.fromDay));
|
||||
const days: PlanDay[] = [];
|
||||
const recent: string[] = [];
|
||||
for (let off = -preOp; off <= lastOffset; off++) {
|
||||
const date = addDays(surgeryDate, off);
|
||||
const isHospital = nights !== null && off >= 0 && off < nights;
|
||||
const pre = off < 0;
|
||||
const level = pre ? 2 : isHospital ? 0 : stepAt(p.outingLevels, off).level;
|
||||
const diet = pre ? 'normal' : stepAt(p.diet, off).type;
|
||||
const recentSet = new Set(recent.slice(-6));
|
||||
const picks = level === 0 || off === 0 ? [] : pickForDay(places, level, diet, prefs, recentSet);
|
||||
recent.push(...picks.map((x) => x.id));
|
||||
days.push({ date, offset: off, level, diet, picks, isSurgery: off === 0, isHospital, isStitch: stitchDate === date, isArrival: off === -preOp, isDeparture: earliestDeparture === date });
|
||||
}
|
||||
return { arriveBy, surgeryDate, dischargeDate, stitchDate, earliestDeparture, stayNights: dep === null ? null : preOp + dep, preOpDays: preOp, days };
|
||||
}
|
||||
|
||||
// ---------- 예약 링크 (§13.7). 검색 결과 페이지 패턴만 쓴다. 제휴 ID 는 확정 후 aid 파라미터로 붙인다. ----------
|
||||
export function bookingUrl(query: string, checkin: string, checkout: string, lang: Lang, aid?: string): string {
|
||||
const u = new URL('https://www.booking.com/searchresults.html');
|
||||
u.searchParams.set('ss', query);
|
||||
u.searchParams.set('checkin', checkin);
|
||||
u.searchParams.set('checkout', checkout);
|
||||
u.searchParams.set('group_adults', '1');
|
||||
u.searchParams.set('no_rooms', '1');
|
||||
u.searchParams.set('lang', lang === 'ko' ? 'ko' : 'en-us');
|
||||
if (aid) u.searchParams.set('aid', aid);
|
||||
return u.toString();
|
||||
}
|
||||
export function googleFlightsUrl(arrive: string, depart: string, lang: Lang): string {
|
||||
const q = `Flights to ICN on ${arrive} returning ${depart}`;
|
||||
return `https://www.google.com/travel/flights?hl=${lang}&q=${encodeURIComponent(q)}`;
|
||||
}
|
||||
export function mapUrl(query: string): string {
|
||||
return `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(query)}`;
|
||||
}
|
||||
|
||||
// ---------- 공유 URL 해시 (서버 미전송) ----------
|
||||
export interface HashState { p?: string; d?: string; l?: Lang; n?: string; pref?: string[] }
|
||||
export function encodeHash(s: HashState): string {
|
||||
const q = new URLSearchParams();
|
||||
if (s.p) q.set('p', s.p);
|
||||
if (s.d) q.set('d', s.d);
|
||||
if (s.l) q.set('l', s.l);
|
||||
if (s.n) q.set('n', s.n);
|
||||
if (s.pref?.length) q.set('pref', s.pref.join(','));
|
||||
return q.toString();
|
||||
}
|
||||
export function decodeHash(hash: string): HashState {
|
||||
const q = new URLSearchParams(hash.replace(/^#/, ''));
|
||||
const l = q.get('l');
|
||||
return {
|
||||
p: q.get('p') ?? undefined,
|
||||
d: isIsoDate(q.get('d')) ? (q.get('d') as string) : undefined,
|
||||
l: l === 'ko' || l === 'en' ? l : undefined,
|
||||
n: q.get('n') ?? undefined,
|
||||
pref: (q.get('pref') ?? '').split(',').filter(Boolean),
|
||||
};
|
||||
}
|
||||
|
||||
// ---------- ICS (종일 일정 4개: 입국·수술·실밥·출국) ----------
|
||||
export function buildIcs(plan: Plan, titles: { arrive: string; surgery: string; stitch: string; departure: string }, calName: string): string {
|
||||
const ev = (date: string, title: string, uid: string) => [
|
||||
'BEGIN:VEVENT', `UID:${uid}@view-supporters`, `DTSTAMP:${new Date().toISOString().replace(/[-:]/g, '').slice(0, 15)}Z`,
|
||||
`DTSTART;VALUE=DATE:${date.replace(/-/g, '')}`, `DTEND;VALUE=DATE:${addDays(date, 1).replace(/-/g, '')}`, `SUMMARY:${title}`, 'END:VEVENT',
|
||||
];
|
||||
const lines = ['BEGIN:VCALENDAR', 'VERSION:2.0', 'PRODID:-//View Supporters//Recovery Planner//KO', `X-WR-CALNAME:${calName}`];
|
||||
lines.push(...ev(plan.arriveBy, titles.arrive, `arrive-${plan.arriveBy}`));
|
||||
lines.push(...ev(plan.surgeryDate, titles.surgery, `surgery-${plan.surgeryDate}`));
|
||||
if (plan.stitchDate) lines.push(...ev(plan.stitchDate, titles.stitch, `stitch-${plan.stitchDate}`));
|
||||
if (plan.earliestDeparture) lines.push(...ev(plan.earliestDeparture, titles.departure, `depart-${plan.earliestDeparture}`));
|
||||
lines.push('END:VCALENDAR');
|
||||
return lines.join('\r\n');
|
||||
}
|
||||
|
||||
/** 상담 신청에 붙여 보낼 요약문. */
|
||||
export function summaryText(plan: Plan, p: Procedure, lang: Lang, t: Record<string, string>): string {
|
||||
const pending = t.pending;
|
||||
const row = (k: string, v: string | null) => `${k}: ${v ?? pending}`;
|
||||
return [
|
||||
`${t.summaryTitle} (${p.label[lang]})`,
|
||||
row(t.arriveBy, plan.arriveBy),
|
||||
row(t.surgery, plan.surgeryDate),
|
||||
row(t.hospital, p.hospitalNights.value === null ? null : p.hospitalNights.value === 0 ? t.hospitalNone : t.hospitalNights.replace('{n}', String(p.hospitalNights.value))),
|
||||
row(t.stitch, plan.stitchDate),
|
||||
row(t.departure, plan.earliestDeparture),
|
||||
row(t.stayNights, plan.stayNights === null ? null : t.nights.replace('{n}', String(plan.stayNights))),
|
||||
].join('\n');
|
||||
}
|
||||
Reference in new issue
Block a user