Update
parent
a2da7a73cd
commit
025cea099e
|
|
@ -4,18 +4,12 @@ namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Enums\DeviceType;
|
use App\Enums\DeviceType;
|
||||||
use App\Models\Device;
|
use App\Models\Device;
|
||||||
use App\Models\MeteorologicalDailyReport;
|
|
||||||
use App\Models\MeteorologicalMonitoringDailyLog;
|
use App\Models\MeteorologicalMonitoringDailyLog;
|
||||||
use App\Models\MeteorologicalMonitoringLog;
|
use App\Models\MeteorologicalMonitoringLog;
|
||||||
use App\Models\MeteorologicalReport;
|
|
||||||
use App\Models\SoilDailyReport;
|
|
||||||
use App\Models\SoilMonitoringDailyLog;
|
use App\Models\SoilMonitoringDailyLog;
|
||||||
use App\Models\SoilMonitoringLog;
|
use App\Models\SoilMonitoringLog;
|
||||||
use App\Models\SoilReport;
|
|
||||||
use App\Models\WaterQualityDailyReport;
|
|
||||||
use App\Models\WaterQualityMonitoringDailyLog;
|
use App\Models\WaterQualityMonitoringDailyLog;
|
||||||
use App\Models\WaterQualityMonitoringLog;
|
use App\Models\WaterQualityMonitoringLog;
|
||||||
use App\Models\WaterQualityReport;
|
|
||||||
use App\Services\DeviceLogService;
|
use App\Services\DeviceLogService;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -412,8 +412,7 @@ class DeviceLogService
|
||||||
|
|
||||||
$attributes = value(function ($meteorologicalReports) {
|
$attributes = value(function ($meteorologicalReports) {
|
||||||
$data = [
|
$data = [
|
||||||
'today_rainfall' => ['sum' => 0, 'count' => 0],
|
'current_rainfall' => 0,
|
||||||
// 'yesterday_rainfall' => ['sum' => 0, 'count' => 0],
|
|
||||||
'accumulated_rainfall' => ['sum' => 0, 'count' => 0],
|
'accumulated_rainfall' => ['sum' => 0, 'count' => 0],
|
||||||
'moment_rainfall' => ['sum' => 0, 'count' => 0],
|
'moment_rainfall' => ['sum' => 0, 'count' => 0],
|
||||||
'pm10' => ['sum' => 0, 'count' => 0],
|
'pm10' => ['sum' => 0, 'count' => 0],
|
||||||
|
|
@ -424,6 +423,7 @@ class DeviceLogService
|
||||||
'air_temperature' => ['sum' => 0, 'count' => 0],
|
'air_temperature' => ['sum' => 0, 'count' => 0],
|
||||||
'air_humidity' => ['sum' => 0, 'count' => 0],
|
'air_humidity' => ['sum' => 0, 'count' => 0],
|
||||||
'noise' => ['sum' => 0, 'count' => 0],
|
'noise' => ['sum' => 0, 'count' => 0],
|
||||||
|
'wind_speed' => ['sum' => 0, 'count' => 0],
|
||||||
'wind_samples' => [],
|
'wind_samples' => [],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -439,8 +439,12 @@ class DeviceLogService
|
||||||
'wind_speed' => $meteorologicalReport->wind_speed, // 风速
|
'wind_speed' => $meteorologicalReport->wind_speed, // 风速
|
||||||
];
|
];
|
||||||
} elseif (! is_null($v = $meteorologicalReport->{$k})) {
|
} elseif (! is_null($v = $meteorologicalReport->{$k})) {
|
||||||
$item['sum'] = bcadd($item['sum'], $v, 2);
|
if ($k === 'current_rainfall') {
|
||||||
$item['count']++;
|
$item = $v;
|
||||||
|
} else {
|
||||||
|
$item['sum'] = bcadd($item['sum'], $v, 2);
|
||||||
|
$item['count']++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$data[$k] = $item;
|
$data[$k] = $item;
|
||||||
|
|
@ -451,63 +455,68 @@ class DeviceLogService
|
||||||
|
|
||||||
foreach ($data as $key => $item) {
|
foreach ($data as $key => $item) {
|
||||||
switch ($key) {
|
switch ($key) {
|
||||||
|
case 'current_rainfall':
|
||||||
|
$attributes['daily_rainfall'] = $item;
|
||||||
|
break;
|
||||||
case 'wind_samples':
|
case 'wind_samples':
|
||||||
$attributes['wind_degree'] = value(function (array $windSamples) {
|
if (! empty($item)) {
|
||||||
if (empty($windSamples)) {
|
$attributes['wind_degree'] = value(function (array $windSamples) {
|
||||||
return null;
|
if (empty($windSamples)) {
|
||||||
}
|
return null;
|
||||||
|
|
||||||
$x = 0;
|
|
||||||
$y = 0;
|
|
||||||
|
|
||||||
foreach ($windSamples as $sample) {
|
|
||||||
if ($sample['wind_degree'] == 0 && $sample['wind_speed'] == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 角度转弧度
|
$x = 0;
|
||||||
$radian = deg2rad($sample['wind_degree']);
|
$y = 0;
|
||||||
|
|
||||||
// $x += $sample['wind_speed'] * sin($radian);
|
foreach ($windSamples as $sample) {
|
||||||
// $y += $sample['wind_speed'] * cos($radian);
|
if ($sample['wind_degree'] == 0 && $sample['wind_speed'] == 0) {
|
||||||
$x += sin($radian);
|
continue;
|
||||||
$y += cos($radian);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$degree = round(rad2deg(atan2($y, $x)));
|
// 角度转弧度
|
||||||
|
$radian = deg2rad($sample['wind_degree']);
|
||||||
|
|
||||||
if (($x > 0 || $x < 0) && $y < 0) {
|
// $x += $sample['wind_speed'] * sin($radian);
|
||||||
$degree += 180;
|
// $y += $sample['wind_speed'] * cos($radian);
|
||||||
} elseif ($x < 0 && $y > 0) {
|
$x += sin($radian);
|
||||||
$degree += 360;
|
$y += cos($radian);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $degree;
|
$degree = round(rad2deg(atan2($y, $x)));
|
||||||
}, $item);
|
|
||||||
|
|
||||||
$attributes['wind_direction'] = value(function ($windDegree) {
|
if (($x > 0 || $x < 0) && $y < 0) {
|
||||||
if (is_null($windDegree)) {
|
$degree += 180;
|
||||||
return null;
|
} elseif ($x < 0 && $y > 0) {
|
||||||
}
|
$degree += 360;
|
||||||
|
}
|
||||||
|
|
||||||
if ($windDegree >= 22.5 && $windDegree < 67.5) {
|
return $degree;
|
||||||
return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_NORTHEAST;
|
}, $item);
|
||||||
} elseif ($windDegree >= 67.5 && $windDegree < 112.5) {
|
|
||||||
return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_EAST;
|
|
||||||
} elseif ($windDegree >= 112.5 && $windDegree < 157.5) {
|
|
||||||
return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_SOUTHEAST;
|
|
||||||
} elseif ($windDegree >= 157.5 && $windDegree < 202.5) {
|
|
||||||
return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_SOUTH;
|
|
||||||
} elseif ($windDegree >= 202.5 && $windDegree < 247.5) {
|
|
||||||
return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_SOUTHWEST;
|
|
||||||
} elseif ($windDegree >= 247.5 && $windDegree < 292.5) {
|
|
||||||
return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_WEST;
|
|
||||||
} elseif ($windDegree >= 292.5 && $windDegree < 337.5) {
|
|
||||||
return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_NORTHWEST;
|
|
||||||
}
|
|
||||||
|
|
||||||
return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_NORTH;
|
$attributes['wind_direction'] = value(function ($windDegree) {
|
||||||
}, $attributes['wind_degree']);
|
if (is_null($windDegree)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($windDegree >= 22.5 && $windDegree < 67.5) {
|
||||||
|
return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_NORTHEAST;
|
||||||
|
} elseif ($windDegree >= 67.5 && $windDegree < 112.5) {
|
||||||
|
return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_EAST;
|
||||||
|
} elseif ($windDegree >= 112.5 && $windDegree < 157.5) {
|
||||||
|
return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_SOUTHEAST;
|
||||||
|
} elseif ($windDegree >= 157.5 && $windDegree < 202.5) {
|
||||||
|
return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_SOUTH;
|
||||||
|
} elseif ($windDegree >= 202.5 && $windDegree < 247.5) {
|
||||||
|
return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_SOUTHWEST;
|
||||||
|
} elseif ($windDegree >= 247.5 && $windDegree < 292.5) {
|
||||||
|
return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_WEST;
|
||||||
|
} elseif ($windDegree >= 292.5 && $windDegree < 337.5) {
|
||||||
|
return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_NORTHWEST;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MeteorologicalMonitoringDailyLog::WIND_DIRECTION_NORTH;
|
||||||
|
}, $attributes['wind_degree']);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue