From ed01011dfb563e7d8ab13b6a0718eed7bf857880 Mon Sep 17 00:00:00 2001 From: Marcin Zelent Date: Fri, 16 Mar 2018 17:48:44 +0100 Subject: Moved PHP website to separate directory. --- pollutometer-php/web/.htaccess | 68 +++++ pollutometer-php/web/app.php | 21 ++ pollutometer-php/web/app_dev.php | 31 ++ pollutometer-php/web/apple-touch-icon.png | Bin 0 -> 2092 bytes pollutometer-php/web/config.php | 422 +++++++++++++++++++++++++++ pollutometer-php/web/favicon.ico | Bin 0 -> 6518 bytes pollutometer-php/web/js/AllDataChart.js | 63 ++++ pollutometer-php/web/js/LastWeekDataChart.js | 63 ++++ pollutometer-php/web/js/realtime.js | 110 +++++++ pollutometer-php/web/robots.txt | 5 + 10 files changed, 783 insertions(+) create mode 100644 pollutometer-php/web/.htaccess create mode 100644 pollutometer-php/web/app.php create mode 100644 pollutometer-php/web/app_dev.php create mode 100644 pollutometer-php/web/apple-touch-icon.png create mode 100644 pollutometer-php/web/config.php create mode 100644 pollutometer-php/web/favicon.ico create mode 100644 pollutometer-php/web/js/AllDataChart.js create mode 100644 pollutometer-php/web/js/LastWeekDataChart.js create mode 100644 pollutometer-php/web/js/realtime.js create mode 100644 pollutometer-php/web/robots.txt (limited to 'pollutometer-php/web') diff --git a/pollutometer-php/web/.htaccess b/pollutometer-php/web/.htaccess new file mode 100644 index 0000000..4dc7251 --- /dev/null +++ b/pollutometer-php/web/.htaccess @@ -0,0 +1,68 @@ +# Use the front controller as index file. It serves as a fallback solution when +# every other rewrite/redirect fails (e.g. in an aliased environment without +# mod_rewrite). Additionally, this reduces the matching process for the +# start page (path "/") because otherwise Apache will apply the rewriting rules +# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl). +DirectoryIndex app.php + +# By default, Apache does not evaluate symbolic links if you did not enable this +# feature in your server configuration. Uncomment the following line if you +# install assets as symlinks or if you experience problems related to symlinks +# when compiling LESS/Sass/CoffeScript assets. +# Options FollowSymlinks + +# Disabling MultiViews prevents unwanted negotiation, e.g. "/app" should not resolve +# to the front controller "/app.php" but be rewritten to "/app.php/app". + + Options -MultiViews + + + + RewriteEngine On + + # Determine the RewriteBase automatically and set it as environment variable. + # If you are using Apache aliases to do mass virtual hosting or installed the + # project in a subdirectory, the base path will be prepended to allow proper + # resolution of the app.php file and to redirect to the correct URI. It will + # work in environments without path prefix as well, providing a safe, one-size + # fits all solution. But as you do not need it in this case, you can comment + # the following 2 lines to eliminate the overhead. + RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ + RewriteRule ^(.*) - [E=BASE:%1] + + # Sets the HTTP_AUTHORIZATION header removed by Apache + RewriteCond %{HTTP:Authorization} . + RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + + # Redirect to URI without front controller to prevent duplicate content + # (with and without `/app.php`). Only do this redirect on the initial + # rewrite by Apache and not on subsequent cycles. Otherwise we would get an + # endless redirect loop (request -> rewrite to front controller -> + # redirect -> request -> ...). + # So in case you get a "too many redirects" error or you always get redirected + # to the start page because your Apache does not expose the REDIRECT_STATUS + # environment variable, you have 2 choices: + # - disable this feature by commenting the following 2 lines or + # - use Apache >= 2.3.9 and replace all L flags by END flags and remove the + # following RewriteCond (best solution) + RewriteCond %{ENV:REDIRECT_STATUS} ^$ + RewriteRule ^app\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L] + + # If the requested filename exists, simply serve it. + # We only want to let Apache serve files and not directories. + RewriteCond %{REQUEST_FILENAME} -f + RewriteRule ^ - [L] + + # Rewrite all other queries to the front controller. + RewriteRule ^ %{ENV:BASE}/app.php [L] + + + + + # When mod_rewrite is not available, we instruct a temporary redirect of + # the start page to the front controller explicitly so that the website + # and the generated links can still be used. + RedirectMatch 302 ^/$ /app.php/ + # RedirectTemp cannot be used instead + + diff --git a/pollutometer-php/web/app.php b/pollutometer-php/web/app.php new file mode 100644 index 0000000..943d089 --- /dev/null +++ b/pollutometer-php/web/app.php @@ -0,0 +1,21 @@ +loadClassCache(); +} +//$kernel = new AppCache($kernel); + +// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter +//Request::enableHttpMethodParameterOverride(); +$request = Request::createFromGlobals(); +$response = $kernel->handle($request); +$response->send(); +$kernel->terminate($request, $response); diff --git a/pollutometer-php/web/app_dev.php b/pollutometer-php/web/app_dev.php new file mode 100644 index 0000000..d2ff583 --- /dev/null +++ b/pollutometer-php/web/app_dev.php @@ -0,0 +1,31 @@ +loadClassCache(); +} +$request = Request::createFromGlobals(); +$response = $kernel->handle($request); +$response->send(); +$kernel->terminate($request, $response); diff --git a/pollutometer-php/web/apple-touch-icon.png b/pollutometer-php/web/apple-touch-icon.png new file mode 100644 index 0000000..6e6b6ce Binary files /dev/null and b/pollutometer-php/web/apple-touch-icon.png differ diff --git a/pollutometer-php/web/config.php b/pollutometer-php/web/config.php new file mode 100644 index 0000000..fd7e17e --- /dev/null +++ b/pollutometer-php/web/config.php @@ -0,0 +1,422 @@ +getFailedRequirements(); +$minorProblems = $symfonyRequirements->getFailedRecommendations(); +$hasMajorProblems = (bool) count($majorProblems); +$hasMinorProblems = (bool) count($minorProblems); + +?> + + + + + + Symfony Configuration Checker + + + +
+
+ + + +
+ +
+
+
+

Configuration Checker

+

+ This script analyzes your system to check whether is + ready to run Symfony applications. +

+ + +

Major problems

+

Major problems have been detected and must be fixed before continuing:

+
    + +
  1. getTestMessage() ?> +

    getHelpHtml() ?>

    +
  2. + +
+ + + +

Recommendations

+

+ Additionally, toTo enhance your Symfony experience, + it’s recommended that you fix the following: +

+
    + +
  1. getTestMessage() ?> +

    getHelpHtml() ?>

    +
  2. + +
+ + + hasPhpIniConfigIssue()): ?> +

* + getPhpIniConfigPath()): ?> + Changes to the php.ini file must be done in "getPhpIniConfigPath() ?>". + + To change settings, create a "php.ini". + +

+ + + +

All checks passed successfully. Your system is ready to run Symfony applications.

+ + + +
+
+
+
Symfony Standard Edition
+
+ + diff --git a/pollutometer-php/web/favicon.ico b/pollutometer-php/web/favicon.ico new file mode 100644 index 0000000..479f7f5 Binary files /dev/null and b/pollutometer-php/web/favicon.ico differ diff --git a/pollutometer-php/web/js/AllDataChart.js b/pollutometer-php/web/js/AllDataChart.js new file mode 100644 index 0000000..6525382 --- /dev/null +++ b/pollutometer-php/web/js/AllDataChart.js @@ -0,0 +1,63 @@ +var gasReading = { + Co: [], + No: [], + So: [] +}; + +var canvas = document.querySelector('#ctx'); +var ctx = canvas.getContext('2d'); + +var datasets = [{ + label: "Co", + borderColor: "rgb(5, 0, 0)", + fill: false, + data: [] +}, { + label: "No", + borderColor: "rgb(69, 169, 230)", + fill: false, + data: [] +}, { + label: "So", + borderColor: "rgb(246, 250, 15)", + fill: false, + data: [] +}]; + +fetch('/AllDataAverage') + .then(function(response) { + return response.json(); + }) + .then(function(data) { + drawChart(data, datasets); + }); + +function drawChart(gasData, datasets) { + + var finishedData = { + labels: [] + }; + + Object.keys(gasData).forEach(function(key) { + finishedData.labels.push(key); + datasets[0].data.push(gasData[key].Co); + datasets[1].data.push(gasData[key].No); + datasets[2].data.push(gasData[key].So); + }); + + finishedData.datasets = datasets; + + var myLineChart = new Chart(ctx, { + type: 'line', + data: finishedData, + options: { + scales: { + xAxes: [{ + time: { + unit: 'day' + } + }] + } + } + }); +} diff --git a/pollutometer-php/web/js/LastWeekDataChart.js b/pollutometer-php/web/js/LastWeekDataChart.js new file mode 100644 index 0000000..b5e3976 --- /dev/null +++ b/pollutometer-php/web/js/LastWeekDataChart.js @@ -0,0 +1,63 @@ +var gasReading = { + Co: [], + No: [], + So: [] +}; + +var canvas = document.querySelector('#ctx'); +var ctx = canvas.getContext('2d'); + +var datasets = [{ + label: "Co", + borderColor: "rgb(5, 0, 0)", + fill: false, + data: [] +}, { + label: "No", + borderColor: "rgb(69, 169, 230)", + fill: false, + data: [] +}, { + label: "So", + borderColor: "rgb(246, 250, 15)", + fill: false, + data: [] +}]; + +fetch('/LastWeekDataAverage') + .then(function(response) { + return response.json(); + }) + .then(function(data) { + drawChart(data, datasets); + }); + +function drawChart(gasData, datasets) { + + var finishedData = { + labels: [] + }; + + Object.keys(gasData).forEach(function(key) { + finishedData.labels.push(key); + datasets[0].data.push(gasData[key].Co); + datasets[1].data.push(gasData[key].No); + datasets[2].data.push(gasData[key].So); + }); + + finishedData.datasets = datasets; + + var myLineChart = new Chart(ctx, { + type: 'line', + data: finishedData, + options: { + scales: { + xAxes: [{ + time: { + unit: 'day' + } + }] + } + } + }); +} diff --git a/pollutometer-php/web/js/realtime.js b/pollutometer-php/web/js/realtime.js new file mode 100644 index 0000000..1f5ef22 --- /dev/null +++ b/pollutometer-php/web/js/realtime.js @@ -0,0 +1,110 @@ +function arrayMax(arr) { + var len = arr.length, max = -Infinity; + while (len--) { + if (arr[len] > max) { + max = arr[len]; + } + } + return max; +}; + + +const table = { + Co: { + breakpoints: [0, 4.4, 4.5, 9.4, 9.5, 12.4, 12.5, 15.4, 15.5, 30.4, 30.5, 40.4, 40.5, 50.4], + aq: [0, 50, 51, 100, 101, 150, 151, 200, 201, 300, 301, 400, 401, 500] + }, + So: { + breakpoints: [0.000, 0.034, 0.035, 0.144, 0.145, 0.224, 0.225, 0.304, 0.305, 0.604, 0.605, 0.804, 0.805, 1.004], + aq:[0, 50, 51, 100, 101, 150, 151, 200, 201, 300, 301, 400, 401, 500] + }, + No: { + breakpoints: [0.65, 1.24, 1.25, 1.64, 1.65, 2.04], + aq:[201, 300, 301, 400, 401, 500] + } +}; + + +function calculateAQI(gasName, concentration) { + var bpLow,bpHi; + var bpLowIndex, bpHiIndex; + + table[gasName].breakpoints.forEach(function(value, index) { + if(value <= concentration && table[gasName].breakpoints[index + 1] >= concentration) { + bpLow = value; + bpLowIndex = index; + } + + if(value >= concentration && table[gasName].breakpoints[index - 1] <= concentration) { + bpHi = value; + bpHiIndex = index; + } + + }); + + + + var airQualityIndex = ((table[gasName].aq[bpHiIndex] - table[gasName].aq[bpLowIndex]) / (bpHi - bpLow)) * (concentration - bpLow) + table[gasName].aq[bpLowIndex]; + + return airQualityIndex; + +} + + +function update() { + + var data; + + fetch('/latest') + .then(function(resp) { + return resp.json(); + }) + .then(function(response) { + data = response; + var table = document.querySelector('#latest').children; + table[0].textContent = data.TimeStamp; + table[1].textContent = data.Co; + table[2].textContent = data.No; + table[3].textContent = data.So; + + var indexes = []; + var CO = isNaN(calculateAQI("Co", data.Co)) ? 0 : calculateAQI("Co", data.Co); + var SO = isNaN(calculateAQI("So", data.So)) ? 0 : calculateAQI("So", data.So); + var NO = isNaN(calculateAQI("No", data.No)) ? 0 : calculateAQI("No", data.No); + indexes.push(CO); + indexes.push(NO); + indexes.push(SO); + + + var max = arrayMax(indexes); + + document.querySelector("#aq").innerHTML = `The current air quality index is ${max}`; + + }) + .catch(function(error) { + console.log(error); + }); + + + + +} + +function drawChart() { + +} + +setInterval(update, 10000); + + + + + + + + + + + + + diff --git a/pollutometer-php/web/robots.txt b/pollutometer-php/web/robots.txt new file mode 100644 index 0000000..4665fca --- /dev/null +++ b/pollutometer-php/web/robots.txt @@ -0,0 +1,5 @@ +# www.robotstxt.org/ +# www.google.com/support/webmasters/bin/answer.py?hl=en&answer=156449 + +User-agent: * +Disallow: -- cgit v1.2.3