Skip to content

Commit

Permalink
A rework of emoncms focusing on an improved timestore based native fe…
Browse files Browse the repository at this point in the history
…ed engine and new nodes and inputs inerfaces
  • Loading branch information
glynhudson committed Feb 18, 2014
1 parent 10ae5c8 commit 8287b1b
Show file tree
Hide file tree
Showing 15 changed files with 1,009 additions and 190 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ settings.php
Modules/sync
Modules/event
Modules/energyaudit
Modules/node
Modules/auto
Modules/energy
Modules/energyform
Expand Down
48 changes: 46 additions & 2 deletions Modules/feed/engine/PHPFina.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public function post($id,$timestamp,$value)

$meta->npoints = $pos + 1;
$this->set_meta($id,$meta);

return $value;
}

/**
Expand All @@ -109,9 +111,51 @@ public function post($id,$timestamp,$value)
* @param integer $time The unix timestamp of the data point, in seconds
* @param float $value The value of the data point
*/
public function update($feedid,$time,$value)
public function update($id,$timestamp,$value)
{

$id = (int) $id;
$timestamp = (int) $timestamp;
$value = (float) $value;

// If meta data file does not exist then exit
if (!$meta = $this->get_meta($id)) return false;

// Calculate interval that this datapoint belongs too
$timestamp = floor($timestamp / $meta->interval) * $meta->interval;

// If this is a new feed (npoints == 0) then set the start time to the current datapoint
if ($meta->npoints == 0) {
$meta->start_time = $timestamp;
}

if ($timestamp < $meta->start_time) {
return false; // in the past
}

// Calculate position in base data file of datapoint
$pos = floor(($timestamp - $meta->start_time) / $meta->interval);

$last_pos = $meta->npoints - 1;

$fh = fopen($this->dir.$meta->id.".dat", 'c+');

// Write padding
$padding = ($pos - $last_pos)-1;
if ($padding>0) $this->write_padding($fh,$meta->npoints,$padding);

// Write new datapoint
fseek($fh,4*$pos);
if (!is_nan($value)) fwrite($fh,pack("f",$value)); else fwrite($fh,pack("f",NAN));

// Close file
fclose($fh);

if (($pos+1)>$meta->npoints) {
$meta->npoints = $pos + 1;
$this->set_meta($id,$meta);
}

return $value;
}

/**
Expand Down
11 changes: 11 additions & 0 deletions Modules/feed/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ var feed = {
return result;
},

'list_assoc':function()
{
var result = {};
$.ajax({ url: path+"feed/list.json", dataType: 'json', async: false, success: function(data) {result = data;} });

var feeds = {};
for (z in result) feeds[result[z].id] = result[z];

return feeds;
},

'list_by_id':function()
{
var feeds = {};
Expand Down
28 changes: 28 additions & 0 deletions Modules/input/Views/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ var input = {
$.ajax({ url: path+"input/list.json", dataType: 'json', async: false, success: function(data) {result = data;} });
return result;
},

'list_assoc':function()
{
var result = {};
$.ajax({ url: path+"input/list.json", dataType: 'json', async: false, success: function(data) {result = data;} });

var inputs = {};
for (z in result) inputs[result[z].id] = result[z];

return inputs;
},

'set':function(id, fields)
{
Expand All @@ -33,6 +44,23 @@ var input = {
{
var result = {};
$.ajax({ url: path+"input/process/list.json", data: "inputid="+inputid, async: false, dataType: 'json', success: function(data){result = data;} });
var processlist = [];
if (result!="")
{
var tmp = result.split(",");
for (n in tmp)
{
var process = tmp[n].split(":");
processlist.push(process);
}
}
return processlist;
},

'getallprocesses':function(inputid)
{
var result = {};
$.ajax({ url: path+"input/getallprocesses.json", data: "inputid="+inputid, async: false, dataType: 'json', success: function(data){result = data;} });
return result;
},

Expand Down
4 changes: 2 additions & 2 deletions Modules/input/Views/input_node.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
table.fields = {
//'id':{'type':"fixed"},
'nodeid':{'title':'<?php echo _("Node:"); ?>','type':"fixed"},
'name':{'title':'<?php echo _("name"); ?>','type':"text"},
'description':{'title':'<?php echo _('Description'); ?>','type':"text"},
'name':{'title':'<?php echo _("Key"); ?>','type':"text"},
'description':{'title':'<?php echo _("Name"); ?>','type':"text"},
'processList':{'title':'<?php echo _('Process list'); ?>','type':"processlist"},
'time':{'title':'last updated', 'type':"updated"},
'value':{'type':"value"},
Expand Down
24 changes: 24 additions & 0 deletions Modules/input/Views/process_info.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8287b1b

Please sign in to comment.