[fix] site,solution/backend: 날씨 상태 라벨을 코드별 고유값으로 — 구간 뭉치기 제거
WMO weather_code 51~57(이슬비 3단계), 61~67(비/어는비 혼재) 등을 "이슬비"·"비" 같은 큰 구간으로 뭉쳐 표시하던 것을 코드 하나당 고유 라벨로 바꿨다. 서버 프리렌더 스냅샷(site_payload._WEATHER_CONDITION_BY_CODE)과 브라우저 재조회 (use-live-weather.ts WEATHER_CONDITION_BY_CODE)가 같은 표를 봐야 하이드레이션 전후로 문구가 안 바뀐다는 기존 불변식은 유지한다. - docs/WEATHER.md: 27개 코드 전체를 "구간→분류" 표에서 "코드→고유 라벨" 표로 재작성 - weather_notes.json: 코드별 문구 갱신 - use-live-weather.ts/.test.ts, weather.test.tsx: 새 라벨 반영
This commit is contained in:
1 parent
47da2f29b3
commit
cd771719df
5 files changed
+285
-104
No files matched your search
@@ -1,28 +1,44 @@
|
||||
import {expect, it} from 'vitest';
|
||||
import {condition} from './use-live-weather';
|
||||
|
||||
it('recognizes fog, showers and thunderstorms as distinct conditions', () => {
|
||||
expect(condition(45)).toBe('안개');
|
||||
expect(condition(48)).toBe('안개');
|
||||
expect(condition(80)).toBe('소나기');
|
||||
expect(condition(81)).toBe('소나기');
|
||||
expect(condition(82)).toBe('소나기');
|
||||
expect(condition(85)).toBe('소나기');
|
||||
expect(condition(86)).toBe('소나기');
|
||||
expect(condition(95)).toBe('뇌우');
|
||||
expect(condition(96)).toBe('뇌우');
|
||||
expect(condition(99)).toBe('뇌우');
|
||||
const WEATHER_CODE_LABELS: Record<number, string> = {
|
||||
0: '맑음',
|
||||
1: '대체로 맑음',
|
||||
2: '구름 조금',
|
||||
3: '흐림',
|
||||
45: '안개',
|
||||
48: '착빙성 안개',
|
||||
51: '가벼운 이슬비',
|
||||
53: '보통 이슬비',
|
||||
55: '강한 이슬비',
|
||||
56: '가벼운 착빙성 이슬비',
|
||||
57: '강한 착빙성 이슬비',
|
||||
61: '약한 비',
|
||||
63: '보통 비',
|
||||
65: '강한 비',
|
||||
66: '약한 착빙성 비',
|
||||
67: '강한 착빙성 비',
|
||||
71: '약한 눈',
|
||||
73: '보통 눈',
|
||||
75: '강한 눈',
|
||||
77: '싸라기눈',
|
||||
80: '약한 소나기',
|
||||
81: '보통 소나기',
|
||||
82: '강한 소나기',
|
||||
85: '약한 소나기눈',
|
||||
86: '강한 소나기눈',
|
||||
95: '뇌우',
|
||||
96: '약한 우박 뇌우',
|
||||
99: '강한 우박 뇌우',
|
||||
};
|
||||
|
||||
it('gives every WMO weather code its own label', () => {
|
||||
for (const [code, label] of Object.entries(WEATHER_CODE_LABELS)) {
|
||||
expect(condition(Number(code))).toBe(label);
|
||||
}
|
||||
});
|
||||
|
||||
it('splits rain into drizzle, normal, heavy and freezing', () => {
|
||||
expect(condition(51)).toBe('이슬비');
|
||||
expect(condition(53)).toBe('이슬비');
|
||||
expect(condition(55)).toBe('이슬비');
|
||||
expect(condition(61)).toBe('비');
|
||||
expect(condition(63)).toBe('비');
|
||||
expect(condition(65)).toBe('강한비');
|
||||
expect(condition(56)).toBe('어는비');
|
||||
expect(condition(57)).toBe('어는비');
|
||||
expect(condition(66)).toBe('어는비');
|
||||
expect(condition(67)).toBe('어는비');
|
||||
it('falls back to overcast for unknown codes', () => {
|
||||
expect(condition(4)).toBe('흐림');
|
||||
expect(condition(-1)).toBe('흐림');
|
||||
});
|
||||
@@ -5,18 +5,43 @@ export interface LiveWeather extends WeatherSnapshot {
|
||||
stale?: boolean;
|
||||
}
|
||||
|
||||
/** WMO weather code → 한 줄. ★ solution/backend/services/site_payload.py 의 _weather_condition() 과 같은 구간이어야 한다. */
|
||||
/**
|
||||
* WMO weather code → 한 줄. 코드 하나마다 고유 문구다(뭉치지 않는다) — ★
|
||||
* solution/backend/services/site_payload.py 의 _WEATHER_CONDITION_BY_CODE 와 같은 표여야 한다.
|
||||
*/
|
||||
const WEATHER_CONDITION_BY_CODE: Record<number, string> = {
|
||||
0: '맑음',
|
||||
1: '대체로 맑음',
|
||||
2: '구름 조금',
|
||||
3: '흐림',
|
||||
45: '안개',
|
||||
48: '착빙성 안개',
|
||||
51: '가벼운 이슬비',
|
||||
53: '보통 이슬비',
|
||||
55: '강한 이슬비',
|
||||
56: '가벼운 착빙성 이슬비',
|
||||
57: '강한 착빙성 이슬비',
|
||||
61: '약한 비',
|
||||
63: '보통 비',
|
||||
65: '강한 비',
|
||||
66: '약한 착빙성 비',
|
||||
67: '강한 착빙성 비',
|
||||
71: '약한 눈',
|
||||
73: '보통 눈',
|
||||
75: '강한 눈',
|
||||
77: '싸라기눈',
|
||||
80: '약한 소나기',
|
||||
81: '보통 소나기',
|
||||
82: '강한 소나기',
|
||||
85: '약한 소나기눈',
|
||||
86: '강한 소나기눈',
|
||||
95: '뇌우',
|
||||
96: '약한 우박 뇌우',
|
||||
99: '강한 우박 뇌우',
|
||||
};
|
||||
|
||||
export function condition(code: number): string {
|
||||
if (code === 0) return '맑음';
|
||||
if (code >= 1 && code <= 2) return '구름많음';
|
||||
if (code === 3) return '흐림';
|
||||
if (code === 45 || code === 48) return '안개';
|
||||
if (code >= 51 && code <= 57) return '이슬비';
|
||||
if (code >= 61 && code <= 67) return '비';
|
||||
if ((code >= 71 && code <= 77) || code === 85 || code === 86) return '눈';
|
||||
if (code >= 80 && code <= 82) return '소나기';
|
||||
if (code >= 95 && code <= 99) return '뇌우';
|
||||
return '흐림';
|
||||
return WEATHER_CONDITION_BY_CODE[code] ?? '흐림';
|
||||
}
|
||||
|
||||
/** 프리렌더 스냅샷으로 시작하고, 하이드레이션이 끝난 뒤에만 최신 캐시를 반영한다. */
|
||||
|
||||
@@ -12,20 +12,20 @@ function render(weather?: WeatherSnapshot) {
|
||||
}
|
||||
|
||||
it('uses the first sky and temperature lines for deterministic HTML', () => {
|
||||
const weather = {temperature: 30, observedAt: '2026-09-15T12:00', condition: '구름많음', noteSets: {'구름많음': ['구름 첫 줄', '다음 줄']}, tempNoteSets: {'혹서': ['더위 첫 줄']}};
|
||||
expect(render(weather)).toContain('구름 첫 줄');
|
||||
const weather = {temperature: 30, observedAt: '2026-09-15T12:00', condition: '대체로 맑음', noteSets: {'대체로 맑음': ['맑음 첫 줄', '다음 줄']}, tempNoteSets: {'혹서': ['더위 첫 줄']}};
|
||||
expect(render(weather)).toContain('맑음 첫 줄');
|
||||
expect(render(weather)).toContain('더위 첫 줄');
|
||||
expect(render(weather)).not.toContain('다음 줄');
|
||||
expect(render(weather)).toBe(render(weather));
|
||||
});
|
||||
|
||||
it('uses condition-specific notes for fog, showers and thunderstorms', () => {
|
||||
const weather = {temperature: 20, observedAt: '2026-09-15T12:00', condition: '소나기', noteSets: {'소나기': ['소나기 첫 줄']}, tempNoteSets: {'선선': ['선선 첫 줄']}};
|
||||
const weather = {temperature: 20, observedAt: '2026-09-15T12:00', condition: '보통 소나기', noteSets: {'보통 소나기': ['소나기 첫 줄']}, tempNoteSets: {'선선': ['선선 첫 줄']}};
|
||||
expect(render(weather)).toContain('소나기 첫 줄');
|
||||
});
|
||||
|
||||
it('uses condition-specific notes for the rain subtypes', () => {
|
||||
const weather = {temperature: 5, observedAt: '2026-09-15T12:00', condition: '어는비', noteSets: {'어는비': ['어는비 첫 줄'], '비': ['일반 비 첫 줄']}, tempNoteSets: {'추움': ['추움 첫 줄']}};
|
||||
const weather = {temperature: 5, observedAt: '2026-09-15T12:00', condition: '강한 착빙성 비', noteSets: {'강한 착빙성 비': ['어는비 첫 줄'], '보통 비': ['일반 비 첫 줄']}, tempNoteSets: {'추움': ['추움 첫 줄']}};
|
||||
expect(render(weather)).toContain('어는비 첫 줄');
|
||||
expect(render(weather)).not.toContain('일반 비 첫 줄');
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user