175 lines
6.1 KiB
PHP
175 lines
6.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Charts;
|
|
|
|
use App\Stats;
|
|
use App\Http\Requests;
|
|
|
|
class PagesController extends Controller
|
|
{
|
|
//
|
|
public function details() {
|
|
$pagetitle = 'Details';
|
|
$activeNav = 'details';
|
|
|
|
|
|
$latestTemp = Stats::select('temperature')
|
|
->where('node_id', 1)
|
|
->orderBy('created_at', 'desc')
|
|
->limit('1')
|
|
->pluck('temperature');
|
|
|
|
$latestHumidity = Stats::select('humidity')
|
|
->where('node_id', 1)
|
|
->orderBy('created_at', 'desc')
|
|
->limit('1')
|
|
->pluck('humidity');
|
|
|
|
$latestGM3 = Stats::select('gm3')
|
|
->where('node_id', 1)
|
|
->orderBy('created_at', 'desc')
|
|
->limit('1')
|
|
->pluck('gm3');
|
|
|
|
$latestTemp = '' . $latestTemp[0];
|
|
$latestHumidity = '' . $latestHumidity[0];
|
|
$latestGM3 = '' . $latestGM3[0];
|
|
|
|
|
|
|
|
for ($i = 1; $i <= 2; $i++) {
|
|
|
|
$temperature = Stats::select('temperature')
|
|
->where('node_id', $i)
|
|
->limit('144')
|
|
->orderBy('created_at', 'desc')
|
|
->pluck('temperature');
|
|
|
|
$humidity = Stats::select('humidity')
|
|
->where('node_id', $i)
|
|
->limit('144')
|
|
->orderBy('created_at', 'desc')
|
|
->pluck('humidity');
|
|
|
|
$gm3 = Stats::select('gm3')
|
|
->where('node_id', $i)
|
|
->limit('144')
|
|
->orderBy('created_at', 'desc')
|
|
->pluck('gm3');
|
|
|
|
$created_at = Stats::select('created_at')
|
|
->where('node_id', $i)
|
|
->limit('144')
|
|
->orderBy('created_at', 'desc')
|
|
->pluck('created_at');
|
|
|
|
$chart[$i - 1] = Charts::multi('line', 'material')
|
|
->title('Zusammenfassung Node ' . $i . ' (°C, %, g/m³)')
|
|
->dimensions(0, 400) // Width x Height
|
|
// This defines a preset of colors already done:)
|
|
->template("material")
|
|
// You could always set them manually
|
|
// ->colors(['#2196F3', '#F44336', '#FFC107'])
|
|
// Setup the diferent datasets (this is a multi chart)
|
|
->dataset('°C', $temperature)
|
|
->dataset('%', $humidity)
|
|
->dataset('g/m³', $gm3)
|
|
// Setup what the values mean
|
|
->labels($created_at);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
$chart[1] = Charts::multi('line', 'material')
|
|
->title("Temperatur")
|
|
->dimensions(0, 400) // Width x Height
|
|
// This defines a preset of colors already done:)
|
|
->template("material")
|
|
// You could always set them manually
|
|
// ->colors(['#2196F3', '#F44336', '#FFC107'])
|
|
// Setup the diferent datasets (this is a multi chart)
|
|
->dataset('°C', $temperature)
|
|
//->dataset('%', $humidity)
|
|
//->dataset('g/m³', $gm3)
|
|
// Setup what the values mean
|
|
->labels($created_at);
|
|
*/
|
|
return view('details')->with([
|
|
'pagetitle' => $pagetitle,
|
|
'activeNav' => $activeNav,
|
|
'chart' => $chart,
|
|
'latestTemp' => $latestTemp,
|
|
'latestHumidity' => $latestHumidity,
|
|
'latestGM3' => $latestGM3,
|
|
]);
|
|
}
|
|
|
|
public function dashboard() {
|
|
$pagetitle = 'Dashboard';
|
|
$activeNav = 'dashboard';
|
|
|
|
|
|
//Db queries
|
|
$latestTemp = Stats::select('temperature')
|
|
->where('node_id', 1)
|
|
->orderBy('created_at', 'desc')
|
|
->limit('1')
|
|
->pluck('temperature');
|
|
|
|
$latestHumidity = Stats::select('humidity')
|
|
->where('node_id', 1)
|
|
->orderBy('created_at', 'desc')
|
|
->limit('1')
|
|
->pluck('humidity');
|
|
|
|
$latestGM3 = Stats::select('gm3')
|
|
->where('node_id', 1)
|
|
->orderBy('created_at', 'desc')
|
|
->limit('1')
|
|
->pluck('gm3');
|
|
|
|
//Pick values from array
|
|
$latestTemp = $latestTemp[0];
|
|
$latestHumidity = $latestHumidity[0];
|
|
$latestGM3 = $latestGM3[0];
|
|
|
|
//prepare suggestion
|
|
$compareIDs = '1-2';
|
|
$ids = explode('-', $compareIDs);
|
|
$z = 0;
|
|
|
|
foreach ($ids as $values) {
|
|
$compareGM3[$z++] = Stats::select('gm3')
|
|
->where('node_id', $values)
|
|
->orderBy('created_at', 'desc')
|
|
->limit('1')
|
|
->pluck('gm3');
|
|
}
|
|
|
|
$lowerHumidityMode = true; //true --> suggestion lowers inside humidity; false --> suggestion heighten inside humidity
|
|
if ($lowerHumidityMode) {
|
|
($compareGM3[0] > $compareGM3[1]) ? $air = true : $air = false;
|
|
} else {
|
|
($compareGM3[0] < $compareGM3[1]) ? $air = true : $air = false;
|
|
}
|
|
|
|
return view('dashboard')->with([
|
|
'pagetitle' => $pagetitle,
|
|
'activeNav' => $activeNav,
|
|
'latestTemp' => $latestTemp,
|
|
'latestHumidity' => $latestHumidity,
|
|
'latestGM3' => $latestGM3,
|
|
'air' => $air,
|
|
]);
|
|
}
|
|
|
|
|
|
}
|