Merge remote-tracking branch 'origin/main' into feat/share-image
This commit is contained in:
commit
05d06e2e76
6 files changed
+144
-13
No files matched your search
@@ -5,6 +5,10 @@ from datetime import datetime, timedelta
|
||||
from common.enums import Confidence, SkyGrade, SkySituation, SkyType
|
||||
|
||||
DISTANCES_KM = (20, 100)
|
||||
# 물들 구름이 하나도 없을 때의 canvas 값. 50% 까지 곧게 올라가 맑은 날도 구름 몇 % 차이로 점수가 갈린다 (맑은 하늘 40점 = 은은함).
|
||||
_CLEAR_CANVAS = 0.2
|
||||
# 해 지기(뜨기) 이만큼 전 사이에 비가 왔다가 그 시각엔 개면 공기가 맑고 구름이 남아 더 붉다.
|
||||
RAIN_BEFORE_HOURS = (2, 6)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -14,15 +18,42 @@ class Layers:
|
||||
high: float
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Air:
|
||||
"""구 중심의 해 질(뜰) 무렵 공기. 값이 없으면 보정하지 않는다."""
|
||||
visibility_km: float | None = None
|
||||
humidity: float | None = None
|
||||
rain_before: int | None = None # RAIN_BEFORE_HOURS 사이 가장 높은 비 확률
|
||||
rain_now: int | None = None
|
||||
|
||||
|
||||
def score(near20: Layers, far100: Layers) -> int:
|
||||
"""머리 위(20km)는 중·상층 구름이 알맞게 있어야 물들고, 먼 쪽(100km)이 막히면 햇빛이 못 들어와 전체가 깎인다."""
|
||||
canvas = max(near20.mid, near20.high)
|
||||
f_canvas = 0.3 if canvas < 10 else max(0.0, 1 - abs(canvas - 50) / 50)
|
||||
f_canvas = _CLEAR_CANVAS + (1 - _CLEAR_CANVAS) * canvas / 50 if canvas <= 50 else max(0.0, 1 - (canvas - 50) / 50)
|
||||
f_near = 1 - 0.8 * near20.low / 100
|
||||
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 _ramp(v: float, bad: float, good: float, low: float) -> float:
|
||||
"""good 쪽은 1.0, bad 쪽은 low, 사이는 직선."""
|
||||
t = max(0.0, min(1.0, (v - bad) / (good - bad)))
|
||||
return low + (1 - low) * t
|
||||
|
||||
|
||||
def air_factor(air: Air) -> float:
|
||||
"""공기로 구름 점수를 보정하는 배수. 뿌연 공기·높은 습도는 색을 흐리게 하고, 비 갠 뒤는 더 붉다."""
|
||||
f = 1.0
|
||||
if air.visibility_km is not None:
|
||||
f *= _ramp(air.visibility_km, 5, 40, 0.6)
|
||||
if air.humidity is not None:
|
||||
f *= _ramp(air.humidity, 90, 50, 0.75)
|
||||
if air.rain_before is not None and air.rain_before >= 60 and (air.rain_now or 0) < 40:
|
||||
f *= 1.15
|
||||
return f
|
||||
|
||||
|
||||
def grade(value: int) -> SkyGrade:
|
||||
if value >= 80:
|
||||
return SkyGrade.RED
|
||||
|
||||
Reference in new issue
Block a user