diff options
author | Marcin Zelent <zelent.marcin@gmail.com> | 2018-03-16 17:53:32 +0100 |
---|---|---|
committer | Marcin Zelent <zelent.marcin@gmail.com> | 2018-03-16 17:53:32 +0100 |
commit | 1ab2b90b02705e206680b5428bf1fbaec6438132 (patch) | |
tree | 8ee964fdf84ff49c22ac6449a178da9d1e67eeb0 /src | |
parent | ed01011dfb563e7d8ab13b6a0718eed7bf857880 (diff) |
Removed old files.
Diffstat (limited to 'src')
-rw-r--r-- | src/.htaccess | 7 | ||||
-rw-r--r-- | src/AppBundle/AppBundle.php | 9 | ||||
-rw-r--r-- | src/AppBundle/Controller/AllDataAverageController.php | 66 | ||||
-rw-r--r-- | src/AppBundle/Controller/AllDataController.php | 43 | ||||
-rw-r--r-- | src/AppBundle/Controller/HomeController.php | 60 | ||||
-rw-r--r-- | src/AppBundle/Controller/LastWeekDataAverageController.php | 66 | ||||
-rw-r--r-- | src/AppBundle/Controller/LastWeekDataController.php | 42 | ||||
-rw-r--r-- | src/AppBundle/Controller/NewDataController.php | 42 | ||||
-rw-r--r-- | src/AppBundle/Controller/TrainScheduleController.php | 110 | ||||
-rw-r--r-- | src/AppBundle/Utils/Aqi.php | 43 |
10 files changed, 0 insertions, 488 deletions
diff --git a/src/.htaccess b/src/.htaccess deleted file mode 100644 index fb1de45..0000000 --- a/src/.htaccess +++ /dev/null @@ -1,7 +0,0 @@ -<IfModule mod_authz_core.c> - Require all denied -</IfModule> -<IfModule !mod_authz_core.c> - Order deny,allow - Deny from all -</IfModule> diff --git a/src/AppBundle/AppBundle.php b/src/AppBundle/AppBundle.php deleted file mode 100644 index 05123b6..0000000 --- a/src/AppBundle/AppBundle.php +++ /dev/null @@ -1,9 +0,0 @@ -<?php - -namespace AppBundle; - -use Symfony\Component\HttpKernel\Bundle\Bundle; - -class AppBundle extends Bundle -{ -} diff --git a/src/AppBundle/Controller/AllDataAverageController.php b/src/AppBundle/Controller/AllDataAverageController.php deleted file mode 100644 index 4434d47..0000000 --- a/src/AppBundle/Controller/AllDataAverageController.php +++ /dev/null @@ -1,66 +0,0 @@ -<?php -namespace AppBundle\Controller; - -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; - - -class AllDataAverageController extends Controller -{ - /** - * @Route("/AllDataAverage", name="AllDataAverage") - */ - - public function GetAllDataAverage() - { - // Get cURL resource - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, "https://pollutometerapi.azurewebsites.net/api/Readings"); - curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json')); // Assuming you're requesting JSON - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - // Send the request & save response to $resp - $resp = curl_exec($curl); - // Close request to clear up some resources - curl_close($curl); - - $data = json_decode($resp, true); - $readings = array(); - $results = array(); - - usort($data, function($a,$b){ - return $a['TimeStamp'] - $b['TimeStamp']; - }); - - foreach($data as $index => $item) - { - $data[$index]['TimeStamp'] = gmdate('d F l', $item['TimeStamp']); - $readings[$data[$index]['TimeStamp']][] = $data[$index]; - } - - foreach ($readings as $key => $item) - { - $gasAverage = array('Co' => 0, 'No' => 0, 'So' => 0); - foreach ($readings[$key] as $index => $values) - { - $gasAverage['Co'] += $readings[$key][$index]['Co']; - $gasAverage['No'] += $readings[$key][$index]['No']; - $gasAverage['So'] += $readings[$key][$index]['So']; - - if($index === count($readings[$key]) - 1) - { - $gasAverage['Co'] /= $index + 1; - $gasAverage['No'] /= $index + 1; - $gasAverage['So'] /= $index + 1; - } - $results[$key] = $gasAverage; - } - } - - $data = json_encode($results); - - $response = new Response($data); - $response->headers->set('Content-Type', 'application/json'); - return $response; - } -}
\ No newline at end of file diff --git a/src/AppBundle/Controller/AllDataController.php b/src/AppBundle/Controller/AllDataController.php deleted file mode 100644 index b45d2c9..0000000 --- a/src/AppBundle/Controller/AllDataController.php +++ /dev/null @@ -1,43 +0,0 @@ -<?php -namespace AppBundle\Controller; - -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; - - -class AllDataController extends Controller -{ - /** - * @Route("/AllData", name="AllData") - */ - - public function GetAllData() - { - // Get cURL resource - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, "https://pollutometerapi.azurewebsites.net/api/Readings"); - curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json')); // Assuming you're requesting JSON - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - // Send the request & save response to $resp - $resp = curl_exec($curl); - // Close request to clear up some resources - curl_close($curl); - - $data = json_decode($resp, true); - - - usort($data, function($a,$b){ - return $a['TimeStamp'] - $b['TimeStamp']; - }); - - foreach($data as $index => $item) - { - $data[$index]['TimeStamp'] = gmdate("l jS \of F Y h:i:s A", $item['TimeStamp']); - } - - $parametersToTwig = array("data" => $data); - - return $this->render('default/AllData.html.twig',$parametersToTwig); - - } -}
\ No newline at end of file diff --git a/src/AppBundle/Controller/HomeController.php b/src/AppBundle/Controller/HomeController.php deleted file mode 100644 index d84ab76..0000000 --- a/src/AppBundle/Controller/HomeController.php +++ /dev/null @@ -1,60 +0,0 @@ -<?php -/** - * Created by PhpStorm. - * User: andy - * Date: 11/23/17 - * Time: 10:21 AM - */ - -namespace AppBundle\Controller; - -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; -use AppBundle\Utils\Aqi; - -class HomeController extends Controller -{ - /** - * @Route("/", name="homepage") - */ - - - public function numberAction(Aqi $aqi) - { - $table = array( - 'Co' => array('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' => array('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' => array('breakpoints' => [0,0.05,0.08,0.10,0.15,0.20,0.25 ,0.31,0.65, 1.24, 1.25, 1.64, 1.65, 2.04], - 'aq' => [0 ,50 ,51 ,100 ,101 ,150 ,151,200,201, 300, 301, 400, 401, 500]) - ); - - - $tableObj = json_decode(json_encode($table)); - - // Get cURL resource - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, "https://pollutometerapi.azurewebsites.net/api/Readings/latest"); - curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json')); // Assuming you're requesting JSON - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - // Send the request & save response to $resp - $resp = curl_exec($curl); - // Close request to clear up some resources - curl_close($curl); - - $data = json_decode($resp, true); - $data['TimeStamp'] = gmdate("l jS \of F Y h:i:s A", $data['TimeStamp']); - - $arr = []; - $CO = is_nan($aqi->calculateAQI("Co", $data['Co'], $tableObj)) ? 0 : $aqi->calculateAQI("Co", $data['Co'], $tableObj); - $SO = is_nan($aqi->calculateAQI("So", $data['So'], $tableObj)) ? 0 : $aqi->calculateAQI("So", $data['So'], $tableObj); - $NO = is_nan($aqi->calculateAQI("No", $data['No'], $tableObj)) ? 0 : $aqi->calculateAQI("No", $data['No'], $tableObj); - - array_push($arr, $CO, $SO, $NO); - $max = max($arr); - $data['Aqi'] = $max; - - return $this->render('default/index.html.twig', $data); - } -} diff --git a/src/AppBundle/Controller/LastWeekDataAverageController.php b/src/AppBundle/Controller/LastWeekDataAverageController.php deleted file mode 100644 index e25b0a8..0000000 --- a/src/AppBundle/Controller/LastWeekDataAverageController.php +++ /dev/null @@ -1,66 +0,0 @@ -<?php -namespace AppBundle\Controller; - -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; - - -class LastWeekDataAverageController extends Controller -{ - /** - * @Route("/LastWeekDataAverage", name="LastWeekDataAverage") - */ - - public function GetLastWeekAverageData() - { - // Get cURL resource - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, "https://pollutometerapi.azurewebsites.net/api/Readings/lastweek"); - curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json')); // Assuming you're requesting JSON - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - // Send the request & save response to $resp - $resp = curl_exec($curl); - // Close request to clear up some resources - curl_close($curl); - - $data = json_decode($resp, true); - $readings = array(); - $results = array(); - - usort($data, function($a,$b){ - return $a['TimeStamp'] - $b['TimeStamp']; - }); - - foreach($data as $index => $item) - { - $data[$index]['TimeStamp'] = gmdate('d F l', $item['TimeStamp']); - $readings[$data[$index]['TimeStamp']][] = $data[$index]; - } - - foreach ($readings as $key => $item) - { - $gasAverage = array('Co' => 0, 'No' => 0, 'So' => 0); - foreach ($readings[$key] as $index => $values) - { - $gasAverage['Co'] += $readings[$key][$index]['Co']; - $gasAverage['No'] += $readings[$key][$index]['No']; - $gasAverage['So'] += $readings[$key][$index]['So']; - - if($index === count($readings[$key]) - 1) - { - $gasAverage['Co'] /= $index + 1; - $gasAverage['No'] /= $index + 1; - $gasAverage['So'] /= $index + 1; - } - $results[$key] = $gasAverage; - } - } - - $data = json_encode($results); - - $response = new Response($data); - $response->headers->set('Content-Type', 'application/json'); - return $response; - } -}
\ No newline at end of file diff --git a/src/AppBundle/Controller/LastWeekDataController.php b/src/AppBundle/Controller/LastWeekDataController.php deleted file mode 100644 index 7b5d993..0000000 --- a/src/AppBundle/Controller/LastWeekDataController.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php -namespace AppBundle\Controller; - -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; - - -class LastWeekDataController extends Controller -{ - /** - * @Route("/LastWeekData", name="LastWeekData") - */ - - public function GetAllData() - { - // Get cURL resource - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, "https://pollutometerapi.azurewebsites.net/api/Readings/lastweek"); - curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json')); // Assuming you're requesting JSON - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - // Send the request & save response to $resp - $resp = curl_exec($curl); - // Close request to clear up some resources - curl_close($curl); - - $data = json_decode($resp, true); - - - usort($data, function($a,$b){ - return $a['TimeStamp'] - $b['TimeStamp']; - }); - - foreach($data as $index => $item) - { - $data[$index]['TimeStamp'] = gmdate("l jS \of F Y h:i:s A", $item['TimeStamp']); - } - - $parametersToTwig = array("data" => $data); - - return $this->render('default/LastWeekData.html.twig',$parametersToTwig); - } -}
\ No newline at end of file diff --git a/src/AppBundle/Controller/NewDataController.php b/src/AppBundle/Controller/NewDataController.php deleted file mode 100644 index 5dd440f..0000000 --- a/src/AppBundle/Controller/NewDataController.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php -/** - * Created by PhpStorm. - * User: andy - * Date: 11/23/17 - * Time: 10:21 AM - */ - -namespace AppBundle\Controller; - -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; - -class NewDataController extends Controller -{ - /** - * @Route("/latest") - */ - - public function getLatestData() - { - // Get cURL resource - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, "https://pollutometerapi.azurewebsites.net/api/Readings/latest"); - curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json')); // Assuming you're requesting JSON - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - // Send the request & save response to $resp - $resp = curl_exec($curl); - // Close request to clear up some resources - curl_close($curl); - - $data = json_decode($resp, true); - $data['TimeStamp'] = gmdate("l jS \of F Y h:i:s A", $data['TimeStamp']); - $data = json_encode($data); - - $response = new Response($data); - $response->headers->set('Content-Type', 'application/json'); - return $response; - } - -} diff --git a/src/AppBundle/Controller/TrainScheduleController.php b/src/AppBundle/Controller/TrainScheduleController.php deleted file mode 100644 index a6b517d..0000000 --- a/src/AppBundle/Controller/TrainScheduleController.php +++ /dev/null @@ -1,110 +0,0 @@ -<?php -/** - * Created by PhpStorm. - * User: marcin - * Date: 07/12/17 - * Time: 10:33 - */ - -namespace AppBundle\Controller; - -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; -use AppBundle\Utils\Aqi; - -class TrainScheduleController extends Controller -{ - /** - * @Route("/TrainSchedule") - */ - - public function GetSchedule() - { - $url = "http://xmlopen.rejseplanen.dk/bin/rest.exe/multiDepartureBoard?id1=008600617&date=" . - date("d.m.Y") . - "&time=00%3A00&useBus=0&format=json"; - - // Get cURL resource - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, $url); - curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json')); // Assuming you're requesting JSON - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - // Send the request & save response to $resp - $resp = curl_exec($curl); - // Close request to clear up some resources - curl_close($curl); - - $trains = json_decode($resp, true); - $trains = $trains['MultiDepartureBoard']['Departure']; - - // Get cURL resource - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, "https://pollutometerapi.azurewebsites.net/api/Readings/lastweek"); - curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json')); // Assuming you're requesting JSON - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - // Send the request & save response to $resp - $resp = curl_exec($curl); - // Close request to clear up some resources - curl_close($curl); - - $readings = json_decode($resp, true); - - - for ($i = 0; $i < count($trains); $i++) { - $closest = 5301590400; - $time = $trains[$i]['time']; - $date = $trains[$i]['date']; - $datesplit = explode(".", $date); - $datetime = $datesplit[0] . "." . $datesplit[1] . ".20" . $datesplit[2] . " " . $time; - $trainTimeStamp = strtotime($datetime) + 3600; - - if($trainTimeStamp > time()) - { - $trains[$i]['direction'] = 0; - continue; - } - - foreach ($readings as $reading) { - if (abs($reading['TimeStamp'] - $trainTimeStamp) < abs($closest - $trainTimeStamp)) - $closest = $reading['TimeStamp']; - } - - $closestReading = $readings[0]; - foreach ($readings as $reading) - { - if($reading['TimeStamp'] == $closest) $closestReading = $reading; - } - $trains[$i]['direction'] = $this->getAqi($closestReading); - } - - $parametersToTwig = array("data" => $trains); - - return $this->render('default/TrainSchedule.html.twig', $parametersToTwig); - } - - private function getAqi(array $data) - { - $aqi = new Aqi(); - - $table = array( - 'Co' => array('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' => array('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' => array('breakpoints' => [0,0.05,0.08,0.10,0.15,0.20,0.25 ,0.31,0.65, 1.24, 1.25, 1.64, 1.65, 2.04], - 'aq' => [0 ,50 ,51 ,100 ,101 ,150 ,151,200,201, 300, 301, 400, 401, 500]) - ); - - $tableObj = json_decode(json_encode($table)); - - $arr = []; - $CO = is_nan($aqi->calculateAQI("Co", $data['Co'], $tableObj)) ? 0 : $aqi->calculateAQI("Co", $data['Co'], $tableObj); - $SO = is_nan($aqi->calculateAQI("So", $data['So'], $tableObj)) ? 0 : $aqi->calculateAQI("So", $data['So'], $tableObj); - $NO = is_nan($aqi->calculateAQI("No", $data['No'], $tableObj)) ? 0 : $aqi->calculateAQI("No", $data['No'], $tableObj); - - array_push($arr, $CO, $SO, $NO); - $max = max($arr); - - return $max; - } -}
\ No newline at end of file diff --git a/src/AppBundle/Utils/Aqi.php b/src/AppBundle/Utils/Aqi.php deleted file mode 100644 index 1b324a8..0000000 --- a/src/AppBundle/Utils/Aqi.php +++ /dev/null @@ -1,43 +0,0 @@ -<?php -/** - * Created by PhpStorm. - * User: andy - * Date: 11/30/17 - * Time: 11:27 AM - * - * - */ - -Namespace AppBundle\Utils; - -class Aqi { - public function calculateAQI($gasName, $concentration, $table) { - $bpLow = 1; - $bpHi = 2; - $bpLowIndex = 1; - $bpHiIndex = 1; - - $arr = $table ->{$gasName} ->{'breakpoints'}; - foreach ($arr as $index => $value) { - 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; - } - - }; - - - - $airQualityIndex = (($table->{$gasName}->{'aq'}[$bpHiIndex] - $table->{$gasName}->{'aq'}[$bpLowIndex]) / ($bpHi - $bpLow)) * ($concentration - $bpLow) + $table->{$gasName}->{'aq'}[$bpLowIndex]; - - return $airQualityIndex; - - } -} - -?>
\ No newline at end of file |