UNPKG

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
<!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>&nbsp;<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&nbsp;<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 &#x3D; require(&#x27;qminer&#x27;); // create a simple base containing one store var base &#x3D; new qm.Base({ mode: &quot;createClean&quot;, schema: [{ name: &quot;People&quot;, fields: [ { name: &quot;Name&quot;, type: &quot;string&quot; }, { name: &quot;Gendre&quot;, type: &quot;string&quot; }, ] }, { name: &quot;Laser&quot;, fields: [ { name: &quot;Time&quot;, type: &quot;datetime&quot; }, { name: &quot;WaveLength&quot;, type: &quot;float&quot; } ] }] }); // create a new stream aggregator for &#x27;People&#x27; store, get the length of the record name (with the function object) var aggr &#x3D; new qm.StreamAggr(base, new function () { var numOfAdds &#x3D; 0; var numOfUpdates &#x3D; 0; var numOfDeletes &#x3D; 0; var time &#x3D; &quot;&quot;; this.name &#x3D; &#x27;nameLength&#x27;, this.onAdd &#x3D; function (rec) { numOfAdds +&#x3D; 1; }; this.onUpdate &#x3D; function (rec) { numOfUpdates +&#x3D; 1; }; this.onDelete &#x3D; function (rec) { numOfDeletes +&#x3D; 1; }; this.onTime &#x3D; function (ts) { time &#x3D; ts; }; this.saveJson &#x3D; function (limit) { return { adds: numOfAdds, updates: numOfUpdates, deletes: numOfDeletes, time: time }; }; }, &quot;People&quot;); // create a new time series window buffer stream aggregator for &#x27;Laser&#x27; store (with the JSON object) var wavelength &#x3D; { name: &quot;WaveLengthLaser&quot;, type: &quot;timeSeriesWinBuf&quot;, store: &quot;Laser&quot;, timestamp: &quot;Time&quot;, value: &quot;WaveLength&quot;, winsize: 10000 } var sa &#x3D; base.store(&quot;Laser&quot;).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>&nbsp;</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>&nbsp;</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>&nbsp;&rarr; <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>&nbsp;&rarr; <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 &#x3D; require(&#x27;qminer&#x27;); // create a simple base containing one store var base &#x3D; new qm.Base({ mode: &#x27;createClean&#x27;, schema: [{ name: &#x27;Grades&#x27;, fields: [ { name: &#x27;Grade&#x27;, type: &#x27;int&#x27; }, { name: &#x27;Procents&#x27;, type: &#x27;float&#x27; }, { name: &#x27;Time&#x27;, type: &#x27;datetime&#x27; } ] }] }); // create a new time series stream aggregator which takes the values from the &#x27;Procents&#x27; field // and the timestamp from the &#x27;Time&#x27; field. The size of the window is 1 year. var ts &#x3D; { name: &#x27;GradesAggr&#x27;, type: &#x27;timeSeriesWinBuf&#x27;, store: &#x27;Grades&#x27;, timestamp: &#x27;Time&#x27;, value: &#x27;Procents&#x27;, winsize: 31536000000 }; var timeSeries &#x3D; base.store(&#x27;Grades&#x27;).addStreamAggr(ts); // create a new moving average stream aggregator that takes the values from the // &#x27;GradesAggr&#x27; stream aggregator var ma &#x3D; { name: &#x27;AverageGrade&#x27;, type: &#x27;ma&#x27;, store: &#x27;Grades&#x27;, inAggr: &#x27;GradesAggr&#x27; } var averageGrade &#x3D; base.store(&#x27;Grades&#x27;).addStreamAggr(ma); // add some grades in the &#x27;Grades&#x27; store base.store(&quot;Grades&quot;).push({ Grade: 7, Procents: 65, Time: &#x27;2014-11-23T10:00:00.0&#x27; }); base.store(&quot;Grades&quot;).push({ Grade: 9, Procents: 88, Time: &#x27;2014-12-20T12:00:00.0&#x27; }); base.store(&quot;Grades&quot;).push({ Grade: 8, Procents: 70, Time: &#x27;2015-02-03T10:00:00.0&#x27; }); // get the average grade procents by using the getFloat method var average &#x3D; 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>&nbsp;&rarr; <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 &#x3D; require(&#x27;qminer&#x27;); // create a simple base containing one store var base &#x3D; new qm.Base({ mode: &#x27;createClean&#x27;, schema: [{ name: &#x27;MusicSale&#x27;, fields: [ { name: &#x27;NumberOfAlbums&#x27;, type: &#x27;float&#x27; }, { name: &#x27;Time&#x27;, type: &#x27;datetime&#x27; } ] }] }); // create a time series containing the &#x27;NumberOfAlbums&#x27; values and getting the timestamp from the &#x27;Time&#x27; field. // The window size should be 1 week. var ts &#x3D; { name: &#x27;Sales&#x27;, type: &#x27;timeSeriesWinBuf&#x27;, store: &#x27;MusicSale&#x27;, timestamp: &#x27;Time&#x27;, value: &#x27;NumberOfAlbums&#x27;, winsize: 604800000 }; var weekSales &#x3D; base.store(&#x27;MusicSale&#x27;).addStreamAggr(ts); // add some records in the store base.store(&#x27;MusicSale&#x27;).push({ NumberOfAlbums: 10, Time: &#x27;2015-03-15T00:00:00.0&#x27; }); base.store(&#x27;MusicSale&#x27;).push({ NumberOfAlbums: 15, Time: &#x27;2015-03-18T00:00:00.0&#x27; }); base.store(&#x27;MusicSale&#x27;).push({ NumberOfAlbums: 30, Time: &#x27;2015-03-19T00:00:00.0&#x27; }); base.store(&#x27;MusicSale&#x27;).push({ NumberOfAlbums: 45, Time: &#x27;2015-03-20T00:00:00.0&#x27; }); // get the second value of the value vector var albums &#x3D; 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>&nbsp;</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>&nbsp;&rarr; <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 &#x3D; require(&#x27;qminer&#x27;); // create a simple base containing one store var base &#x3D; new qm.Base({ mode: &#x27;createClean&#x27;, schema: [{ name: &#x27;IceCreams&#x27;, fields: [ { name: &#x27;Type&#x27;, type: &#x27;string&#x27; }, { name: &#x27;Price&#x27;, type: &#x27;float&#x27; }, { name: &#x27;TimeOfConsumption&#x27;, type: &#x27;datetime&#x27; } ] }] }); // create a time series stream aggregator, that takes values from the &#x27;Price&#x27; field and the timestamp // from the &#x27;TimeOfConsumation&#x27; field of &#x27;IceCream&#x27; store. The window size should be 1 day. var ts &#x3D; { name: &#x27;IcePrice&#x27;, type: &#x27;timeSeriesWinBuf&#x27;, store: &#x27;IceCreams&#x27;, timestamp: &#x27;TimeOfConsumption&#x27;, value: &#x27;Price&#x27;, winsize: 86400000 }; var icePrice &#x3D; base.store(&#x27;IceCreams&#x27;).addStreamAggr(ts); // add some ice creams in the store base.store(&#x27;IceCreams&#x27;).push({ Type: &#x27;Chocholate&#x27;, Price: 5, TimeOfConsumption: &#x27;2015-07-21T09:00:00.0&#x27; }); base.store(&#x27;IceCreams&#x27;).push({ Type: &#x27;Blue Sky&#x27;, Price: 3, TimeOfConsumption: &#x27;2015-07-21T14:13:00.0&#x27; }); base.store(&#x27;IceCreams&#x27;).push({ Type: &#x27;Stracciatella&#x27;, Price: 5, TimeOfConsumption: &#x27;2015-07-21T21:05:00.0&#x27; }); // get the number of ice creams consumed by using getFloatLength method var numberOfIceCreamsEaten &#x3D; 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>&nbsp;&rarr; <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 &#x3D; require(&#x27;qminer&#x27;); // create a simple base containing one store var base &#x3D; new qm.Base({ mode: &#x27;createClean&#x27;, schema: [{ name: &#x27;Hospital&#x27;, fields: [ { name: &#x27;NumberOfPatients&#x27;, type: &#x27;float&#x27; }, { name: &#x27;Date&#x27;, type: &#x27;datetime&#x27; } ] }] }); // create a new time series stream aggregator that takes the values from the &#x27;NumberOfPatients&#x27; field // and the timestamp from the &#x27;Date&#x27; field. The window size should be 1 week. var ts &#x3D; { name: &#x27;WeekPatients&#x27;, type: &#x27;timeSeriesWinBuf&#x27;, store: &#x27;Hospital&#x27;, timestamp: &#x27;Date&#x27;, value: &#x27;NumberOfPatients&#x27;, winsize: 604800000 }; var weekPatients &#x3D; base.store(&#x27;Hospital&#x27;).addStreamAggr(ts); // add some records in the store base.store(&#x27;Hospital&#x27;).push({ NumberOfPatients: 50, Date: &#x27;2015-05-20T00:00:00.0&#x27; }); base.store(&#x27;Hospital&#x27;).push({ NumberOfPatients: 56, Date: &#x27;2015-05-21T00:00:00.0&#x27; }); base.store(&#x27;Hospital&#x27;).push({ NumberOfPatients: 120, Date: &#x27;2015-05-22T00:00:00.0&#x27; }); base.store(&#x27;Hospital&#x27;).push({ NumberOfPatients: 40, Date: &#x27;2015-05-23T00:00:00.0&#x27; }); // get the values that are in the time series window buffer as a vector var values &#x3D; 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>&nbsp;&rarr; <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 &#x3D; require(&#x27;qminer&#x27;); // create a simple base containing one store var base &#x3D; new qm.Base({ mode: &#x27;createClean&#x27;, schema: [{ name: &#x27;Noise&#x27;, fields: [ { name: &#x27;Decibels&#x27;, type: &#x27;float&#x27; }, { name: &#x27;Time&#x27;, type: &#x27;datetime&#x27; } ] }] }); // create a time series stream aggregator that takes the values from the &#x27;Decibels&#x27; field // and timestamps from the &#x27;Time&#x27; fields. The window size should be 1 second. var ts &#x3D; { name: &#x27;Music&#x27;, type: &#x27;timeSeriesWinBuf&#x27;, store: &#x27;Noise&#x27;, timestamp: &#x27;Time&#x27;, value: &#x27;Decibels&#x27;, winsize: 1000 }; var music &#x3D; base.store(&#x27;Noise&#x27;).addStreamAggr(ts); // add some records in the store base.store(&#x27;Noise&#x27;).push({ Decibels: 54, Time: &#x27;2015-07-21T14:43:00.0&#x27; }); base.store(&#x27;Noise&#x27;).push({ Decibels: 55, Time: &#x27;2015-07-21T14:43:00.200&#x27; }); base.store(&#x27;Noise&#x27;).push({ Decibels: 53, Time: &#x27;2015-07-21T14:43:00.800&#x27; }); base.store(&#x27;Noise&#x27;).push({ Decibels: 54, Time: &#x27;2015-07-21T14:43:01.0&#x27; }); base.store(&#x27;Noise&#x27;).push({ Decibels: 53, Time: &#x27;2015-07-21T14:43:01.2&#x27; }); // get the in vector var vec &#x3D; 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>&nbsp;&rarr; <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>&nbsp;&rarr; <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 &#x3D; require(&#x27;qminer&#x27;); // create a simple base containing one store var base &#x3D; new qm.Base({ mode: &#x27;createClean&#x27;, schema: [{ name: &#x27;Noise&#x27;, fields: [ { name: &#x27;Decibels&#x27;, type: &#x27;float&#x27; }, { name: &#x27;Time&#x27;, type: &#x27;datetime&#x27; } ] }] }); // create a time series stream aggregator that takes the values from the &#x27;Decibels&#x27; field // and timestamps from the &#x27;Time&#x27; fields. The window size should be 1 second. var ts &#x3D; { name: &#x27;Music&#x27;, type: &#x27;timeSeriesWinBuf&#x27;, store: &#x27;Noise&#x27;, timestamp: &#x27;Time&#x27;, value: &#x27;Decibels&#x27;, winsize: 1000 }; var music &#x3D; base.store(&#x27;Noise&#x27;).addStreamAggr(ts); // add some records in the store base.store(&#x27;Noise&#x27;).push({ Decibels: 54, Time: &#x27;2015-07-21T14:43:00.0&#x27; }); base.store(&#x27;Noise&#x27;).push({ Decibels: 55, Time: &#x27;2015-07-21T14:43:00.200&#x27; }); base.store(&#x27;Noise&#x27;).push({ Decibels: 53, Time: &#x27;2015-07-21T14:43:00.800&#x27; }); base.store(&#x27;Noise&#x27;).push({ Decibels: 54, Time: &#x27;2015-07-21T14:43:01.0&#x27; }); base.store(&#x27;Noise&#x27;).push({ Decibels: 53, Time: &#x27;2015-07-21T14:43:01.2&#x27; }); // get the in timestamps var vec &#x3D; 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>&nbsp;&rarr; <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 &#x3D; require(&#x27;qminer&#x27;); // create a simple base containing one store var base &#x3D; new qm.Base({ mode: &#x27;createClean&#x27;, schema: [{ name: &#x27;Docs&#x27;, fields: [ { name: &#x27;Time&#x27;, type: &#x27;datetime&#x27; }, { name: &#x27;Text&#x27;, type: &#x27;string&#x27; } ] }] }); store &#x3D; base.store(&#x27;Docs&#x27;); // 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 &#x3D; { type: &#x27;timeSeriesWinBufFeatureSpace&#x27;, store: &#x27;Docs&#x27;, timestamp: &#x27;Time&#x27;, featureSpace: { type: &quot;categorical&quot;, source: &quot;Docs&quot;, field: &quot;Text&quot; }, winsize: 1000 }; var streamAggregate &#x3D; store.addStreamAggr(aggr); store.push({ Time: &#x27;2015-06-10T14:13:32.0&#x27;, Text: &#x27;a&#x27; }); store.push({ Time: &#x27;2015-06-10T14:13:33.0&#x27;, Text: &#x27;b&#x27; }); store.push({ Time: &#x27;2015-06-10T14:13:34.0&#x27;, Text: &#x27;c&#x27; }); // we have three dimensions, where &quot;a&quot; -&gt; [1,0,0], &quot;b&quot; -&gt; [0,1,0], &quot;c&quot; -&gt; [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 &#x3D; sparse matrices. streamAggregate.getInValueVector().print(); // one column, one nonzero element at index 2 // &#x3D; [ // 2 0 1.000000 // ] streamAggregate.getOutValueVector().print(); // one column, one nonzero element at index 0 // &#x3D; [ // 0 0 1.000000 // ] streamAggregate.getValueVector().print(); // two column vectors, each with one nonzero element // &#x3D; [ // 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>&nbsp;&rarr; <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 &#x3D; require(&#x27;qminer&#x27;); // create a simple base containing one store var base &#x3D; new qm.Base({ mode: &#x27;createClean&#x27;, schema: [{ name: &#x27;MusicSale&#x27;, fields: [ { name: &#x27;NumberOfAlbums&#x27;, type: &#x27;float&#x27; }, { name: &#x27;Time&#x27;, type: &#x27;datetime&#x27; } ] }] }); // create a time series containing the values from the &#x27;NumberOfAlbums&#x27; field and // the timestamp from the &#x27;Time&#x27; field. The window size should be 1 week. var ts &#x3D; { name: &#x27;Sales&#x27;, type: &#x27;timeSeriesWinBuf&#x27;, store: &#x27;MusicSale&#x27;, timestamp: &#x27;Time&#x27;, value: &#x27;NumberOfAlbums&#x27;, winsize: 604800000 }; var weekSales &#x3D; base.store(&#x27;MusicSale&#x27;).addStreamAggr(ts); // add some records in the store base.store(&#x27;MusicSale&#x27;).push({ NumberOfAlbums: 10, Time: &#x27;2015-03-15T00:00:00.0&#x27; }); base.store(&#x27;MusicSale&#x27;).push({ NumberOfAlbums: 15, Time: &#x27;2015-03-18T00:00:00.0&#x27; }); base.store(&#x27;MusicSale&#x27;).push({ NumberOfAlbums: 30, Time: &#x27;2015-03-19T00:00:00.0&#x27; }); base.store(&#x27;MusicSale&#x27;).push({ NumberOfAlbums: 45, Time: &#x27;2015-03-20T00:00:00.0&#x27; }); // get the number of records in the window buffer var num &#x3D; 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>&nbsp;&rarr; <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 &#x3D; require(&#x27;qminer&#x27;); // create a simple base containing one store var base &#x3D; new qm.Base({ mode: &#x27;createClean&#x27;, schema: [{ name: &#x27;F1&#x27;, fields: [ { name: &#x27;Driver&#x27;, type: &#x27;string&#x27; }, { name: &#x27;Speed&#x27;, type: &#x27;float&#x27; }, { name: &#x27;Time&#x27;, type: &#x27;datetime&#x27; } ] }] }); // create a time series stream aggregator that gets the values from the &#x27;Speed&#x27; field // and the timestamp from the &#x27;Time&#x27; field. The window size should be 5 minutes. var ts &#x3D; { name: &#x27;Sensor&#x27;, type: &#x27;timeSeriesWinBuf&#x27;, store: &#x27;F1&#x27;, timestamp: &#x27;Time&#x27;, value: &#x27;Speed&#x27;, winsize: 300000 }; var sensor &#x3D; base.store(&#x27;F1&#x27;).addStreamAggr(ts); // add some records to the store base.store(&#x27;F1&#x27;).push({ Driver: &#x27;Sebastian Vettel&#x27;, Speed: 203.4, Time: &#x27;2015-07-19T09:32:01.0&#x27; }); base.store(&#x27;F1&#x27;).push({ Driver: &#x27;Thomas &quot;Tommy&quot; Angelo&#x27;, Speed: 152.8, Time: &#x27;2015-07-19T09:35:23.0&#x27; }); base.store(&#x27;F1&#x27;).push({ Driver: &#x27;Mark Ham&#x27;, Speed: 189.5, Time: &#x27;2015-07-19T09:38:43.0&#x27; }); base.store(&#x27;F1&#x27;).push({ Driver: &#x27;Speedy Gonzales&#x27;, Speed: 171.4, Time: &#x27;2015-07-19T09:40:32.0&#x27; }); // 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 &#x3D; 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>&nbsp;&rarr; <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 &#x3D; require(&#x27;qminer&#x27;); // create a simple base containing one store var base &#x3D; new qm.Base({ mode: &#x27;createClean&#x27;, schema: [{ name: &#x27;Noise&#x27;, fields: [ { name: &#x27;Decibels&#x27;, type: &#x27;float&#x27; }, { name: &#x27;Time&#x27;, type: &#x27;datetime&#x27; } ] }] }); // create a time series stream aggregator that takes the values from the &#x27;Decibels&#x27; field // and timestamps from the &#x27;Time&#x27; fields. The window size should be 1 second. var ts &#x3D; { name: &#x27;Music&#x27;, type: &#x27;timeSeriesWinBuf&#x27;, store: &#x27;Noise&#x27;, timestamp: &#x27;Time&#x27;, value: &#x27;Decibels&#x27;, winsize: 1000 }; var music &#x3D; base.store(&#x27;Noise&#x27;).addStreamAggr(ts); // add some records in the store base.store(&#x27;Noise&#x27;).push({ Decibels: 54, Time: &#x27;2015-07-21T14:43:00.0&#x27; }); base.store(&#x27;Noise&#x27;).push({ Decibels: 55, Time: &#x27;2015-07-21T14:43:00.200&#x27; }); base.store(&#x27;Noise&#x27;).push({ Decibels: 54, Time: &#x27;2015-07-21T14:43:00.400&#x27; }); base.store(&#x27;Noise&#x27;).push({ Decibels: 53, Time: &#x27;2015-07-21T14:43:00.600&#x27; }); base.store(&#x27;Noise&#x27;).push({ Decibels: 53, Time: &#x27;2015-07-21T14:43:00.800&#x27; }); base.store(&#x27;Noise&#x27;).push({ Decibels: 54, Time: &#x27;2015-07-21T14:43:01.0&#x27; }); base.store(&#x27;Noise&#x27;).push({ Decibels: 53, Time: &#x27;2015-07-21T14:43:01.2&#x27; }); // get the timestamps that just left the window buffer by adding the last record var last &#x3D; 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>&nbsp;&rarr; <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>&nbsp;&rarr; <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>&nbsp;&rarr; <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 &#x3D; require(&#x27;qminer&#x27;); // create a simple base containing one store var base &#x3D; new qm.Base({ mode: &#x27;createClean&#x27;, schema: [{ name: &#x27;GameCollection&#x27;, fields: [ { name: &#x27;GameName&#x27;, type: &#x27;string&#x27; }, { name: &#x27;Price&#x27;, type: &#x27;float&#x27; }, { name: &#x27;ReleaseDate&#x27;, type: &#x27;datetime&#x27; } ] }] }); // create a new time series stream aggregator which takes the values from the &#x27;Price&#x27; field // and the timestamps from the &#x27;ReleaseDate&#x27; field. The window size should be 1 month. var ts &#x3D; { name: &#x27;GameSeries&#x27;, type: &#x27;timeSeriesWinBuf&#x27;, store: &#x27;GameCollection&#x27;, timestamp: &#x27;ReleaseDate&#x27;, value: &#x27;Price&#x27;, winsize: 2678400000 }; var timeSeries &#x3D; base.store(&#x27;GameCollection&#x27;).addStreamAggr(ts); // create a new sum stream aggregator var sum &#x3D; { name: &#x27;SumPrice&#x27;, type: &#x27;winBufSum&#x27;, store: &#x27;GameCollection&#x27;, inAggr: &#x27;GameSeries&#x27; }; var priceSum &#x3D; base.store(&#x27;GameCollection&#x27;).addStreamAggr(sum); // put some records in the store base.store(&#x27;GameCollection&#x27;).push({ GameName: &#x27;Tetris&#x27;, Price: 0, ReleaseDate: &#x27;1984-06-06T00:00:00.0&#x27; }); base.store(&#x27;GameCollection&#x27;).push({ GameName: &#x27;Super Mario Bros.&#x27;, Price: 100, ReleaseDate: &#x27;1985-09-13T00:00:00.0&#x27; }); base.store(&#x27;GameCollection&#x27;).push({ GameName: &#x27;The Legend of Zelda&#x27;, Price: 90, ReleaseDate: &#x27;1986-02-21T00:00:00.0 &#x27;}); // get the timestamp of the last bought game by using getTimestamp var date &#x3D; 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>&nbsp;&rarr; <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 &#x3D; require(&#x27;qminer&#x27;); // create a simple base containing one store var base &#x3D; new qm.Base({ mode: &#x27;createClean&#x27;, schema: [{ name: &#x27;Route66&#x27;, fields: [ { name: &#x27;NumberOfCars&#x27;, type: &#x27;float&#x27; }, { name: &#x27;Time&#x27;, type: &#x27;datetime&#x27; } ] }] }); // create a time series stream aggregator that takes the values from the &#x27;NumberOfCars&#x27; field // and the timestamps from the &#x27;Time&#x27; field. The window size should be 1 day. var ts &#x3D; { name: &#x27;Traffic&#x27;, type: &#x27;timeSeriesWinBuf&#x27;, store: &#x27;Route66&#x27;, timestamp: &#x27;Time&#x27;, value: &#x27;NumberOfCars&#x27;, winsize: 86400000 }; var traffic &#x3D; base.store(&#x27;Route66&#x27;).addStreamAggr(ts); // add some records in the store base.store(&#x27;Route66&#x27;).push({ NumberOfCars: 100, Time: &#x27;2015-06-15T06:00:00.0&#x27; }); base.store(&#x27;Route66&#x27;).push({ NumberOfCars: 88, Time: &#x27;2015-06-15T:10:00.0&#x27; }); base.store(&#x27;Route66&#x27;).push({ NumberOfCars: 60, Time: &#x27;2015-06-15T13:00:00.0&#x27; }); base.store(&#x27;Route66&#x27;).push({ NumberOfCars: 90, Time: &#x27;2015-06-15T18:00:00.0&#x27; }); base.store(&#x27;Route66&#x27;).push({ NumberOfCars: 110, Time: &#x27;2015-06-16T00:00:00.0&#x27; }); // get the third timestamp in the buffer var time &#x3D; 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>&nbsp;</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>&nbsp;&rarr; <span class="signature-returns"> nu