New Controllers added. Added Charts
This commit is contained in:
@@ -3,6 +3,10 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Charts;
|
||||
|
||||
use App\Stats;
|
||||
use App\Http\Requests;
|
||||
|
||||
class PagesController extends Controller
|
||||
{
|
||||
@@ -10,10 +14,72 @@ 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,
|
||||
]);
|
||||
}
|
||||
|
||||
|
36
Laravel/app/Http/Requests/StatsRequest.php
Normal file
36
Laravel/app/Http/Requests/StatsRequest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StatsRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'node_id' => 'required|integer',
|
||||
'pin' => 'required|integer',
|
||||
'humidity' => 'required|float',
|
||||
'temperature' => 'required|float',
|
||||
'isoutside' => 'required|integer',
|
||||
'gm3' => 'required|float',
|
||||
'created_at' => 'required|date',
|
||||
];
|
||||
}
|
||||
}
|
50
Laravel/app/Stats.php
Normal file
50
Laravel/app/Stats.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Stats extends Model
|
||||
{
|
||||
/**
|
||||
* The database table uses by the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'stats';
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dates = [
|
||||
'created_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'node_id',
|
||||
'pin',
|
||||
'humidity',
|
||||
'temperature',
|
||||
'isoutside',
|
||||
'gm3',
|
||||
'created_at'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = [
|
||||
//
|
||||
];
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user