public function getSoilMoistureDailySummary($id) { $soilMin = Daily::where('sensor_id', 'like', $id)->min('minSoilMoisture'); $soilAverage = Daily::where('sensor_id', 'like', $id)->avg('avgSoilMoisture'); $soilMax = Daily::where('sensor_id', 'like', $id)->max('maxSoilMoisture'); return response()->json(['soilMin' => $soilMin, 'soilMax' => $soilMax, 'soilAverage' => $soilAverage]); }
$soilMoistureDailyMax = Daily::where('sensor_id', '=', $SensorPrimaryKey)->max('maxSoilMoisture'); $weekly = new Weekly(); $weekly->minLight = $lightDailyMin; $weekly->avgLight = $lightDailyAverage; $weekly->maxLight = $lightDailyMax; $weekly->minTemperature = $temperatureDailyMin; $weekly->avgTemperature = $temperatureDailyAverage; $weekly->maxTemperature = $temperatureDailyMax; $weekly->minAirHumidity = $humidityDailyMin; $weekly->avgAirHumidity = $humidityDailyAverage; $weekly->maxAirHumidity = $humidityDailyMax; $weekly->minSoilMoisture = $soilMoistureDailyMin; $weekly->avgSoilMoisture = $soilMoistureDailyAverage; $weekly->maxSoilMoisture = $soilMoistureDailyMax; $Sensor->weekly()->save($weekly); Daily::where('sensor_id', 'like', $SensorPrimaryKey)->delete(); $checkWeekly = Weekly::where('sensor_id', '=', $SensorPrimaryKey)->count(); if ($checkWeekly == 7) { $lightWeeklyMin = Weekly::where('sensor_id', '=', $SensorPrimaryKey)->min('minLight'); $lightWeeklyAverage = Weekly::where('sensor_id', '=', $SensorPrimaryKey)->avg('avgLight'); $lightWeeklyMax = Weekly::where('sensor_id', '=', $SensorPrimaryKey)->max('maxLight'); $temperatureWeeklyMin = Weekly::where('sensor_id', '=', $SensorPrimaryKey)->min('minTemperature'); $temperatureWeeklyAverage = Weekly::where('sensor_id', '=', $SensorPrimaryKey)->avg('avgTemperature'); $temperatureWeeklyMax = Weekly::where('sensor_id', '=', $SensorPrimaryKey)->max('maxTemperature'); $humidityWeeklyMin = Weekly::where('sensor_id', '=', $SensorPrimaryKey)->min('minAirHumidity'); $humidityWeeklyAverage = Weekly::where('sensor_id', '=', $SensorPrimaryKey)->avg('avgAirHumidity'); $humidityWeeklyMax = Weekly::where('sensor_id', '=', $SensorPrimaryKey)->max('maxAirHumidity'); $soilMoistureWeeklyMin = Weekly::where('sensor_id', '=', $SensorPrimaryKey)->min('minSoilMoisture'); $soilMoistureWeeklyAverage = Weekly::where('sensor_id', '=', $SensorPrimaryKey)->avg('avgSoilMoisture'); $soilMoistureWeeklyMax = Weekly::where('sensor_id', '=', $SensorPrimaryKey)->max('maxSoilMoisture'); $weeklyHistory = new WeeklyHistory();