87 lines
3.0 KiB
PHP
87 lines
3.0 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 dashboard() {
|
|
$pagetitle = 'Dashboard';
|
|
$activeNav = 'dashboard';
|
|
|
|
$temperature = Stats::select('temperature')
|
|
->limit('1440')
|
|
->orderBy('created_at', 'desc')
|
|
->pluck('temperature');
|
|
|
|
$humidity = Stats::select('humidity')
|
|
->limit('1440')
|
|
->orderBy('created_at', 'desc')
|
|
->pluck('humidity');
|
|
|
|
$gm3 = Stats::select('gm3')
|
|
->limit('1440')
|
|
->orderBy('created_at', 'desc')
|
|
->pluck('gm3');
|
|
|
|
$created_at = Stats::select('created_at')
|
|
->limit('1440')
|
|
->orderBy('created_at', 'desc')
|
|
->pluck('created_at');
|
|
|
|
$latestTemp = Stats::select('temperature')
|
|
->orderBy('created_at', 'desc')
|
|
->limit('1')
|
|
->pluck('temperature');
|
|
|
|
$latestHumidity = Stats::select('humidity')
|
|
->orderBy('created_at', 'desc')
|
|
->limit('1')
|
|
->pluck('humidity');
|
|
|
|
$latestGM3 = Stats::select('gm3')
|
|
->orderBy('created_at', 'desc')
|
|
->limit('1')
|
|
->pluck('gm3');
|
|
|
|
|
|
|
|
$latestTemp = '' . $latestTemp[0];
|
|
$latestHumidity = '' . $latestHumidity[0];
|
|
$latestGM3 = '' . $latestGM3[0];
|
|
|
|
$latestShit = 'Temp: ' . $latestTemp . ' Hum: ' . $latestHumidity . ' g/m³: ' . $latestGM3;
|
|
|
|
$chart = Charts::multi('line', 'material')
|
|
->title("Temperatur, Luftfeuchtigkeit, 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('Temperatur', $temperature)
|
|
->dataset('Luftfeuchtigkeit', $humidity)
|
|
->dataset('g/m³', $gm3)
|
|
// Setup what the values mean
|
|
->labels($created_at);
|
|
|
|
return view('dashboard')->with([
|
|
'pagetitle' => $pagetitle,
|
|
'activeNav' => $activeNav,
|
|
'chart' => $chart,
|
|
'latestTemp' => $latestTemp,
|
|
'latestHumidity' => $latestHumidity,
|
|
'latestGM3' => $latestGM3,
|
|
'latestShit' => $latestShit,
|
|
]);
|
|
}
|
|
|
|
}
|