From 29e4660cf6eef13d8d1c6cc5101b558b494f02c1 Mon Sep 17 00:00:00 2001 From: Jing Li Date: Fri, 4 Aug 2023 21:45:47 +0800 Subject: [PATCH] U --- app/Services/BiAngDeviceLogService.php | 31 ++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/app/Services/BiAngDeviceLogService.php b/app/Services/BiAngDeviceLogService.php index c1dfef7..8fa38e9 100644 --- a/app/Services/BiAngDeviceLogService.php +++ b/app/Services/BiAngDeviceLogService.php @@ -176,10 +176,33 @@ class BiAngDeviceLogService }; if ($attribute) { - if ($attribute == 'moment_rainfall') { - $attributes[$attribute] = bcadd($attributes[$attribute] ?? '0.00', $v, 2); - } else { - $attributes[$attribute] = $v; + switch ($attribute) { + case 'moment_rainfall': + $attributes[$attribute] = bcadd($attributes[$attribute] ?? '0.00', $v, 2); + break; + + case 'wind_degree': + $attributes[$attribute] = value(function ($v) { + if ($v >= 22.5 && $v < 67.5) { + return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_NORTHEAST; + } elseif ($v >= 67.5 && $v < 112.5) { + return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_EAST; + } elseif ($v >= 112.5 && $v < 157.5) { + return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_SOUTHEAST; + } elseif ($v >= 157.5 && $v < 202.5) { + return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_SOUTH; + } elseif ($v >= 202.5 && $v < 247.5) { + return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_SOUTHWEST; + } elseif ($v >= 247.5 && $v < 292.5) { + return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_WEST; + } elseif ($v >= 292.5 && $v < 337.5) { + return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_NORTHWEST; + } + return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_NORTH; + }, $v); + default: + $attributes[$attribute] = $v; + break; } } }