- 화면 전체 스켈레톤, 로딩·완료·실패 사이 레이아웃 고정, 값 없음은 '?' - 행사 사진·출처 표시, 문화정보 API 전시 연결, 행사 30km 거리 기준 - 각 상세 점수 칸 오늘/내일/토/일, 단기예보 밖 주말은 중기예보 예상 점수 - 6각 차트 축 이름을 좋은 방향으로, 계산 근거 문구 정리 - 아이콘 오용·뜻 모를 표시·빈 데이터·포스트 본문 반복 수정 - 미세먼지 별도 포스트, 노을 명소 전국 155곳 거리 기준, 노을 탭 결론 중심 재구성 - 밤 다크 테마·별똥별, 댓글·좋아요 대기·실패 표시 - 주말 전국 랭킹·당일치기 카드, 계절 이야기 사진 수집 - 문서: 포스트 타입별 내용, 각 데이터 정리, TODO 진행 순서
96 lines
4.3 KiB
Python
96 lines
4.3 KiB
Python
import statistics
|
|
from dataclasses import dataclass
|
|
from datetime import datetime, timedelta
|
|
|
|
from common.enums import Confidence, SkyGrade, SkyType
|
|
|
|
DISTANCES_KM = (20, 50, 100)
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Layers:
|
|
low: float
|
|
mid: float
|
|
high: float
|
|
|
|
|
|
def score(near20: Layers, near50: Layers, far100: Layers) -> int:
|
|
"""머리 위(20·50km)는 중·상층 구름이 알맞게 있어야 물들고, 먼 쪽(100km)이 막히면 햇빛이 못 들어와 전체가 깎인다."""
|
|
canvas = (max(near20.mid, near20.high) + max(near50.mid, near50.high)) / 2
|
|
f_canvas = 0.3 if canvas < 10 else max(0.0, 1 - abs(canvas - 50) / 50)
|
|
f_near = 1 - 0.8 * (near20.low + near50.low) / 200
|
|
light = 1 - min(far100.low + 0.5 * far100.mid, 100) / 100
|
|
return round(100 * (0.75 * f_canvas + 0.25 * f_near) * (0.25 + 0.75 * light))
|
|
|
|
|
|
def grade(value: int) -> SkyGrade:
|
|
if value >= 80:
|
|
return SkyGrade.RED
|
|
if value >= 60:
|
|
return SkyGrade.GLOW
|
|
if value >= 40:
|
|
return SkyGrade.SOFT
|
|
return SkyGrade.GRAY
|
|
|
|
|
|
def confidence(model_scores: list[int]) -> Confidence:
|
|
"""모델끼리 점수가 비슷할수록 확신이 높다."""
|
|
if len(model_scores) < 2:
|
|
return Confidence.LOW
|
|
spread = statistics.pstdev(model_scores)
|
|
return Confidence.HIGH if spread < 8 else Confidence.NORMAL if spread < 15 else Confidence.LOW
|
|
|
|
|
|
def best_times(kind: SkyType, sun_at: datetime, twilight_at: datetime, high_cloud: float) -> list[dict]:
|
|
"""노을은 해 진 뒤 10~20분이 가장 붉다. 높은 구름이 많을수록 늦게까지 물든다."""
|
|
peak_min = 10 + round(min(high_cloud, 100) / 10)
|
|
sun_at, twilight_at = sun_at.replace(second=0, microsecond=0), twilight_at.replace(second=0, microsecond=0)
|
|
if kind is SkyType.SUNSET:
|
|
return [
|
|
{"at": sun_at.isoformat(), "kind": "sun", "label": "해 져요"},
|
|
{"at": (sun_at + timedelta(minutes=peak_min)).isoformat(), "kind": "peak", "label": "가장 붉을 때"},
|
|
{"at": twilight_at.isoformat(), "kind": "twilight", "label": "보랏빛 하늘"},
|
|
]
|
|
return [
|
|
{"at": twilight_at.isoformat(), "kind": "twilight", "label": "푸른 새벽"},
|
|
{"at": (sun_at - timedelta(minutes=peak_min)).isoformat(), "kind": "peak", "label": "가장 붉을 때"},
|
|
{"at": sun_at.isoformat(), "kind": "sun", "label": "해 떠요"},
|
|
]
|
|
|
|
|
|
GRADE_LABEL = {SkyGrade.RED: "붉음", SkyGrade.GLOW: "고움", SkyGrade.SOFT: "은은함", SkyGrade.GRAY: "잿빛"}
|
|
|
|
GO_SCORE = 60
|
|
MAYBE_SCORE = 40
|
|
VERDICT_LINE = {"go": "나가 볼 만해요", "maybe": "애매해요", "rest": "쉬어요"}
|
|
|
|
|
|
def verdict(value: int) -> str:
|
|
return "go" if value >= GO_SCORE else "maybe" if value >= MAYBE_SCORE else "rest"
|
|
|
|
|
|
def mean_layers(rows: list[Layers]) -> Layers:
|
|
return Layers(*(statistics.mean(getattr(r, k) for r in rows) for k in ("low", "mid", "high")))
|
|
|
|
|
|
def reason(near20: Layers, near50: Layers, far100: Layers) -> str:
|
|
"""score() 가 깎는 순서대로 본다: 먼 쪽 빛이 막혔나 → 머리 위 낮은 구름 → 물들 중·높은 구름의 양."""
|
|
if far100.low + 0.5 * far100.mid >= 60:
|
|
return "해 지는 쪽 먼 하늘이 구름에 막혀 빛이 못 들어와요"
|
|
if (near20.low + near50.low) / 2 >= 60:
|
|
return "낮은 구름이 머리 위를 덮어 붉은빛을 가려요"
|
|
canvas = round((max(near20.mid, near20.high) + max(near50.mid, near50.high)) / 2)
|
|
if canvas < 10:
|
|
return "물들 구름이 거의 없어 하늘이 은은하게 끝나요"
|
|
if canvas > 85:
|
|
return f"중·높은 구름이 {canvas}%로 두꺼워 빛이 덜 비쳐요"
|
|
if 25 <= canvas <= 75:
|
|
return f"중·높은 구름이 {canvas}% 알맞게 깔리고 해 지는 쪽이 트였어요"
|
|
return f"물들 중·높은 구름이 {canvas}%로 {'적은' if canvas < 25 else '많은'} 편이에요"
|
|
|
|
|
|
def sunset_timeline(golden_at: datetime, sun_at: datetime, peak_at: datetime | None, blue_at: datetime) -> list[dict]:
|
|
"""일몰 전 골든아워 → 해 짐 → 가장 붉을 때 → 블루아워. 분 아래는 버린다."""
|
|
rows = [("golden", "골든아워", golden_at), ("sun", "해 져요", sun_at), ("peak", "가장 붉을 때", peak_at), ("blue", "블루아워", blue_at)]
|
|
return [{"at": at.replace(second=0, microsecond=0).isoformat(), "kind": kind, "label": label} for kind, label, at in rows if at is not None]
|