Skip to content

Commit

Permalink
- Modularisation of feed storage engines, mysql, timestore, histogram.
Browse files Browse the repository at this point in the history
- Feed size calculator and refresh button
- db update004 for moving from `timestore` feeds field to `engine`
- removal of feed convert page as this is now moved to new converttotimestore module
- update timestore datapoint, scale timestore range of datapoints
  • Loading branch information
trystanlea committed Aug 28, 2013
1 parent 8e29478 commit 0787d25
Show file tree
Hide file tree
Showing 19 changed files with 183 additions and 793 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ Modules/rss
Modules/adminusers
Modules/feedconvert
Modules/report
Modules/notify
Modules/converttotimestore
4 changes: 2 additions & 2 deletions Lib/dbschemasetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function db_schema_setup($mysqli, $schema, $apply)
$type = $schema[$table][$field]['type'];
if (isset($schema[$table][$field]['Null'])) $null = $schema[$table][$field]['Null']; else $null = "YES";
if (isset($schema[$table][$field]['Key'])) $key = $schema[$table][$field]['Key']; else $key = null;
if (isset($schema[$table][$field]['default'])) $default = $schema[$table][$field]['default']; else $default = null;
if (isset($schema[$table][$field]['default'])) $default = $schema[$table][$field]['default']; else unset($default);
if (isset($schema[$table][$field]['Extra'])) $extra = $schema[$table][$field]['Extra']; else $extra = null;

// if field exists:
Expand All @@ -53,7 +53,7 @@ function db_schema_setup($mysqli, $schema, $apply)
$query = "";

if ($array['Type']!=$type) $query .= ";";
if ($array['Default']!=$default) $query .= " Default '$default'";
if (isset($default) && $array['Default']!=$default) $query .= " Default '$default'";
if ($array['Null']!=$null && $null=="NO") $query .= " not null";
if ($array['Extra']!=$extra && $extra=="auto_increment") $query .= " auto_increment";
if ($array['Key']!=$key && $key=="PRI") $query .= " primary key";
Expand Down
3 changes: 2 additions & 1 deletion Modules/admin/admin_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ function admin_controller()
$updates[] = $update->u0001($applychanges);
$updates[] = $update->u0002($applychanges);
$updates[] = $update->u0003($applychanges);

$updates[] = $update->u0004($applychanges);

}

$result = view("Modules/admin/update_view.php", array('applychanges'=>$applychanges, 'updates'=>$updates));
Expand Down
20 changes: 20 additions & 0 deletions Modules/admin/update_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,24 @@ function u0003($apply)
'operations'=>$operations
);
}

function u0004($apply)
{
$operations = array();
$result = $this->mysqli->query("SELECT id,timestore,engine FROM feeds");
while ($row = $result->fetch_object())
{
$id = $row->id;
$timestore = $row->timestore;

if ($timestore==1 && $row->engine==0) $operations[] = "Set feed engine for feed $id to timestore";
if ($timestore && $apply) $this->mysqli->query("UPDATE feeds SET `engine`='1' WHERE `id`='$id'");
}

return array(
'title'=>"Field name change",
'description'=>"Changed to more generic field name called engine rather than timestore specific",
'operations'=>$operations
);
}
}
2 changes: 1 addition & 1 deletion Modules/dashboard/dashboard_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct($mysqli)
public function create($userid)
{
$userid = (int) $userid;
$this->mysqli->query("INSERT INTO dashboard (`userid`) VALUES ('$userid')");
$this->mysqli->query("INSERT INTO dashboard (`userid`,`alias`) VALUES ('$userid','')");
return $this->mysqli->insert_id;
}

Expand Down
170 changes: 0 additions & 170 deletions Modules/feed/Views/feedconvert_view.php

This file was deleted.

15 changes: 10 additions & 5 deletions Modules/feed/Views/feedlist_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
<div class="container">
<div id="localheading"><h2><?php echo _('Feeds'); ?></h2></div>

<div class='alert alert-info'><i class='icon-star'></i> <b>Upgrade to timestore:</b> You can now prepare your feeds for conversion to timestore for query speeds that are several magnitudes faster. Select your prefered conversion interval rates on the <a href="<?php echo $path; ?>feed/convert" >conversion page</a>.</div>


<div id="table"></div>

<div id="nofeeds" class="alert alert-block hide">
<h4 class="alert-heading"><?php echo _('No feeds created'); ?></h4>
<p><?php echo _('Feeds are where your monitoring data is stored. The recommended route for creating feeds is to start by creating inputs (see the inputs tab). Once you have inputs you can either log them straight to feeds or if you want you can add various levels of input processing to your inputs to create things like daily average data or to calibrate inputs before storage. You may want to follow the link as a guide for generating your request.'); ?><a href="api"><?php echo _('Feed API helper'); ?></a></p>
</div>

<hr>
<button id="refreshfeedsize" class="btn btn-small" >Refresh feed size <i class="icon-refresh" ></i></button>
</div>

<div id="myModal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="false">
Expand All @@ -45,6 +45,7 @@

<script>


var path = "<?php echo $path; ?>";

// Extemd table library field types
Expand All @@ -57,10 +58,10 @@
'name':{'title':"<?php echo _('Name'); ?>", 'type':"text"},
'tag':{'title':"<?php echo _('Tag'); ?>", 'type':"text"},
'datatype':{'title':"<?php echo _('Datatype'); ?>", 'type':"select", 'options':['','REALTIME','DAILY','HISTOGRAM']},
'engine':{'title':"<?php echo _('Engine'); ?>", 'type':"select", 'options':['MYSQL','TIMESTORE']},
'public':{'title':"<?php echo _('Public'); ?>", 'type':"icon", 'trueicon':"icon-globe", 'falseicon':"icon-lock"},
'size':{'title':"<?php echo _('Size'); ?>", 'type':"fixed"},
'dpinterval':{'title':"<?php echo _('Interval'); ?>", 'type':"fixed"},


'time':{'title':"<?php echo _('Updated'); ?>", 'type':"updated"},
'value':{'title':"<?php echo _('Value'); ?>",'type':"value"},

Expand Down Expand Up @@ -120,5 +121,9 @@ function update()

$('#myModal').modal('hide');
});

$("#refreshfeedsize").click(function(){
$.ajax({ url: path+"feed/updatesize.json", success: function(data){update();} });
});

</script>
Binary file removed Modules/feed/Views/step1.png
Binary file not shown.
Binary file removed Modules/feed/Views/step2.png
Binary file not shown.
56 changes: 25 additions & 31 deletions Modules/feed/feed_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@ function feed_controller()
global $mysqli, $session, $route, $timestore_adminkey;
$result = false;

require "Modules/feed/timestore_class.php";
$timestore = new Timestore($timestore_adminkey);

include "Modules/feed/feed_model.php";
$feed = new Feed($mysqli,$timestore);
$feed = new Feed($mysqli,$timestore_adminkey);

if ($route->format == 'html')
{
if ($route->action == "convert" && $session['write']) $result = view("Modules/feed/Views/feedconvert_view.php",array());
if ($route->action == "list" && $session['write']) $result = view("Modules/feed/Views/feedlist_view.php",array());
if ($route->action == "api" && $session['write']) $result = view("Modules/feed/Views/feedapi_view.php",array());
}
Expand All @@ -48,12 +44,15 @@ function feed_controller()
}
elseif ($route->action == "create" && $session['write']) {
$result = $feed->create($session['userid'],get('name'),get('type'));
}
}
elseif ($route->action == "updatesize" && $session['write']) {
$result = $feed->update_user_feeds_size($session['userid']);
}
else {
$feedid = (int) get('id');
// Actions that operate on a single existing feed that all use the feedid to select:
// First we load the meta data for the feed that we want
$qresult = $mysqli->query("SELECT userid,public,timestore FROM feeds WHERE `id` = '$feedid'");
$qresult = $mysqli->query("SELECT userid,public,engine FROM feeds WHERE `id` = '$feedid'");
$row = $qresult->fetch_array();

if ($row) // if the feed exists
Expand All @@ -63,39 +62,34 @@ function feed_controller()
{
if ($route->action == "value") $result = $feed->get_field($feedid,'value');
if ($route->action == "get") $result = $feed->get_field($feedid,get('field')); // '/[^\w\s-]/'
if ($route->action == 'histogram') $result = $feed->get_histogram_data($feedid,get('start'),get('end'));
if ($route->action == 'kwhatpower') $result = $feed->get_kwhd_atpower($feedid,get('min'),get('max'));
if ($route->action == 'kwhatpowers') $result = $feed->get_kwhd_atpowers($feedid,get('points'));

if ($route->action == 'data' && $row['timestore']) $result = $feed->get_data_timestore($feedid,get('start'),get('end'),get('dp'));

if ($route->action == 'data' && !$row['timestore']) $result = $feed->get_data_mysql($feedid,get('start'),get('end'),get('dp'));

if ($route->action == 'histogram') $result = $feed->histogram_get_power_vs_kwh($feedid,get('start'),get('end'));
if ($route->action == 'kwhatpower') $result = $feed->histogram_get_kwhd_atpower($feedid,get('min'),get('max'));
if ($route->action == 'kwhatpowers') $result = $feed->histogram_get_kwhd_atpowers($feedid,get('points'));

if ($route->action == 'data') $result = $feed->get_data($feedid,get('start'),get('end'));
}

// write session required
if ($session['write'] && $session['userid']>0 && $row['userid']==$session['userid'])
{
// Storage engine agnostic
if ($route->action == 'set') $result = $feed->set_feed_fields($feedid,get('fields'));
if ($row['timestore'])
{
if ($route->action == "insert") $result = $feed->insert_data_timestore($feedid,time(),get("time"),get("value"));
if ($route->action == "delete") $result = $feed->delete_timestore($feedid);

if ($route->action == "export") $result = $feed->export_timestore($feedid,get('layer'),get('start'));
if ($route->action == "exportmeta") $result = $feed->export_timestore_meta($feedid);

if ($route->action == "getmeta") $result = $feed->get_timestore_meta($feedid);
}
else
if ($route->action == "insert") $result = $feed->insert_data($feedid,time(),get("time"),get("value"));
if ($route->action == "update") $result = $feed->update_data($feedid,time(),get("time"),get('value'));
if ($route->action == "delete") $result = $feed->delete($feedid);

if ($row['engine']==Engine::TIMESTORE)
{
if ($route->action == "insert") $result = $feed->insert_data($feedid,time(),get("time"),get("value"));
if ($route->action == "update") $result = $feed->update_data($feedid,time(),get("time"),get('value'));
if ($route->action == "deletedatapoint") $result = $feed->delete_data($feedid,get('feedtime'),get('feedtime'));
if ($route->action == "deletedatarange") $result = $feed->deletedatarange($feedid,get('start'),get('end'));
if ($route->action == "delete") $result = $feed->delete($feedid);
if ($route->action == "export") $result = $feed->timestore_export($feedid,get('layer'),get('start'));
if ($route->action == "exportmeta") $result = $feed->timestore_export_meta($feedid);
if ($route->action == "getmeta") $result = $feed->timestore_get_meta($feedid);
if ($route->action == "scalerange") $result = $feed->timestore_scale_range($feedid,get('start'),get('end'),get('value'));
} elseif ($row['engine']==Engine::MYSQL) {
if ($route->action == "export") $result = $feed->mysqltimeseries_export($feedid,get('start'));
if ($route->action == "deletedatapoint") $result = $feed->mysqltimeseries_delete_data_point($feedid,get('feedtime'));
if ($route->action == "deletedatarange") $result = $feed->mysqltimeseries_delete_data_range($feedid,get('start'),get('end'));

if ($route->action == "export") $result = $feed->export($feedid,get('start'));
}
}
}
Expand Down
Loading

0 comments on commit 0787d25

Please sign in to comment.