qminer
Version:
A C++ based data analytics platform for processing large-scale real-time streams containing structured and unstructured data
1,082 lines (1,077 loc) • 76.5 kB
HTML
<!doctype html>
<html>
<head>
<meta name="generator" content="JSDoc 3">
<meta charset="utf-8">
<title>Class: StreamAggr</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
<link href="css/baseline.css" rel="stylesheet">
</head>
<body onload="prettyPrint()">
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">QMiner JavaScript API v9.4.0</a>
</div>
</div>
</nav>
<div id="jsdoc-body-container">
<div id="jsdoc-content">
<div id="jsdoc-content-container">
<div id="jsdoc-main" role="main">
<header class="page-header">
<div class="symbol-detail-labels"><span class="label label-kind">class</span> <span class="label label-static">static</span></div>
<h1><small><a href="module-qm.html">qm</a>.<wbr></small><span class="symbol-name">StreamAggr</span></h1>
<p class="source-link">Source: <a href="qminer_aggrdoc.js.html#source-line-83">qminer_aggrdoc.<wbr>js:83</a></p>
<div class="symbol-classdesc">
<p>Represents a stream aggregate. The class can construct these <a href="module-qm.html#~StreamAggregator">module:qm~StreamAggregator</a> objects. Also turn to these stream aggregators to see
which methods are implemented.</p>
</div>
<dl class="dl-compact">
</dl>
</header>
<section id="summary">
<div class="summary-callout">
<h2 class="summary-callout-heading">Properties</h2>
<div class="summary-content">
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-qm.StreamAggr.html#init">init</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-qm.StreamAggr.html#name">name</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-qm.StreamAggr.html#val">val</a></dt>
<dd>
</dd>
</dl>
</div>
</div>
</div>
<div class="summary-callout">
<h2 class="summary-callout-heading">Methods</h2>
<div class="summary-content">
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-qm.StreamAggr.html#getFeatureSpace">getFeatureSpace()</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#getFloat">getFloat([str])</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#getFloatAt">getFloatAt(idx)</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#getFloatLength">getFloatLength()</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#getFloatVector">getFloatVector()</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#getInFloatVector">getInFloatVector()</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#getInteger">getInteger([str])</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#getInTimestampVector">getInTimestampVector()</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#getInValueVector">getInValueVector()</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#getNumberOfRecords">getNumberOfRecords()</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#getOutFloatVector">getOutFloatVector()</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-qm.StreamAggr.html#getOutTimestampVector">getOutTimestampVector()</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#getOutValueVector">getOutValueVector()</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#getParams">getParams()</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#getTimestamp">getTimestamp()</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#getTimestampAt">getTimestampAt(idx)</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#getTimestampLength">getTimestampLength()</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#getTimestampVector">getTimestampVector()</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#getValueVector">getValueVector()</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#load">load(fin)</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#loadStateJson">loadStateJson(state)</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#onAdd">onAdd(rec[, Caller])</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-qm.StreamAggr.html#onDelete">onDelete(rec[, Caller])</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#onStep">onStep([Caller])</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#onTime">onTime(ts[, Caller])</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#onUpdate">onUpdate(rec[, Caller])</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#reset">reset()</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#save">save(fout)</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#saveJson">saveJson([limit])</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#saveStateJson">saveStateJson()</a></dt>
<dd>
</dd>
<dt><a href="module-qm.StreamAggr.html#setParams">setParams(params)</a></dt>
<dd>
</dd>
</dl>
</div>
</div>
</div>
</section>
<section>
<h2 id="StreamAggr">new <span class="symbol-name">StreamAggr</span><span class="signature"><span class="signature-params">(base, arg[, storeName])</span></span></h2>
<p>Stream Aggregate</p>
<section>
<h3>
Example
</h3>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a simple base containing one store
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "People",
fields: [
{ name: "Name", type: "string" },
{ name: "Gendre", type: "string" },
]
},
{
name: "Laser",
fields: [
{ name: "Time", type: "datetime" },
{ name: "WaveLength", type: "float" }
]
}]
});
// create a new stream aggregator for 'People' store, get the length of the record name (with the function object)
var aggr = new qm.StreamAggr(base, new function () {
var numOfAdds = 0;
var numOfUpdates = 0;
var numOfDeletes = 0;
var time = "";
this.name = 'nameLength',
this.onAdd = function (rec) {
numOfAdds += 1;
};
this.onUpdate = function (rec) {
numOfUpdates += 1;
};
this.onDelete = function (rec) {
numOfDeletes += 1;
};
this.onTime = function (ts) {
time = ts;
};
this.saveJson = function (limit) {
return { adds: numOfAdds, updates: numOfUpdates, deletes: numOfDeletes, time: time };
};
}, "People");
// create a new time series window buffer stream aggregator for 'Laser' store (with the JSON object)
var wavelength = {
name: "WaveLengthLaser",
type: "timeSeriesWinBuf",
store: "Laser",
timestamp: "Time",
value: "WaveLength",
winsize: 10000
}
var sa = base.store("Laser").addStreamAggr(wavelength);
base.close();</code></pre>
</div>
</section>
<section>
<h3>Parameters</h3>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>base</p>
</td>
<td>
<p><a href="module-qm.Base.html">module:qm.Base</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The base object on which it's created.</p>
</td>
</tr>
<tr>
<td>
<p>arg</p>
</td>
<td>
<p>(<a href="module-qm.html#~StreamAggregator">module:qm~StreamAggregator</a> or function())</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Constructor arguments. There are two argument types:
<br>1. Using the <a href="module-qm.html#~StreamAggregator">module:qm~StreamAggregator</a> object,
<br>2. using a function/JavaScript class. The function has defined The object containing the schema of the stream aggregate or the function object defining the operations of the stream aggregate.
</p>
</td>
</tr>
<tr>
<td>
<p>storeName</p>
</td>
<td>
<p>(string or Array of string)</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>The store names where the aggregate will be registered.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
</dl>
</section>
<section>
<h2>Properties</h2>
<section>
<h3 id="init"><span class="symbol-name">init</span></h3>
<p>Returns true when the stream aggregate has enough data to initialize its internal state. Type <code>init</code>.</p>
<dl class="dl-compact">
</dl>
<h3 id="name"><span class="symbol-name">name</span></h3>
<p>Returns the name of the stream aggregate. Type <code>string</code>.</p>
<dl class="dl-compact">
</dl>
<h3 id="val"><span class="symbol-name">val</span></h3>
<p>Returns the JSON object of the stream aggregate. Same as the method saveJson. Type <code>object</code>.</p>
<dl class="dl-compact">
</dl>
</section>
<h2>Methods</h2>
<section>
<h3 id="getFeatureSpace"><span class="symbol-name">getFeatureSpace</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> <a href="module-qm.FeatureSpace.html">module:qm.FeatureSpace</a></span></span></h3>
<p>Returns a feature space.</p>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-qm.FeatureSpace.html">module:qm.FeatureSpace</a></code>B The feature space.</p>
</dd>
</dl>
<h3 id="getFloat"><span class="symbol-name">getFloat</span><span class="signature"><span class="signature-params">([str])</span> → <span class="signature-returns"> (number or null)</span></span></h3>
<p>Returns the value of the specific stream aggregator. For return values see <a href="module-qm.html#~StreamAggregator">module:qm~StreamAggregator</a>.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a simple base containing one store
var base = new qm.Base({
mode: 'createClean',
schema: [{
name: 'Grades',
fields: [
{ name: 'Grade', type: 'int' },
{ name: 'Procents', type: 'float' },
{ name: 'Time', type: 'datetime' }
]
}]
});
// create a new time series stream aggregator which takes the values from the 'Procents' field
// and the timestamp from the 'Time' field. The size of the window is 1 year.
var ts = {
name: 'GradesAggr',
type: 'timeSeriesWinBuf',
store: 'Grades',
timestamp: 'Time',
value: 'Procents',
winsize: 31536000000
};
var timeSeries = base.store('Grades').addStreamAggr(ts);
// create a new moving average stream aggregator that takes the values from the
// 'GradesAggr' stream aggregator
var ma = {
name: 'AverageGrade',
type: 'ma',
store: 'Grades',
inAggr: 'GradesAggr'
}
var averageGrade = base.store('Grades').addStreamAggr(ma);
// add some grades in the 'Grades' store
base.store("Grades").push({ Grade: 7, Procents: 65, Time: '2014-11-23T10:00:00.0' });
base.store("Grades").push({ Grade: 9, Procents: 88, Time: '2014-12-20T12:00:00.0' });
base.store("Grades").push({ Grade: 8, Procents: 70, Time: '2015-02-03T10:00:00.0' });
// get the average grade procents by using the getFloat method
var average = averageGrade.getFloat(); // returns 74 + 1/3
base.close();</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>str</p>
</td>
<td>
<p>string</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>The string.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>(number or null)</code>B A number (stream aggregator specific), possibly null if <code>str</code> was provided.</p>
</dd>
</dl>
<h3 id="getFloatAt"><span class="symbol-name">getFloatAt</span><span class="signature"><span class="signature-params">(idx)</span> → <span class="signature-returns"> number</span></span></h3>
<p>Returns the value of the vector containing the values of the stream aggregator at a specific index.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a simple base containing one store
var base = new qm.Base({
mode: 'createClean',
schema: [{
name: 'MusicSale',
fields: [
{ name: 'NumberOfAlbums', type: 'float' },
{ name: 'Time', type: 'datetime' }
]
}]
});
// create a time series containing the 'NumberOfAlbums' values and getting the timestamp from the 'Time' field.
// The window size should be 1 week.
var ts = {
name: 'Sales',
type: 'timeSeriesWinBuf',
store: 'MusicSale',
timestamp: 'Time',
value: 'NumberOfAlbums',
winsize: 604800000
};
var weekSales = base.store('MusicSale').addStreamAggr(ts);
// add some records in the store
base.store('MusicSale').push({ NumberOfAlbums: 10, Time: '2015-03-15T00:00:00.0' });
base.store('MusicSale').push({ NumberOfAlbums: 15, Time: '2015-03-18T00:00:00.0' });
base.store('MusicSale').push({ NumberOfAlbums: 30, Time: '2015-03-19T00:00:00.0' });
base.store('MusicSale').push({ NumberOfAlbums: 45, Time: '2015-03-20T00:00:00.0' });
// get the second value of the value vector
var albums = weekSales.getFloatAt(1); // returns 15
base.close();</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>idx</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The index.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>number</code>B The value of the float vector at position <code>idx</code>.</p>
</dd>
</dl>
<h3 id="getFloatLength"><span class="symbol-name">getFloatLength</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> number</span></span></h3>
<p>Gets the length of the vector containing the values of the stream aggregator.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a simple base containing one store
var base = new qm.Base({
mode: 'createClean',
schema: [{
name: 'IceCreams',
fields: [
{ name: 'Type', type: 'string' },
{ name: 'Price', type: 'float' },
{ name: 'TimeOfConsumption', type: 'datetime' }
]
}]
});
// create a time series stream aggregator, that takes values from the 'Price' field and the timestamp
// from the 'TimeOfConsumation' field of 'IceCream' store. The window size should be 1 day.
var ts = {
name: 'IcePrice',
type: 'timeSeriesWinBuf',
store: 'IceCreams',
timestamp: 'TimeOfConsumption',
value: 'Price',
winsize: 86400000
};
var icePrice = base.store('IceCreams').addStreamAggr(ts);
// add some ice creams in the store
base.store('IceCreams').push({ Type: 'Chocholate', Price: 5, TimeOfConsumption: '2015-07-21T09:00:00.0' });
base.store('IceCreams').push({ Type: 'Blue Sky', Price: 3, TimeOfConsumption: '2015-07-21T14:13:00.0' });
base.store('IceCreams').push({ Type: 'Stracciatella', Price: 5, TimeOfConsumption: '2015-07-21T21:05:00.0' });
// get the number of ice creams consumed by using getFloatLength method
var numberOfIceCreamsEaten = icePrice.getFloatLength(); // returns 3
base.close();</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>number</code>B The length of the vector.</p>
</dd>
</dl>
<h3 id="getFloatVector"><span class="symbol-name">getFloatVector</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Gets the whole vector of values of the stream aggregator.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a simple base containing one store
var base = new qm.Base({
mode: 'createClean',
schema: [{
name: 'Hospital',
fields: [
{ name: 'NumberOfPatients', type: 'float' },
{ name: 'Date', type: 'datetime' }
]
}]
});
// create a new time series stream aggregator that takes the values from the 'NumberOfPatients' field
// and the timestamp from the 'Date' field. The window size should be 1 week.
var ts = {
name: 'WeekPatients',
type: 'timeSeriesWinBuf',
store: 'Hospital',
timestamp: 'Date',
value: 'NumberOfPatients',
winsize: 604800000
};
var weekPatients = base.store('Hospital').addStreamAggr(ts);
// add some records in the store
base.store('Hospital').push({ NumberOfPatients: 50, Date: '2015-05-20T00:00:00.0' });
base.store('Hospital').push({ NumberOfPatients: 56, Date: '2015-05-21T00:00:00.0' });
base.store('Hospital').push({ NumberOfPatients: 120, Date: '2015-05-22T00:00:00.0' });
base.store('Hospital').push({ NumberOfPatients: 40, Date: '2015-05-23T00:00:00.0' });
// get the values that are in the time series window buffer as a vector
var values = weekPatients.getFloatVector(); // returns the vector [50, 56, 120, 40]
base.close();</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Vector.html">module:la.Vector</a></code>B The vector containing the values of the buffer.</p>
</dd>
</dl>
<h3 id="getInFloatVector"><span class="symbol-name">getInFloatVector</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Gets a vector containing the values that are entering the stream aggregator.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a simple base containing one store
var base = new qm.Base({
mode: 'createClean',
schema: [{
name: 'Noise',
fields: [
{ name: 'Decibels', type: 'float' },
{ name: 'Time', type: 'datetime' }
]
}]
});
// create a time series stream aggregator that takes the values from the 'Decibels' field
// and timestamps from the 'Time' fields. The window size should be 1 second.
var ts = {
name: 'Music',
type: 'timeSeriesWinBuf',
store: 'Noise',
timestamp: 'Time',
value: 'Decibels',
winsize: 1000
};
var music = base.store('Noise').addStreamAggr(ts);
// add some records in the store
base.store('Noise').push({ Decibels: 54, Time: '2015-07-21T14:43:00.0' });
base.store('Noise').push({ Decibels: 55, Time: '2015-07-21T14:43:00.200' });
base.store('Noise').push({ Decibels: 53, Time: '2015-07-21T14:43:00.800' });
base.store('Noise').push({ Decibels: 54, Time: '2015-07-21T14:43:01.0' });
base.store('Noise').push({ Decibels: 53, Time: '2015-07-21T14:43:01.2' });
// get the in vector
var vec = music.getInFloatVector();
base.close();</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Vector.html">module:la.Vector</a></code>B The vector containing the values that are entering the buffer.</p>
</dd>
</dl>
<h3 id="getInteger"><span class="symbol-name">getInteger</span><span class="signature"><span class="signature-params">([str])</span> → <span class="signature-returns"> (number or null)</span></span></h3>
<p>A map from strings to integers</p>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>str</p>
</td>
<td>
<p>string</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>The string.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>(number or null)</code>B A number (stream aggregator specific), possibly null if <code>str</code> was provided.</p>
</dd>
</dl>
<h3 id="getInTimestampVector"><span class="symbol-name">getInTimestampVector</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Gets a vector containing the timestamps that are entering the stream aggregator.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a simple base containing one store
var base = new qm.Base({
mode: 'createClean',
schema: [{
name: 'Noise',
fields: [
{ name: 'Decibels', type: 'float' },
{ name: 'Time', type: 'datetime' }
]
}]
});
// create a time series stream aggregator that takes the values from the 'Decibels' field
// and timestamps from the 'Time' fields. The window size should be 1 second.
var ts = {
name: 'Music',
type: 'timeSeriesWinBuf',
store: 'Noise',
timestamp: 'Time',
value: 'Decibels',
winsize: 1000
};
var music = base.store('Noise').addStreamAggr(ts);
// add some records in the store
base.store('Noise').push({ Decibels: 54, Time: '2015-07-21T14:43:00.0' });
base.store('Noise').push({ Decibels: 55, Time: '2015-07-21T14:43:00.200' });
base.store('Noise').push({ Decibels: 53, Time: '2015-07-21T14:43:00.800' });
base.store('Noise').push({ Decibels: 54, Time: '2015-07-21T14:43:01.0' });
base.store('Noise').push({ Decibels: 53, Time: '2015-07-21T14:43:01.2' });
// get the in timestamps
var vec = music.getInTimestampVector();
base.close();</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Vector.html">module:la.Vector</a></code>B The vector containing the timestamps that are entering the buffer.</p>
</dd>
</dl>
<h3 id="getInValueVector"><span class="symbol-name">getInValueVector</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> (<a href="module-la.Vector.html">module:la.Vector</a> or <a href="module-la.SparseMatrix.html">module:la.SparseMatrix</a>)</span></span></h3>
<p>Gets the vector of 'just-in' values (values that have just entered the buffer). Values can be floats or sparse vectors.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a simple base containing one store
var base = new qm.Base({
mode: 'createClean',
schema: [{
name: 'Docs',
fields: [
{ name: 'Time', type: 'datetime' },
{ name: 'Text', type: 'string' }
]
}]
});
store = base.store('Docs');
// the following aggregate maintains a window buffer (1000 milliseconds) with no delay
// and contains a categorical feature extractor. The extractor maps records in the buffer
// to sparse vectors (indicator vectors for growing set of categories). Each record that
// enters the buffer updates the feature extractor (potentially introduces a new category,
// which increases the dimensionality).
var aggr = {
type: 'timeSeriesWinBufFeatureSpace',
store: 'Docs',
timestamp: 'Time',
featureSpace: {
type: "categorical",
source: "Docs",
field: "Text"
},
winsize: 1000
};
var streamAggregate = store.addStreamAggr(aggr);
store.push({ Time: '2015-06-10T14:13:32.0', Text: 'a' });
store.push({ Time: '2015-06-10T14:13:33.0', Text: 'b' });
store.push({ Time: '2015-06-10T14:13:34.0', Text: 'c' });
// we have three dimensions, where "a" -> [1,0,0], "b" -> [0,1,0], "c" -> [0,0,1]
// the first record just fell out of the buffer, the third record just entered the buffer
// and buffer currently contains the second and the third record.
// In case of the feature space based window buffer, the vectors of just-in, just-out and in-the-buffer
// values correspond to vectors of sparse vectors = sparse matrices.
streamAggregate.getInValueVector().print(); // one column, one nonzero element at index 2
// = [
// 2 0 1.000000
// ]
streamAggregate.getOutValueVector().print(); // one column, one nonzero element at index 0
// = [
// 0 0 1.000000
// ]
streamAggregate.getValueVector().print(); // two column vectors, each with one nonzero element
// = [
// 1 0 1.000000
// 2 1 1.000000
// ]
base.close();</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>(<a href="module-la.Vector.html">module:la.Vector</a> or <a href="module-la.SparseMatrix.html">module:la.SparseMatrix</a>)</code>B The vector or sparse matrix of values that just entered the buffer.</p>
</dd>
</dl>
<h3 id="getNumberOfRecords"><span class="symbol-name">getNumberOfRecords</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> number</span></span></h3>
<p>Gets the number of records in the stream aggregator.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a simple base containing one store
var base = new qm.Base({
mode: 'createClean',
schema: [{
name: 'MusicSale',
fields: [
{ name: 'NumberOfAlbums', type: 'float' },
{ name: 'Time', type: 'datetime' }
]
}]
});
// create a time series containing the values from the 'NumberOfAlbums' field and
// the timestamp from the 'Time' field. The window size should be 1 week.
var ts = {
name: 'Sales',
type: 'timeSeriesWinBuf',
store: 'MusicSale',
timestamp: 'Time',
value: 'NumberOfAlbums',
winsize: 604800000
};
var weekSales = base.store('MusicSale').addStreamAggr(ts);
// add some records in the store
base.store('MusicSale').push({ NumberOfAlbums: 10, Time: '2015-03-15T00:00:00.0' });
base.store('MusicSale').push({ NumberOfAlbums: 15, Time: '2015-03-18T00:00:00.0' });
base.store('MusicSale').push({ NumberOfAlbums: 30, Time: '2015-03-19T00:00:00.0' });
base.store('MusicSale').push({ NumberOfAlbums: 45, Time: '2015-03-20T00:00:00.0' });
// get the number of records in the window buffer
var num = weekSales.getNumberOfRecords(); // returns 4
base.close();</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>number</code>B The number of records in the buffer.</p>
</dd>
</dl>
<h3 id="getOutFloatVector"><span class="symbol-name">getOutFloatVector</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Gets a vector containing the values that are leaving the stream aggregator.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a simple base containing one store
var base = new qm.Base({
mode: 'createClean',
schema: [{
name: 'F1',
fields: [
{ name: 'Driver', type: 'string' },
{ name: 'Speed', type: 'float' },
{ name: 'Time', type: 'datetime' }
]
}]
});
// create a time series stream aggregator that gets the values from the 'Speed' field
// and the timestamp from the 'Time' field. The window size should be 5 minutes.
var ts = {
name: 'Sensor',
type: 'timeSeriesWinBuf',
store: 'F1',
timestamp: 'Time',
value: 'Speed',
winsize: 300000
};
var sensor = base.store('F1').addStreamAggr(ts);
// add some records to the store
base.store('F1').push({ Driver: 'Sebastian Vettel', Speed: 203.4, Time: '2015-07-19T09:32:01.0' });
base.store('F1').push({ Driver: 'Thomas "Tommy" Angelo', Speed: 152.8, Time: '2015-07-19T09:35:23.0' });
base.store('F1').push({ Driver: 'Mark Ham', Speed: 189.5, Time: '2015-07-19T09:38:43.0' });
base.store('F1').push({ Driver: 'Speedy Gonzales', Speed: 171.4, Time: '2015-07-19T09:40:32.0' });
// get the values, that have got out of the window buffer.
// because the window size is 5 seconds, the last value that have left the buffer is 152.8
var left = sensor.getOutFloatVector(); // returns [152.8]
base.close();</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Vector.html">module:la.Vector</a></code>B The vector containing the values that are leaving the buffer.</p>
</dd>
</dl>
<h3 id="getOutTimestampVector"><span class="symbol-name">getOutTimestampVector</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Gets a vector containing the timestamps that are leaving the stream aggregator.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a simple base containing one store
var base = new qm.Base({
mode: 'createClean',
schema: [{
name: 'Noise',
fields: [
{ name: 'Decibels', type: 'float' },
{ name: 'Time', type: 'datetime' }
]
}]
});
// create a time series stream aggregator that takes the values from the 'Decibels' field
// and timestamps from the 'Time' fields. The window size should be 1 second.
var ts = {
name: 'Music',
type: 'timeSeriesWinBuf',
store: 'Noise',
timestamp: 'Time',
value: 'Decibels',
winsize: 1000
};
var music = base.store('Noise').addStreamAggr(ts);
// add some records in the store
base.store('Noise').push({ Decibels: 54, Time: '2015-07-21T14:43:00.0' });
base.store('Noise').push({ Decibels: 55, Time: '2015-07-21T14:43:00.200' });
base.store('Noise').push({ Decibels: 54, Time: '2015-07-21T14:43:00.400' });
base.store('Noise').push({ Decibels: 53, Time: '2015-07-21T14:43:00.600' });
base.store('Noise').push({ Decibels: 53, Time: '2015-07-21T14:43:00.800' });
base.store('Noise').push({ Decibels: 54, Time: '2015-07-21T14:43:01.0' });
base.store('Noise').push({ Decibels: 53, Time: '2015-07-21T14:43:01.2' });
// get the timestamps that just left the window buffer by adding the last record
var last = music.getOutTimestampVector(); // returns [13081963380000]
base.close();</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Vector.html">module:la.Vector</a></code>B The vector containing the leaving timestamps.</p>
</dd>
</dl>
<h3 id="getOutValueVector"><span class="symbol-name">getOutValueVector</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> (<a href="module-la.Vector.html">module:la.Vector</a> or <a href="module-la.SparseMatrix.html">module:la.SparseMatrix</a>)</span></span></h3>
<p>Gets the vector of 'just-out' values (values that have just fallen out of the buffer). Values can be floats or sparse vectors.
For use example see <a href="module-qm.StreamAggr.html#getOutFloatVector">module:qm.StreamAggr#getOutFloatVector</a> example.</p>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>(<a href="module-la.Vector.html">module:la.Vector</a> or <a href="module-la.SparseMatrix.html">module:la.SparseMatrix</a>)</code>B Vector of floats or a vector of sparse vectors.</p>
</dd>
</dl>
<h3 id="getParams"><span class="symbol-name">getParams</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> Object</span></span></h3>
<p>Returns all the parameters of the stream aggregate</p>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Object</code>B parameters</p>
</dd>
</dl>
<h3 id="getTimestamp"><span class="symbol-name">getTimestamp</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> number</span></span></h3>
<p>Returns the timestamp value of the newest record in buffer.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a simple base containing one store
var base = new qm.Base({
mode: 'createClean',
schema: [{
name: 'GameCollection',
fields: [
{ name: 'GameName', type: 'string' },
{ name: 'Price', type: 'float' },
{ name: 'ReleaseDate', type: 'datetime' }
]
}]
});
// create a new time series stream aggregator which takes the values from the 'Price' field
// and the timestamps from the 'ReleaseDate' field. The window size should be 1 month.
var ts = {
name: 'GameSeries',
type: 'timeSeriesWinBuf',
store: 'GameCollection',
timestamp: 'ReleaseDate',
value: 'Price',
winsize: 2678400000
};
var timeSeries = base.store('GameCollection').addStreamAggr(ts);
// create a new sum stream aggregator
var sum = {
name: 'SumPrice',
type: 'winBufSum',
store: 'GameCollection',
inAggr: 'GameSeries'
};
var priceSum = base.store('GameCollection').addStreamAggr(sum);
// put some records in the store
base.store('GameCollection').push({ GameName: 'Tetris', Price: 0, ReleaseDate: '1984-06-06T00:00:00.0' });
base.store('GameCollection').push({ GameName: 'Super Mario Bros.', Price: 100, ReleaseDate: '1985-09-13T00:00:00.0' });
base.store('GameCollection').push({ GameName: 'The Legend of Zelda', Price: 90, ReleaseDate: '1986-02-21T00:00:00.0 '});
// get the timestamp of the last bought game by using getTimestamp
var date = priceSum.getTimestamp(); // returns 12153801600000 (the miliseconds since 1601-01-01T00:00:00.0)
base.close();</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>number</code>B The timestamp of the newest record. It represents the number of miliseconds between the record time and 01.01.1601 time: 00:00:00.0.</p>
</dd>
</dl>
<h3 id="getTimestampAt"><span class="symbol-name">getTimestampAt</span><span class="signature"><span class="signature-params">(idx)</span> → <span class="signature-returns"> number</span></span></h3>
<p>Gets the timestamp from the timestamp vector of the stream aggregator at the specific index.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a simple base containing one store
var base = new qm.Base({
mode: 'createClean',
schema: [{
name: 'Route66',
fields: [
{ name: 'NumberOfCars', type: 'float' },
{ name: 'Time', type: 'datetime' }
]
}]
});
// create a time series stream aggregator that takes the values from the 'NumberOfCars' field
// and the timestamps from the 'Time' field. The window size should be 1 day.
var ts = {
name: 'Traffic',
type: 'timeSeriesWinBuf',
store: 'Route66',
timestamp: 'Time',
value: 'NumberOfCars',
winsize: 86400000
};
var traffic = base.store('Route66').addStreamAggr(ts);
// add some records in the store
base.store('Route66').push({ NumberOfCars: 100, Time: '2015-06-15T06:00:00.0' });
base.store('Route66').push({ NumberOfCars: 88, Time: '2015-06-15T:10:00.0' });
base.store('Route66').push({ NumberOfCars: 60, Time: '2015-06-15T13:00:00.0' });
base.store('Route66').push({ NumberOfCars: 90, Time: '2015-06-15T18:00:00.0' });
base.store('Route66').push({ NumberOfCars: 110, Time: '2015-06-16T00:00:00.0' });
// get the third timestamp in the buffer
var time = traffic.getTimestampAt(2); // returns 13078864800000
base.close();</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>idx</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The index.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>number</code>B The timestamp of the timestamp vector at position <code>idx</code>.</p>
</dd>
</dl>
<h3 id="getTimestampLength"><span class="symbol-name">getTimestampLength</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> nu