fix: [dashboard] 날씨 위젯 단기+중기 데이터 병합 로직 개선
- 단기예보 기온 없는 날 중기예보 기온으로 보충 - 데이터 없는 날 '준비 중' 표시
This commit is contained in:
@@ -63,30 +63,36 @@ private function buildForecast(): array
|
||||
$midTa = $this->fetchMidTemperature();
|
||||
$midLand = $this->fetchMidLandForecast();
|
||||
|
||||
// 오늘부터 7일간 데이터 조합
|
||||
// 오늘부터 7일간 데이터 조합 (단기 + 중기 병합)
|
||||
$forecasts = [];
|
||||
for ($i = 0; $i < 7; $i++) {
|
||||
$date = $today->copy()->addDays($i)->format('Ymd');
|
||||
|
||||
// 단기예보 데이터 우선
|
||||
if (isset($short[$date])) {
|
||||
$forecasts[] = $short[$date];
|
||||
|
||||
continue;
|
||||
}
|
||||
$shortData = $short[$date] ?? null;
|
||||
|
||||
// 중기예보 데이터
|
||||
$tmn = $midTa["taMin{$i}"] ?? null;
|
||||
$tmx = $midTa["taMax{$i}"] ?? null;
|
||||
$wf = $midLand["wf{$i}Am"] ?? ($midLand["wf{$i}"] ?? '');
|
||||
$midTmn = $midTa["taMin{$i}"] ?? null;
|
||||
$midTmx = $midTa["taMax{$i}"] ?? null;
|
||||
$midWf = $midLand["wf{$i}Am"] ?? ($midLand["wf{$i}"] ?? '');
|
||||
|
||||
$forecasts[] = [
|
||||
'date' => $date,
|
||||
'tmn' => $tmn,
|
||||
'tmx' => $tmx,
|
||||
'icon' => ! empty($wf) ? $this->midWeatherToIcon($wf) : null,
|
||||
'weather_text' => $wf,
|
||||
];
|
||||
if ($shortData) {
|
||||
// 단기예보 우선, 기온이 없으면 중기로 보충
|
||||
$forecasts[] = [
|
||||
'date' => $date,
|
||||
'tmn' => $shortData['tmn'] ?? $midTmn,
|
||||
'tmx' => $shortData['tmx'] ?? $midTmx,
|
||||
'icon' => $shortData['icon'] ?? (! empty($midWf) ? $this->midWeatherToIcon($midWf) : null),
|
||||
'weather_text' => $shortData['weather_text'] ?: $midWf,
|
||||
];
|
||||
} else {
|
||||
$forecasts[] = [
|
||||
'date' => $date,
|
||||
'tmn' => $midTmn,
|
||||
'tmx' => $midTmx,
|
||||
'icon' => ! empty($midWf) ? $this->midWeatherToIcon($midWf) : null,
|
||||
'weather_text' => $midWf,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $forecasts;
|
||||
|
||||
Reference in New Issue
Block a user