aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/AppBundle/Controller/AllDataAverageController.php18
-rw-r--r--src/AppBundle/Controller/LastWeekDataAverageController.php24
2 files changed, 15 insertions, 27 deletions
diff --git a/src/AppBundle/Controller/AllDataAverageController.php b/src/AppBundle/Controller/AllDataAverageController.php
index 87a9d7c..4434d47 100644
--- a/src/AppBundle/Controller/AllDataAverageController.php
+++ b/src/AppBundle/Controller/AllDataAverageController.php
@@ -25,26 +25,24 @@ class AllDataAverageController extends Controller
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];
}
- $gasAverage = array('Co' => 0, 'No' => 0, 'So' => 0);
- foreach($readings as $key => $item)
+ foreach ($readings as $key => $item)
{
- foreach($readings[$key] as $index => $values)
+ $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'];
@@ -55,15 +53,11 @@ class AllDataAverageController extends Controller
$gasAverage['No'] /= $index + 1;
$gasAverage['So'] /= $index + 1;
}
+ $results[$key] = $gasAverage;
}
-
- $readings[$key] = $gasAverage;
-
}
-
- $data = json_encode($readings);
-
+ $data = json_encode($results);
$response = new Response($data);
$response->headers->set('Content-Type', 'application/json');
diff --git a/src/AppBundle/Controller/LastWeekDataAverageController.php b/src/AppBundle/Controller/LastWeekDataAverageController.php
index fe30fd4..e25b0a8 100644
--- a/src/AppBundle/Controller/LastWeekDataAverageController.php
+++ b/src/AppBundle/Controller/LastWeekDataAverageController.php
@@ -25,9 +25,12 @@ class LastWeekDataAverageController extends Controller
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)
{
@@ -35,14 +38,11 @@ class LastWeekDataAverageController extends Controller
$readings[$data[$index]['TimeStamp']][] = $data[$index];
}
-
-
- $gasAverage = array('Co' => 0, 'No' => 0, 'So' => 0);
- foreach($readings as $key => $item)
+ foreach ($readings as $key => $item)
{
- foreach($readings[$key] as $index => $values)
+ $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'];
@@ -53,20 +53,14 @@ class LastWeekDataAverageController extends Controller
$gasAverage['No'] /= $index + 1;
$gasAverage['So'] /= $index + 1;
}
+ $results[$key] = $gasAverage;
}
-
- $readings[$key] = $gasAverage;
-
}
-
- $data = json_encode($readings);
-
+ $data = json_encode($results);
$response = new Response($data);
$response->headers->set('Content-Type', 'application/json');
return $response;
-
-
}
} \ No newline at end of file