Laravel display multiple node graphs

This commit is contained in:
2017-09-24 16:47:36 +02:00
parent 232b63c508
commit 3ab9b80e50

View File

@@ -14,54 +14,60 @@ class PagesController extends Controller
public function details() { public function details() {
$pagetitle = 'Details'; $pagetitle = 'Details';
$activeNav = 'details'; $activeNav = 'details';
$temperature = Stats::select('temperature')
->where('node_id', 1)
->limit('144')
->orderBy('created_at', 'desc')
->pluck('temperature');
$humidity = Stats::select('humidity')
->where('node_id', 1)
->limit('144')
->orderBy('created_at', 'desc')
->pluck('humidity');
$gm3 = Stats::select('gm3')
->where('node_id', 1)
->limit('144')
->orderBy('created_at', 'desc')
->pluck('gm3');
$created_at = Stats::select('created_at')
->where('node_id', 1)
->limit('144')
->orderBy('created_at', 'desc')
->pluck('created_at');
$latestTemp = Stats::select('temperature') $latestTemp = Stats::select('temperature')
->where('node_id', 1)
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->limit('1') ->limit('1')
->pluck('temperature'); ->pluck('temperature');
$latestHumidity = Stats::select('humidity') $latestHumidity = Stats::select('humidity')
->where('node_id', 1)
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->limit('1') ->limit('1')
->pluck('humidity'); ->pluck('humidity');
$latestGM3 = Stats::select('gm3') $latestGM3 = Stats::select('gm3')
->where('node_id', 1)
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->limit('1') ->limit('1')
->pluck('gm3'); ->pluck('gm3');
$latestTemp = '' . $latestTemp[0]; $latestTemp = '' . $latestTemp[0];
$latestHumidity = '' . $latestHumidity[0]; $latestHumidity = '' . $latestHumidity[0];
$latestGM3 = '' . $latestGM3[0]; $latestGM3 = '' . $latestGM3[0];
$chart[0] = Charts::multi('line', 'material')
->title("Temperatur, Luftfeuchtigkeit, g/m³")
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 ->dimensions(0, 400) // Width x Height
// This defines a preset of colors already done:) // This defines a preset of colors already done:)
->template("material") ->template("material")
@@ -73,6 +79,13 @@ public function details() {
->dataset('g/m³', $gm3) ->dataset('g/m³', $gm3)
// Setup what the values mean // Setup what the values mean
->labels($created_at); ->labels($created_at);
}
/*
$chart[1] = Charts::multi('line', 'material') $chart[1] = Charts::multi('line', 'material')
->title("Temperatur") ->title("Temperatur")
@@ -87,7 +100,7 @@ public function details() {
//->dataset('g/m³', $gm3) //->dataset('g/m³', $gm3)
// Setup what the values mean // Setup what the values mean
->labels($created_at); ->labels($created_at);
*/
return view('details')->with([ return view('details')->with([
'pagetitle' => $pagetitle, 'pagetitle' => $pagetitle,
'activeNav' => $activeNav, 'activeNav' => $activeNav,
@@ -105,16 +118,19 @@ public function details() {
//Db queries //Db queries
$latestTemp = Stats::select('temperature') $latestTemp = Stats::select('temperature')
->where('node_id', 1)
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->limit('1') ->limit('1')
->pluck('temperature'); ->pluck('temperature');
$latestHumidity = Stats::select('humidity') $latestHumidity = Stats::select('humidity')
->where('node_id', 1)
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->limit('1') ->limit('1')
->pluck('humidity'); ->pluck('humidity');
$latestGM3 = Stats::select('gm3') $latestGM3 = Stats::select('gm3')
->where('node_id', 1)
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->limit('1') ->limit('1')
->pluck('gm3'); ->pluck('gm3');
@@ -127,12 +143,21 @@ public function details() {
//prepare suggestion //prepare suggestion
$compareIDs = '1-2'; $compareIDs = '1-2';
$ids = explode('-', $compareIDs); $ids = explode('-', $compareIDs);
$latestTest = 11.0; //Outside $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 $lowerHumidityMode = true; //true --> suggestion lowers inside humidity; false --> suggestion heighten inside humidity
if ($lowerHumidityMode) { if ($lowerHumidityMode) {
($latestGM3 > $latestTest) ? $air = true : $air = false; ($compareGM3[0] > $compareGM3[1]) ? $air = true : $air = false;
} else { } else {
($latestGM3 < $latestTest) ? $air = true : $air = false; ($compareGM3[0] < $compareGM3[1]) ? $air = true : $air = false;
} }
return view('dashboard')->with([ return view('dashboard')->with([