diff --git a/backend/lib/controller/channelcontroller.php b/backend/lib/controller/channelcontroller.php
index 1638911..d42e56f 100644
--- a/backend/lib/controller/channelcontroller.php
+++ b/backend/lib/controller/channelcontroller.php
@@ -25,7 +25,7 @@ class ChannelController extends Controller {
$this->view->channels = array();
if ($this->view->request->get['data'] == 'channels') { // get all channels assigned to user
- $user = current(User::getByFilter(array('id' => 1))); // TODO replace by authentication or session handling
+ $user = User::getByUuid($this->view->request->get['uuid']);
$channels = $user->getChannels();
}
else {
@@ -42,13 +42,13 @@ class ChannelController extends Controller {
$jsonChannels = array();
foreach ($channels as $channel) {
- $jsonChannel = $channel->toJson(); // TODO fix hardcoded json output
+ $jsonChannel = $this->view->getChannel($channel);
- if ($this->view->request->get['data'] == 'pulses') {
- $jsonChannel['pulses'] = array();
+ if ($this->view->request->get['data'] == 'readings') {
+ $jsonChannel['readings'] = array();
foreach ($channel->getPulses($from, $to, $groupBy) as $pulse) {
- $jsonChannel['pulses'][] = array($pulse['timestamp'], $pulse['value']);
+ $jsonChannel['readingsgi'][] = array($pulse['timestamp'], $pulse['value']);
}
}
@@ -64,9 +64,7 @@ class ChannelController extends Controller {
$channel = Channel::getByUcid($ucid);
- if (!($channel instanceof Channel)) { // TODO rework
- $channel = Channel::addChannel($ucid);
- }
+ // TODO add channel if it doesn't exist (use $this->add)
$channel->addData($this->view->request->get);
}
diff --git a/backend/lib/model/channel.php b/backend/lib/model/channel.php
index 136c8b6..c470c76 100644
--- a/backend/lib/model/channel.php
+++ b/backend/lib/model/channel.php
@@ -190,14 +190,4 @@ abstract class Channel extends DatabaseObject implements ChannelInterface {
$sql .= static::buildFilterCondition($filters, $conjunction);
return $sql;
}
-
- public function toJson() {
- return array(
- 'id' => (int) $this->id,
- 'ucid' => $this->ucid,
- 'resolution' => (int) $this->resolution,
- 'description' => $this->description,
- 'type' => $this->type,
- 'costs' => $this->cost);
- }
}
\ No newline at end of file
diff --git a/backend/lib/view/jsonview.php b/backend/lib/view/jsonview.php
index d740680..423fdc7 100644
--- a/backend/lib/view/jsonview.php
+++ b/backend/lib/view/jsonview.php
@@ -61,10 +61,17 @@ class JsonView extends View {
'line' => $exception->getLine(),
'trace' => $exception->getTrace()
);
-
- echo 'bla';
$this->render();
}
+
+ public function getChannel(Channel $channel) { // TODO improve view interface
+ return array('id' => (int) $channel->id,
+ 'ucid' => $channel->ucid,
+ 'resolution' => (int) $channel->resolution,
+ 'description' => $channel->description,
+ 'type' => $channel->type,
+ 'costs' => $channel->cost);
+ }
}
?>
\ No newline at end of file
diff --git a/share/tools/tests.php b/share/tools/tests.php
index 2a50720..3b83a5f 100644
--- a/share/tools/tests.php
+++ b/share/tools/tests.php
@@ -21,38 +21,18 @@
include '../../backend/init.php';
-$user = User::getByEMail($_GET['email']);
-$groups = $user->getGroups(true);
+$meter = current(Channel::getByFilter(array('id' => 1)));
-foreach ($groups as $group) {
- $channels = $group->getChannels();
- echo $group->description . ' (' . count($channels) . '):
';
- foreach ($channels as $channel) {
- echo ' [' . $channel->ucid . '] ' . $channel->description . ': ' . $channel::unit;
- echo ' Min: ' . implode('|', $channel->getMin());
- echo ' Max: ' . implode('|', $channel->getMax());
- echo ' Avg: ' . implode('|', $channel->getAverage());
- echo '
';
- }
+$readings = $meter->getData(0, time()*1000, 'hour');
+
+echo '
';
+foreach ($readings as $i => $reading) {
+ echo '' . ($i + 1) . ' | ' . date('l jS \of F Y h:i:s A', $reading['timestamp']/1000) . ' | ' . $reading['value'] . ' | ' . $reading['count'] . ' |
';
}
+echo '
';
echo '';
var_dump(Database::getConnection());
echo '
';
-/*$meter = current(Channel::getByFilter(array('id' => 19)));
-
-$start = microtime(true);
-$readings = $meter->getData(0, time(), 'day');
-echo microtime(true) - $start;
-
-echo '
';
-foreach ($readings as $i => $reading) {
- echo '' . ($i + 1) . ' | ' . date('l jS \of F Y h:i:s A', $reading['timestamp']) . ' | ' . $reading['value'] . ' | ' . $reading['count'] . ' |
';
-}
-echo '
';
-
-$max = $meter->getAverage();
-echo 'Maximal value: ' . date('l jS \of F Y h:i:s A', $max['timestamp']) . ' (' . $max['value'] . ')';*/
-
?>
\ No newline at end of file