diff options
Diffstat (limited to 'src/AppBundle/Controller/AllDataAverageController.php')
-rw-r--r-- | src/AppBundle/Controller/AllDataAverageController.php | 18 |
1 files changed, 6 insertions, 12 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'); |