From ed01011dfb563e7d8ab13b6a0718eed7bf857880 Mon Sep 17 00:00:00 2001 From: Marcin Zelent Date: Fri, 16 Mar 2018 17:48:44 +0100 Subject: Moved PHP website to separate directory. --- .../Controller/AllDataAverageController.php | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 pollutometer-php/src/AppBundle/Controller/AllDataAverageController.php (limited to 'pollutometer-php/src/AppBundle/Controller/AllDataAverageController.php') diff --git a/pollutometer-php/src/AppBundle/Controller/AllDataAverageController.php b/pollutometer-php/src/AppBundle/Controller/AllDataAverageController.php new file mode 100644 index 0000000..4434d47 --- /dev/null +++ b/pollutometer-php/src/AppBundle/Controller/AllDataAverageController.php @@ -0,0 +1,66 @@ + $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 -- cgit v1.2.3