refactor $readings -> $data

This commit is contained in:
Steffen Vogel 2010-06-08 19:57:42 +02:00
parent c3027bc4f6
commit 9dc4986f6d
3 changed files with 8 additions and 8 deletions

View file

@ -43,10 +43,10 @@ class DataController extends Controller {
foreach ($channels as $channel) {
$jsonChannel = $this->view->getChannel($channel);
$jsonChannel['readings'] = array();
$jsonChannel['data'] = array();
foreach ($channel->getPulses($from, $to, $groupBy) as $reading) {
$jsonChannel['readings'][] = array($reading['timestamp'], $reading['value'], $reading['count']);
$jsonChannel['data'][] = array($reading['timestamp'], $reading['value'], $reading['count']);
}
$data['channels'][] = $jsonChannel;

View file

@ -35,19 +35,19 @@ abstract class Channel extends DatabaseObject implements ChannelInterface {
const table = 'channels';
public function delete() {
$this->reset(); // delete all readings if database doesn't support foreign keys
$this->reset(); // delete all data if database doesn't support foreign keys
parent::delete();
}
/*
* deletes all readings from database
* deletes all data from database
*/
public function reset($from = NULL, $to = NULL) {
$this->dbh->execute('DELETE FROM data WHERE channel_id = ' . (int) $this->id) . $this->buildTimeFilter($from, $to);
}
/*
* add a new reading to the database
* add a new data to the database
*/
public function addData($data) {
$sql = 'INSERT INTO data (channel_id, timestamp, value) VALUES(' . $this->dbh->escape($this) . ', ' . $this->dbh->escape($data['timestamp']) . ', ' . $this->dbh->escape($data['value']) . ')';
@ -55,7 +55,7 @@ abstract class Channel extends DatabaseObject implements ChannelInterface {
}
/*
* This function retrieve readings from the database. If desired it groups it into packages ($groupBy parameter)
* This function retrieve data from the database. If desired it groups it into packages ($groupBy parameter)
*
* @return array() Array with timestamps => value (sorted by timestamp from newest to oldest)
* @param $groupBy determines how readings are grouped. Possible values are: year, month, day, hour, minute or an integer for the desired size of the returned array

View file

@ -23,10 +23,10 @@ include '../../backend/init.php';
$meter = current(Channel::getByFilter(array('id' => 1)));
$readings = $meter->getData(0, time()*1000);
$data = $meter->getData(0, time()*1000);
echo '<table border="1">';
foreach ($readings as $i => $reading) {
foreach ($data as $i => $reading) {
echo '<tr><td>' . ($i + 1) . '</td><td>' . date('h:i:s', $reading['timestamp']/1000) . '</td><td>' . $reading['value'] . '</td><td>' . $reading['count'] . '</td></tr>';
}
echo '</table>';