node-red-contrib-timeseries
Version:
A suite of Node-RED nodes providing an easy-to-use interface for working with a TimeSeries database.
220 lines (204 loc) • 9.79 kB
HTML
<!--
Copyright 2015 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script type="text/javascript">
RED.nodes.registerType( 'timeseries-- in' , {
category: 'storage-input',
color: '#bbe5ff',
defaults: {
timeseries: { type : "timeseries" , required : true },
name: { value : "" },
table : { value : "" , required : true },
idcolumn: { value : "" , required : true },
filter_id: { value : "" },
tscolumn: { value : "" , required : true },
end_type: { value : "now" },
end_ts: { value : "" , validate : function( v ) {
$end_type = $( "#node-input-end_type" );
var end_type = $end_type.length > 0 ? $end_type.val() : this.end_type;
if( end_type === "now" )
{
return true;
}
else
{
return !isNaN( Date.parse( v ) );
}
} },
start_value: { value : "0" , required : true , validate : function( v ) {
v = parseFloat( v );
return ( !isNaN( v ) && v > 0 );
} },
start_unit: { value : "seconds" , required : true }
},
inputs:1,
outputs:1,
icon: "timeseries.png",
label: function() {
return this.name || "timeseries simple";
},
oneditprepare : function() {
function zeropad( v )
{
return v < 10 ? "0" + v : v;
}
function updateStartTS( type )
{
var $tsInput = $( "#node-input-end_ts" );
var $container = $tsInput.parent( ".form-row" );
if( type === "now" )
{
$container.hide();
$tsInput.val( "" );
}
else
{
$container.show();
if( !$tsInput.val() )
{
var d = new Date();
$tsInput.val( zeropad( d.getMonth() + 1 ) + "/" + zeropad( d.getDate() ) + "/" + d.getFullYear() + " " +
zeropad( d.getHours() ) + ":" + zeropad( d.getMinutes() ) + ":" + zeropad( d.getSeconds() ) );
}
}
}
$( "#node-input-idcolumn" ).on( "change" , function() {
$( "#node-input-filter_id" ).attr( "placeholder" , "msg.payload." + $( this ).val() );
} );
$( "#node-input-end_type" ).on( "change" , function() {
updateStartTS( $( this ).val() );
} );
updateStartTS( this.end_type );
}
});
</script>
<script type="text/x-red" data-template-name="timeseries-- in">
<div class="form-row">
<label for="node-input-timeseries"><i class="fa fa-server"></i> Server</label>
<input type="text" id="node-input-timeseries">
</div>
<div class="form-row">
<label for="node-input-table"><i class="fa fa-table"></i> Table</label>
<input type="text" id="node-input-table" placeholder="Table">
</div>
<div class="form-row">
<label for="node-input-idcolumn"><i class="fa fa-columns"></i> Unique Column</label>
<input type="text" id="node-input-idcolumn" placeholder="Unique Column Name">
</div>
<div class="form-row">
<label for="node-input-filter_id"><i class="icon-tag"></i> ID</label>
<input type="text" id="node-input-filter_id" placeholder="ID">
</div>
<div class="form-row">
<label for="node-input-tscolumn"><i class="fa fa-columns"></i> TS Column</label>
<input type="text" id="node-input-tscolumn" placeholder="Timeseries Column Name">
</div>
<div class="form-row">
<label for="node-input-end_type"><i class="icon-time"></i> Select between</label>
<select id="node-input-end_type">
<option value="now">Now</option>
<option value="tstamp">Enter Date/Time...</option>
</select>
</div>
<div class="form-row">
<label for="node-input-end_ts"> </label>
<input type="text" id="node-input-end_ts" placeholder="Enter Date/Time">
</div>
<div class="form-row">
<label for="node-input-start_value">...and</label>
<input type="text" id="node-input-start_value" placeholder="#" style="width:40px">
<select id="node-input-start_unit" style="width:150px">
<option value="seconds">second(s)</option>
<option value="minutes">minute(s)</option>
<option value="hours">hour(s)</option>
<option value="days">day(s)</option>
<option value="weeks">week(s)</option>
<option value="months">month(s)</option>
<option value="years">year(s)</option>
</select> ago
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="timeseries-- in">
<p>This node is a simpler version of the TimeSeries aggregate node. Instead of performing aggregation, this node simply selects all TimeSeries data from one row in a TimeSeries table, between two configurable timestamps.</p>
<h4><strong>Configuration</strong></h4>
<p><strong>Server</strong> - The TimeSeries database server to connect to. Like the previous TimeSeries nodes, this node makes use of the TimeSeries configuration node included in this package.</p>
<p><strong>Table</strong> - The TimeSeries table to select from.</p>
<p><strong>Unique Column</strong> - The name of the unique column used to filter by. The name of the column will also be used to find the unique key value in the incoming JSON (<code>msg.payload.<unique_column></code>).</p>
<p><strong>ID</strong> (Optional) - An unique value (i.e. unique ID of the sensor) used to filter the result. If an ID is received through <code>msg.payload</code>, however, it will override this field.</p>
<p><strong>TS Column</strong> - Name of the column containing TimeSeries data.</p>
<p><strong>Select between ... and ...</strong> - The time period to retrieve data from.</p>
<p>The end timestamp can be set to <code>Now</code> which will use the current date and time, or it can be set to an absolute timestamp. The node will attempt to parse any date/time string entered, and will immediately let you know if something is wrong.</p>
<p>The start timestamp is calculated based on the end timestamp.</p>
<p><em>Example 1: Select all data from 2014</em></p>
<ul>
<li>Select between <code>12/31/2014</code> and <code>1</code> <code>year(s)</code> ago.</li>
</ul>
<p><em>Example 2: Select data for the last 3 months</em></p>
<ul>
<li>Select between <code>Now</code> and <code>3</code> <code>month(s)</code> ago.</li>
</ul>
<p>The node will also look for start and end timestamps (UNIX timestamps in milliseconds) in the incoming JSON (<code>msg.payload.start</code> and <code>msg.payload.end</code>). Both are optional, but, when available, they will override the values configured in the node.</p>
<pre><code>msg.payload = { ...
// 06/30/2015
start : 1435622400000,
// 07/30/2015
end : 1438214400000
... }
</code></pre>
<p>These methods can also be combined. For example, you could only supply an end timestamp through <code>msg.payload.end</code> and configure the node to calculate the start timestamp based on it.</p>
<p><em>Note: If the end timestamp is before the start timestamp, the node will automatically flip the values.</em></p>
<p><strong>Name</strong> - An optional label for the node.</p>
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType( 'timeseries-- out' , {
category: 'storage-output',
color: '#bbe5ff',
defaults: {
timeseries: { type : "timeseries" , required : true },
name: { value : "" },
table : { value : "" , required : true }
},
inputs:1,
outputs:0,
icon: "timeseries.png",
align: "right",
label: function() {
return this.name || "timeseries post";
}
});
</script>
<script type="text/x-red" data-template-name="timeseries-- out">
<div class="form-row">
<label for="node-input-timeseries"><i class="fa fa-server"></i> Server</label>
<input type="text" id="node-input-timeseries">
</div>
<div class="form-row">
<label for="node-input-table"><i class="fa fa-table"></i> Table</label>
<input type="text" id="node-input-table" placeholder="table">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="timeseries-- out">
<p>This node inserts data into a database using an HTTP POST request, and <code>msg.payload</code> as the body of the request.</p>
<h4><strong>Configuration</strong></h4>
<p><strong>Server</strong> - The TimeSeries database server to connect to. Like the previous TimeSeries nodes, this node makes use of the TimeSeries configuration node included in this package.</p>
<p><strong>Table</strong> - The table/collection to insert into.</p>
<p><strong>Name</strong> - An optional label for the node.</p>
</script>