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() {
$pagetitle = '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')
->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];
$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
// This defines a preset of colors already done:)
->template("material")
@@ -73,6 +79,13 @@ public function details() {
->dataset('g/m³', $gm3)
// Setup what the values mean
->labels($created_at);
}
/*
$chart[1] = Charts::multi('line', 'material')
->title("Temperatur")
@@ -87,7 +100,7 @@ public function details() {
//->dataset('g/m³', $gm3)
// Setup what the values mean
->labels($created_at);
*/
return view('details')->with([
'pagetitle' => $pagetitle,
'activeNav' => $activeNav,
@@ -105,16 +118,19 @@ public function details() {
//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');
@@ -127,12 +143,21 @@ public function details() {
//prepare suggestion
$compareIDs = '1-2';
$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
if ($lowerHumidityMode) {
($latestGM3 > $latestTest) ? $air = true : $air = false;
($compareGM3[0] > $compareGM3[1]) ? $air = true : $air = false;
} else {
($latestGM3 < $latestTest) ? $air = true : $air = false;
($compareGM3[0] < $compareGM3[1]) ? $air = true : $air = false;
}
return view('dashboard')->with([