diff --git a/backend/lib/controller/datacontroller.php b/backend/lib/controller/datacontroller.php index 1af6dda..0d51e18 100644 --- a/backend/lib/controller/datacontroller.php +++ b/backend/lib/controller/datacontroller.php @@ -32,7 +32,7 @@ class DataController extends Controller { $from = (isset($this->view->request->get['from'])) ? (int) $this->view->request->get['from'] : NULL; $to = (isset($this->view->request->get['to'])) ? (int) $this->view->request->get['to'] : NULL; - $groupBy = (isset($this->view->request->get['groupBy'])) ? $this->view->request->get['groupBy'] : 400; // get all readings by default + $groupBy = (isset($this->view->request->get['groupBy'])) ? $this->view->request->get['groupBy'] : NULL; // get all readings by default foreach ($channels as $channel) { $this->view->addChannel($channel, $channel->getPulses($from, $to, $groupBy)); diff --git a/backend/lib/model/channel.php b/backend/lib/model/channel.php index b207a09..06cca9f 100644 --- a/backend/lib/model/channel.php +++ b/backend/lib/model/channel.php @@ -88,6 +88,9 @@ abstract class Channel extends DatabaseObject implements ChannelInterface { break; default: + if (is_numeric($groupBy)) { + $groupBy = (int) $groupBy; + } $sqlGroupBy = false; } @@ -116,7 +119,7 @@ abstract class Channel extends DatabaseObject implements ChannelInterface { $reading = $result->rewind(); for ($i = 1; $i <= $packageCount; $i++) { $package = array('timestamp' => $reading['timestamp'], // last timestamp in package - 'value' => $reading['value'], // sum of values + 'value' => (float) $reading['value'], // sum of values 'count' => ($sqlGroupBy === false) ? 1 : $reading['count']); // total count of values or pulses in the package while ($package['count'] < $packageSize) { diff --git a/backend/lib/view/jsonview.php b/backend/lib/view/jsonview.php index 1da824b..5290bf8 100644 --- a/backend/lib/view/jsonview.php +++ b/backend/lib/view/jsonview.php @@ -60,7 +60,7 @@ class JsonView extends View { $channel['unit'] = $obj->unit; $channel['description'] = $obj->description; $channel['resolution'] = (int) $obj->resolution; - $channel['costs'] = $obj->cost; + $channel['costs'] = (float) $obj->cost; // TODO check for optional data in second param if (!is_null($data) && is_array($data)) { diff --git a/share/tools/tests.php b/share/tools/tests.php index 6b3f065..ef6b67c 100644 --- a/share/tools/tests.php +++ b/share/tools/tests.php @@ -23,7 +23,7 @@ include '../../backend/init.php'; $meter = current(Channel::getByFilter(array('id' => 1))); -$data = $meter->getData(0, time()*1000); +$data = $meter->getPulses(1270062000000, 1270666800000, 400); echo '