aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcinzelent <zelent.marcin@gmail.com>2017-12-01 11:06:41 +0100
committermarcinzelent <zelent.marcin@gmail.com>2017-12-01 11:06:41 +0100
commit8b8639740c08633728f0d9dd778ac022e43f7e1b (patch)
treed8f087a875416d7feb05f53ec459aacdfd12c47d
parent7d09b3a6201a175128421d117d4c63495813fa05 (diff)
parent8c514c01aa4d620aea084beca3f4808270671f7e (diff)
Merge remote-tracking branch 'origin/master'
-rw-r--r--app/Resources/views/default/index.html.twig3
-rw-r--r--src/AppBundle/Controller/AllDataController.php9
-rw-r--r--src/AppBundle/Controller/HomeController.php1
-rw-r--r--src/AppBundle/Controller/NewDataController.php1
-rw-r--r--tests/AppBundle/Controller/MathControllerTest.php19
5 files changed, 29 insertions, 4 deletions
diff --git a/app/Resources/views/default/index.html.twig b/app/Resources/views/default/index.html.twig
index 684393d..ce28faf 100644
--- a/app/Resources/views/default/index.html.twig
+++ b/app/Resources/views/default/index.html.twig
@@ -18,7 +18,8 @@
</table>
</div>
<a href="/AllDataReadings">All Data Page</a>
- <p id="aq">{{ Aqi }}</p>
+
+ <p id="aq">The current air quality index is <strong>{{ Aqi }}</strong></p>
<img src="https://www.ourair.org/wp-content/uploads/AQItable.gif">
{% endblock %}
{% block javascripts %}
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);
diff --git a/src/AppBundle/Controller/HomeController.php b/src/AppBundle/Controller/HomeController.php
index 606d666..ca2043e 100644
--- a/src/AppBundle/Controller/HomeController.php
+++ b/src/AppBundle/Controller/HomeController.php
@@ -47,7 +47,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 9722cbd..8bfda68 100644
--- a/src/AppBundle/Controller/NewDataController.php
+++ b/src/AppBundle/Controller/NewDataController.php
@@ -43,7 +43,6 @@ class NewDataController extends Controller
if($aqi >= 151) $emailSender->sendEmail($data);
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 @@
+<?php
+
+namespace Tests\AppBundle\Controller;
+
+use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
+
+class MathControllerTest extends WebTestCase
+{
+ public function testAQIMath()
+ {
+ $CO = 1;
+ $bpLowCO = 0;
+ $bpHiCO = 4;
+ $bpLowIndex = 0;
+ $bpHiIndex = 50;
+ $AQI = ((50 - 0)/(4 - 0))*(1-0)+0;
+ $this->assertEquals(12.5, $AQI);
+ }
+} \ No newline at end of file