From 0f5659465584b5ef9fcbec26ea695fe3f1af9012 Mon Sep 17 00:00:00 2001 From: Shadify Date: Fri, 1 Dec 2017 08:51:24 +0100 Subject: Sorted all data --- app/Resources/views/default/index.html.twig | 1 + src/AppBundle/Controller/AllDataController.php | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/Resources/views/default/index.html.twig b/app/Resources/views/default/index.html.twig index 684393d..7882c26 100644 --- a/app/Resources/views/default/index.html.twig +++ b/app/Resources/views/default/index.html.twig @@ -18,6 +18,7 @@ All Data Page +

{{ Aqi }}

{% endblock %} diff --git a/src/AppBundle/Controller/AllDataController.php b/src/AppBundle/Controller/AllDataController.php index 18a30a1..78b4752 100644 --- a/src/AppBundle/Controller/AllDataController.php +++ b/src/AppBundle/Controller/AllDataController.php @@ -5,11 +5,13 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Component\HttpFoundation\Response; use Symfony\Bundle\FrameworkBundle\Controller\Controller; + class AllDataController extends Controller { /** * @Route("/AllDataReadings", name="AllData") */ + public function GetAllData() { // Get cURL resource @@ -23,6 +25,12 @@ class AllDataController extends Controller 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']); @@ -30,7 +38,6 @@ class AllDataController extends Controller $parametersToTwig = array("data" => $data); - return $this->render('default/AllDataPage.html.twig',$parametersToTwig); -- cgit v1.2.3 From 8c514c01aa4d620aea084beca3f4808270671f7e Mon Sep 17 00:00:00 2001 From: Shadify Date: Fri, 1 Dec 2017 09:59:15 +0100 Subject: wrote test case + cleaned up main page --- app/Resources/views/default/index.html.twig | 2 +- src/AppBundle/Controller/HomeController.php | 1 - src/AppBundle/Controller/NewDataController.php | 1 - tests/AppBundle/Controller/MathControllerTest.php | 19 +++++++++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 tests/AppBundle/Controller/MathControllerTest.php diff --git a/app/Resources/views/default/index.html.twig b/app/Resources/views/default/index.html.twig index 7882c26..ce28faf 100644 --- a/app/Resources/views/default/index.html.twig +++ b/app/Resources/views/default/index.html.twig @@ -19,7 +19,7 @@ All Data Page -

{{ Aqi }}

+

The current air quality index is {{ Aqi }}

{% endblock %} {% block javascripts %} diff --git a/src/AppBundle/Controller/HomeController.php b/src/AppBundle/Controller/HomeController.php index d8234cf..0cfe2ab 100644 --- a/src/AppBundle/Controller/HomeController.php +++ b/src/AppBundle/Controller/HomeController.php @@ -51,7 +51,6 @@ class HomeController extends Controller $data['TimeStamp'] = gmdate("l jS \of F Y h:i:s A", $data['TimeStamp']); $arr = []; - print_r($data); $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); diff --git a/src/AppBundle/Controller/NewDataController.php b/src/AppBundle/Controller/NewDataController.php index f63a7fa..ecb1be9 100644 --- a/src/AppBundle/Controller/NewDataController.php +++ b/src/AppBundle/Controller/NewDataController.php @@ -38,7 +38,6 @@ class NewDataController extends Controller $response->headers->set('Content-Type', 'application/json'); return $response; - } } diff --git a/tests/AppBundle/Controller/MathControllerTest.php b/tests/AppBundle/Controller/MathControllerTest.php new file mode 100644 index 0000000..523f9e5 --- /dev/null +++ b/tests/AppBundle/Controller/MathControllerTest.php @@ -0,0 +1,19 @@ +assertEquals(12.5, $AQI); + } +} \ No newline at end of file -- cgit v1.2.3