diff --git a/Laravel/.env b/Laravel/.env new file mode 100644 index 0000000..d184184 --- /dev/null +++ b/Laravel/.env @@ -0,0 +1,33 @@ +APP_NAME=Laravel +APP_ENV=local +APP_KEY=base64:yiCZrXkhkUItoott+xl/5gpJhgrl1kCkGHfywwHNuxs= +APP_DEBUG=true +APP_LOG_LEVEL=debug +APP_URL=http://localhost + +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=dhtstats +DB_USERNAME=dhtuser +DB_PASSWORD=raspberry + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +SESSION_DRIVER=file +QUEUE_DRIVER=sync + +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_DRIVER=smtp +MAIL_HOST=smtp.mailtrap.io +MAIL_PORT=2525 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= diff --git a/Laravel/app/Http/Controllers/PagesController.php b/Laravel/app/Http/Controllers/PagesController.php index 4ee3227..fc39d5a 100644 --- a/Laravel/app/Http/Controllers/PagesController.php +++ b/Laravel/app/Http/Controllers/PagesController.php @@ -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, ]); } diff --git a/Laravel/app/Http/Requests/StatsRequest.php b/Laravel/app/Http/Requests/StatsRequest.php new file mode 100644 index 0000000..ba56710 --- /dev/null +++ b/Laravel/app/Http/Requests/StatsRequest.php @@ -0,0 +1,36 @@ + 'required|integer', + 'pin' => 'required|integer', + 'humidity' => 'required|float', + 'temperature' => 'required|float', + 'isoutside' => 'required|integer', + 'gm3' => 'required|float', + 'created_at' => 'required|date', + ]; + } +} diff --git a/Laravel/app/Stats.php b/Laravel/app/Stats.php new file mode 100644 index 0000000..1adbc0f --- /dev/null +++ b/Laravel/app/Stats.php @@ -0,0 +1,50 @@ +=7.0.0", + "consoletvs/charts": "5.*", "fideloper/proxy": "~3.3", "laravel/framework": "5.5.*", "laravel/tinker": "~1.0" diff --git a/Laravel/composer.lock b/Laravel/composer.lock index 5fa2d57..c98e21a 100644 --- a/Laravel/composer.lock +++ b/Laravel/composer.lock @@ -4,8 +4,57 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "8f2120fa77d42a42b4210cdbe1c114e2", + "content-hash": "ffd0258eb25bcccc681eb1cbe2d657e9", "packages": [ + { + "name": "consoletvs/charts", + "version": "5.0.2", + "source": { + "type": "git", + "url": "https://github.com/ConsoleTVs/Charts.git", + "reference": "954e969c974ad9cd53a6afd263824b33dcdb8540" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ConsoleTVs/Charts/zipball/954e969c974ad9cd53a6afd263824b33dcdb8540", + "reference": "954e969c974ad9cd53a6afd263824b33dcdb8540", + "shasum": "" + }, + "require": { + "illuminate/support": "5.*", + "jenssegers/date": "v3.*", + "jlawrence/eos": "3.*", + "php": ">=5.6.4" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "ConsoleTVs\\Charts\\ChartsServiceProvider" + ], + "aliases": { + "Charts": "ConsoleTVs\\Charts\\Facades\\Charts" + } + } + }, + "autoload": { + "psr-4": { + "ConsoleTVs\\Charts\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Erik Campobadal", + "email": "soc@erik.cat" + } + ], + "description": "Create charts for laravel using diferent charts libraries", + "time": "2017-08-14T11:10:46+00:00" + }, { "name": "dnoegel/php-xdg-base-dir", "version": "0.1", @@ -403,6 +452,114 @@ ], "time": "2015-04-20T18:58:01+00:00" }, + { + "name": "jenssegers/date", + "version": "v3.2.12", + "source": { + "type": "git", + "url": "https://github.com/jenssegers/date.git", + "reference": "1db4d580d1d45085a48fd4a332697619b9a3851c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jenssegers/date/zipball/1db4d580d1d45085a48fd4a332697619b9a3851c", + "reference": "1db4d580d1d45085a48fd4a332697619b9a3851c", + "shasum": "" + }, + "require": { + "nesbot/carbon": "^1.0", + "php": ">=5.4", + "symfony/translation": "^2.7|^3.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0|^5.0|^6.0", + "satooshi/php-coveralls": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + }, + "laravel": { + "providers": [ + "Jenssegers\\Date\\DateServiceProvider" + ], + "aliases": { + "Date": "Jenssegers\\Date\\Date" + } + } + }, + "autoload": { + "psr-4": { + "Jenssegers\\Date\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jens Segers", + "homepage": "https://jenssegers.com" + } + ], + "description": "A date library to help you work with dates in different languages", + "homepage": "https://github.com/jenssegers/date", + "keywords": [ + "carbon", + "date", + "datetime", + "i18n", + "laravel", + "time", + "translation" + ], + "time": "2017-06-30T11:51:03+00:00" + }, + { + "name": "jlawrence/eos", + "version": "v3.2.2", + "source": { + "type": "git", + "url": "https://github.com/jlawrence11/eos.git", + "reference": "25e3d0f2316cb4636000f452a8e7dcc83725a32a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jlawrence11/eos/zipball/25e3d0f2316cb4636000f452a8e7dcc83725a32a", + "reference": "25e3d0f2316cb4636000f452a8e7dcc83725a32a", + "shasum": "" + }, + "require-dev": { + "codeclimate/php-test-reporter": "dev-master", + "phpunit/phpunit": "4.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "jlawrence\\eos\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1+" + ], + "authors": [ + { + "name": "Jon Lawrence", + "email": "jon@jon-lawrence.com" + } + ], + "description": "Parse and solve math equations without using 'eval()'.", + "keywords": [ + "eos", + "equations", + "math", + "solve" + ], + "time": "2016-03-02T22:35:41+00:00" + }, { "name": "laravel/framework", "version": "v5.5.4", diff --git a/Laravel/config/app.php b/Laravel/config/app.php index 0e4ebed..b3d185f 100644 --- a/Laravel/config/app.php +++ b/Laravel/config/app.php @@ -176,7 +176,9 @@ return [ // App\Providers\BroadcastServiceProvider::class, App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, + + ], /* diff --git a/Laravel/config/charts.php b/Laravel/config/charts.php new file mode 100644 index 0000000..5fa47c0 --- /dev/null +++ b/Laravel/config/charts.php @@ -0,0 +1,191 @@ + [ + 'type' => 'line', // The default chart type. + 'library' => 'material', // The default chart library. + 'element_label' => 'Element', // The default chart element label. + 'empty_dataset_label' => 'No Data Set', + 'empty_dataset_value' => 0, + 'title' => 'My Cool Chart', // Default chart title. + 'height' => 400, // 0 Means it will take 100% of the division height. + 'width' => 0, // 0 Means it will take 100% of the division width. + 'responsive' => false, // Not recommended since all libraries have diferent sizes. + 'background_color' => 'inherit', // The chart division background color. + 'colors' => [], // Default chart colors if using no template is set. + 'one_color' => false, // Only use the first color in all values. + 'template' => 'material', // The default chart color template. + 'legend' => true, // Whether to enable the chart legend (where applicable). + 'x_axis_title' => false, // The title of the x-axis + 'y_axis_title' => null, // The title of the y-axis (When set to null will use element_label value). + 'loader' => [ + 'active' => true, // Determines the if loader is active by default. + 'duration' => 500, // In milliseconds. + 'color' => '#000000', // Determines the default loader color. + ], + ], + + /* + |-------------------------------------------------------------------------- + | All the color templates available for the charts. + |-------------------------------------------------------------------------- + */ + 'templates' => [ + 'material' => [ + '#2196F3', '#F44336', '#FFC107', + ], + 'red-material' => [ + '#B71C1C', '#F44336', '#E57373', + ], + 'indigo-material' => [ + '#1A237E', '#3F51B5', '#7986CB', + ], + 'blue-material' => [ + '#0D47A1', '#2196F3', '#64B5F6', + ], + 'teal-material' => [ + '#004D40', '#009688', '#4DB6AC', + ], + 'green-material' => [ + '#1B5E20', '#4CAF50', '#81C784', + ], + 'yellow-material' => [ + '#F57F17', '#FFEB3B', '#FFF176', + ], + 'orange-material' => [ + '#E65100', '#FF9800', '#FFB74D', + ], + ], + + /* + |-------------------------------------------------------------------------- + | Assets required by the libraries. + |-------------------------------------------------------------------------- + */ + + 'assets' => [ + 'global' => [ + 'scripts' => [ + 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js', + ], + ], + + 'canvas-gauges' => [ + 'scripts' => [ + 'https://cdn.rawgit.com/Mikhus/canvas-gauges/gh-pages/download/2.1.2/all/gauge.min.js', + ], + ], + + 'chartist' => [ + 'scripts' => [ + 'https://cdnjs.cloudflare.com/ajax/libs/chartist/0.10.1/chartist.min.js', + ], + 'styles' => [ + 'https://cdnjs.cloudflare.com/ajax/libs/chartist/0.10.1/chartist.min.css', + ], + ], + + 'chartjs' => [ + 'scripts' => [ + 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js', + ], + ], + + 'fusioncharts' => [ + 'scripts' => [ + 'https://static.fusioncharts.com/code/latest/fusioncharts.js', + 'https://static.fusioncharts.com/code/latest/themes/fusioncharts.theme.fint.js', + ], + ], + + 'google' => [ + 'scripts' => [ + 'https://www.google.com/jsapi', + 'https://www.gstatic.com/charts/loader.js', + "google.charts.load('current', {'packages':['corechart', 'gauge', 'geochart', 'bar', 'line']})", + ], + ], + + 'highcharts' => [ + 'styles' => [ + // The following CSS is not added due to color compatibility errors. + // 'https://cdnjs.cloudflare.com/ajax/libs/highcharts/5.0.7/css/highcharts.css', + ], + 'scripts' => [ + 'https://cdnjs.cloudflare.com/ajax/libs/highcharts/5.0.7/highcharts.js', + 'https://cdnjs.cloudflare.com/ajax/libs/highcharts/5.0.7/js/modules/offline-exporting.js', + 'https://cdnjs.cloudflare.com/ajax/libs/highmaps/5.0.7/js/modules/map.js', + 'https://cdnjs.cloudflare.com/ajax/libs/highmaps/5.0.7/js/modules/data.js', + 'https://code.highcharts.com/mapdata/custom/world.js', + ], + ], + + 'justgage' => [ + 'scripts' => [ + 'https://cdnjs.cloudflare.com/ajax/libs/raphael/2.2.6/raphael.min.js', + 'https://cdnjs.cloudflare.com/ajax/libs/justgage/1.2.2/justgage.min.js', + ], + ], + + 'morris' => [ + 'styles' => [ + 'https://cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css', + ], + 'scripts' => [ + 'https://cdnjs.cloudflare.com/ajax/libs/raphael/2.2.6/raphael.min.js', + 'https://cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js', + ], + ], + + 'plottablejs' => [ + 'scripts' => [ + 'https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js', + 'https://cdnjs.cloudflare.com/ajax/libs/plottable.js/2.8.0/plottable.min.js', + ], + 'styles' => [ + 'https://cdnjs.cloudflare.com/ajax/libs/plottable.js/2.2.0/plottable.css', + ], + ], + + 'progressbarjs' => [ + 'scripts' => [ + 'https://cdnjs.cloudflare.com/ajax/libs/progressbar.js/1.0.1/progressbar.min.js', + ], + ], + + 'c3' => [ + 'scripts' => [ + 'https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js', + 'https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.11/c3.min.js', + ], + 'styles' => [ + 'https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.11/c3.min.css', + ], + ], + + 'echarts' => [ + 'scripts' => [ + 'https://cdnjs.cloudflare.com/ajax/libs/echarts/3.6.2/echarts.min.js', + ], + ], + + 'amcharts' => [ + 'scripts' => [ + 'https://cdnjs.cloudflare.com/ajax/libs/amcharts/3.21.2/amcharts.js', + 'https://cdnjs.cloudflare.com/ajax/libs/amcharts/3.21.2/serial.js', + 'https://cdnjs.cloudflare.com/ajax/libs/amcharts/3.21.2/plugins/export/export.min.js', + 'https://cdnjs.cloudflare.com/ajax/libs/amcharts/3.21.2/themes/light.js', + ], + 'styles' => [ + 'https://cdnjs.cloudflare.com/ajax/libs/amcharts/3.21.2/plugins/export/export.css', + ], + ], + ], +]; diff --git a/Laravel/config/trustedproxy.php b/Laravel/config/trustedproxy.php new file mode 100644 index 0000000..fab11a0 --- /dev/null +++ b/Laravel/config/trustedproxy.php @@ -0,0 +1,71 @@ +getClientIp() + * always gets the originating client IP, no matter + * how many proxies that client's request has + * subsequently passed through. + */ + 'proxies' => [ + '192.168.1.10', + ], + + /* + * Or, to trust all proxies that connect + * directly to your server, uncomment this: + */ + # 'proxies' => '*', + + /* + * Or, to trust ALL proxies, including those that + * are in a chain of forwarding, uncomment this: + */ + # 'proxies' => '**', + + /* + * Default Header Names + * + * Change these if the proxy does + * not send the default header names. + * + * Note that headers such as X-Forwarded-For + * are transformed to HTTP_X_FORWARDED_FOR format. + * + * The following are Symfony defaults, found in + * \Symfony\Component\HttpFoundation\Request::$trustedHeaders + * + * You may optionally set headers to 'null' here if you'd like + * for them to be considered untrusted instead. Ex: + * + * Illuminate\Http\Request::HEADER_CLIENT_HOST => null, + * + * WARNING: If you're using AWS Elastic Load Balancing or Heroku, + * the FORWARDED and X_FORWARDED_HOST headers should be set to null + * as they are currently unsupported there. + */ + 'headers' => [ + (defined('Illuminate\Http\Request::HEADER_FORWARDED') ? Illuminate\Http\Request::HEADER_FORWARDED : 'forwarded') => 'FORWARDED', + Illuminate\Http\Request::HEADER_CLIENT_IP => 'X_FORWARDED_FOR', + Illuminate\Http\Request::HEADER_CLIENT_HOST => 'X_FORWARDED_HOST', + Illuminate\Http\Request::HEADER_CLIENT_PROTO => 'X_FORWARDED_PROTO', + Illuminate\Http\Request::HEADER_CLIENT_PORT => 'X_FORWARDED_PORT', + ] +]; diff --git a/Laravel/resources/views/dashboard.blade.php b/Laravel/resources/views/dashboard.blade.php index f5bbfed..651c61c 100644 --- a/Laravel/resources/views/dashboard.blade.php +++ b/Laravel/resources/views/dashboard.blade.php @@ -62,7 +62,12 @@ .m-b-md { margin-bottom: 30px; } + + + + {!! Charts::styles() !!} +