Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More

swstats

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swstats - npm Package Compare versions

Comparing version 0.6.1 to 0.6.2

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ module.exports = {

@@ -366,2 +366,7 @@ "use strict";

}, {
key: "toJSON",
value: function toJSON() {
return this.stats;
}
}, {
key: "length",

@@ -468,2 +473,7 @@ get: function get() {

}, {
key: "toJSON",
value: function toJSON() {
return this.stats;
}
}, {
key: "length",

@@ -470,0 +480,0 @@ get: function get() {

@@ -1,3 +0,3 @@

/*! swstats 2017-06-08 */
/*! swstats 2018-01-09 */
"use strict";function _classCallCheck(t,s){if(!(t instanceof s))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function t(t,s){for(var n=0;n<s.length;n++){var r=s[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(s,n,r){return n&&t(s.prototype,n),r&&t(s,r),s}}(),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};!function t(s,n,r){function e(a,o){if(!n[a]){if(!s[a]){var u="function"==typeof require&&require;if(!o&&u)return u(a,!0);if(i)return i(a,!0);var h=new Error("Cannot find module '"+a+"'");throw h.code="MODULE_NOT_FOUND",h}var f=n[a]={exports:{}};s[a][0].call(f.exports,function(t){var n=s[a][1][t];return e(n||t)},f,f.exports,t,s,n,r)}return n[a].exports}for(var i="function"==typeof require&&require,a=0;a<r.length;a++)e(r[a]);return e}({1:[function(t,s,n){!function(s){var n=t("./main.js");s.SWindow=n}(window)},{"./main.js":3}],2:[function(t,s,n){s.exports={sum:function(t,s,n,r,e,i){t=void 0===t?{}:t;for(var a=s.length,o=n.length,u=0;u<a;u++)for(var h in s[u].v)t[h]=t[h]||0,t[h]+=s[u].v[h];for(var f=0;f<o;f++)for(var c in n[f].v)t[c]=t[c]||0,t[c]-=n[f].v[c];return t},freq:function(t,s,n,r,e,i){var a=e.sum,o=0,u={};for(var h in a)o+=a[h];for(var f in a)u[f]=a[f]/o;return u},mode:function(t,s,n,r,e,i){var a=e.sum,o=[];for(var u in a)o.push({k:u,t:a[u]});return o.sort(function(t,s){return t.t-s.t}),(o.pop()||{}).k}}},{}],3:[function(t,s,n){function r(t){if("object"!=(void 0===t?"undefined":_typeof(t)))return t;var s={};for(var n in t)s[n]=r(t[n]);return s}function e(t,s,n,r,e){p[t][s]={fn:r,deps:n},e&&c[t].push(s)}function i(t,s,n){var r=p[n][t].deps;return!!r.length&&(r.indexOf(s)>=0||r.reduce(function(t,r){return t||i(r,s,n)},!1))}function a(t,s){var n={},r=!1;t.forEach(function(t){return n[t]=!0});do{r=!1,t.forEach(function(e){p[s][e].deps.forEach(function(s){n[s]||(n[s]=!0,t.push(s),r=!0)})})}while(r);if(t.length>1){var e=null,a=!1;do{a=!1;for(var o=0;o<t.length;o++)for(var u=o;u<t.length;u++)i(t[o],t[u],s)&&(e=t[o],t[o]=t[u],t[u]=e,a=!0)}while(a)}}var o=t("./nops.js"),u=t("./cops.js"),h=[],f={numeric:"numeric",category:"category"},c={numeric:["count","sum","max","min","avg","stdev"],category:["sum","freq","mode"]},v={type:f.numeric,ops:c.numeric,step:1e3},p={numeric:{count:{fn:o.count,deps:[]},sum:{fn:o.sum,deps:[]},max:{fn:o.max,deps:[]},min:{fn:o.min,deps:[]},avg:{fn:o.avg,deps:[]},stdev:{fn:o.stdev,deps:["avg"]}},category:{sum:{fn:u.sum,deps:[]},freq:{fn:u.freq,deps:["sum"]},mode:{fn:u.mode,deps:["sum"]}}};setInterval(function(){var t=Date.now();h.filter(function(t){return!t._pause}).forEach(function(s){for(var n=s._arr,e=s._time,i=s._type,a=[],o=r(s.stats);n.length&&t-n[0].t>e;)a.push(n.shift());s._ops.forEach(function(t){s.stats[t]=p[i][t].fn(s.stats[t],[],a,s._arr,s.stats,o)})})},1e3);var l=function(){function t(s,n){_classCallCheck(this,t),n=n||v,this._options=n,this._arr=[],this._time=s||1e4,this._type=n.type||v.type,this._ops=n.ops||c[this._type],this._step=n.step||v.step,this._pause=!1,this._active=!0,this._oldstats={},this.stats=r(n.stats||{}),a(this._ops,this._type),h.push(this)}return _createClass(t,[{key:"clean",value:function(){this._arr=[],this._oldstats={},this.stats=r(this._options.stats||{})}},{key:"push",value:function(t){if(this._active&&!this._pause)return t=t instanceof Array?t:[t],this._type==f.numeric?this._pushNum(t):this._pushCat(t)}},{key:"pause",value:function(){this._pause=!0}},{key:"resume",value:function(t){var s=this._arr;if(t&&s.length){var n=Date.now()-s[s.length].t;s.length.forEach(function(t){return t.t+=n})}this._pause=!1}},{key:"destroy",value:function(){var t=h.indexOf(this);h.splice(t,1),this._active=!1}},{key:"_pushNum",value:function(t){var s=this,n=Date.now(),e=this._arr,i=this._type,a=r(this.stats);t=t.map(function(t){return{t:n,v:t,l:1,max:t,min:t}}),e.length||e.push({t:n,v:0,l:0,max:-1/0,min:1/0});var o=r(e[e.length-1]);if(n-o.t<this._step){t.forEach(function(t){o.v+=t.v,o.l+=1,o.max=Math.max(o.max,t.v),o.min=Math.min(o.min,t.v)});var u=[e.pop()],h=[o];e.push(o),this._ops.forEach(function(t){s.stats[t]=p[i][t].fn(s.stats[t],h,u,e,s.stats,a)})}else t.forEach(function(t){e.push(t)}),this._ops.forEach(function(n){s.stats[n]=p[i][n].fn(s.stats[n],t,[],e,s.stats,a)});return this}},{key:"_pushCat",value:function(t){var s=this,n=Date.now(),e=this._arr,i=this._type,a=r(this.stats),o={};t.forEach(function(t){o[t]=o[t]||0,o[t]++}),e.length||e.push({t:n,v:{}});var u=r(e[e.length-1]);if(n-u.t<this._step){for(var h in o)u.v[h]=u.v[h]||0,u.v[h]+=o[h];var f=[e.pop()],c=[u];e.push(u),this._ops.forEach(function(t){s.stats[t]=p[i][t].fn(s.stats[t],c,f,e,s.stats,a)})}else{var v={t:n,v:o};e.push(v),this._ops.forEach(function(t){s.stats[t]=p[i][t].fn(s.stats[t],[v],[],e,s.stats,a)})}return this}},{key:"length",get:function(){return this._arr.length}}]),t}(),_=function(){function t(s,n){_classCallCheck(this,t),n=n||v,this._options=n,this._arr=[],this._size=s||1e3,this._type=n.type||v.type,this._ops=n.ops||c[this._type],this.stats=r(n.stats||{}),a(this._ops,this._type)}return _createClass(t,[{key:"clean",value:function(){this._arr=[],this._oldstats={},this.stats=r(this._options.stats||{})}},{key:"push",value:function(t){return t=t instanceof Array?t:[t],this._type==f.numeric?this._pushNum(t):this._pushCat(t)}},{key:"_pushNum",value:function(t){var s=this,n=this._arr,e=[],i=this._type,a=r(this.stats);for((t=t.map(function(t){return{v:t,l:1,max:t,min:t}})).forEach(function(t){return s._arr.push(t)});this._arr.length>this._size;)e.push(this._arr.shift());return this._ops.forEach(function(r){s.stats[r]=p[i][r].fn(s.stats[r],t,e,n,s.stats,a)}),this}},{key:"_pushCat",value:function(t){var s=this,n=this._arr,e=[],i=this._type,a=r(this.stats),o={v:{}};for(t.forEach(function(t){o.v[t]=o.v[t]||0,o.v[t]++}),this._arr.push(o);this._arr.length>this._size;)e.push(this._arr.shift());return this._ops.forEach(function(t){s.stats[t]=p[i][t].fn(s.stats[t],[o],e,n,s.stats,a)}),this}},{key:"length",get:function(){return this._arr.length}}]),t}();s.exports={TimeStats:l,SizeStats:_,register:e}},{"./cops.js":2,"./nops.js":4}],4:[function(t,s,n){var r={count:function(t,s,n,r,e,i){for(var a=0,o=r.length,u=0;u<o;u++)a+=r[u].l||1;return a},sum:function(t,s,n,r,e,i){t=void 0===t?0:t;for(var a=s.length,o=n.length,u=0;u<a;u++)t+=s[u].v;for(var h=0;h<o;h++)t-=n[h].v;return t},max:function(t,s,n,r,e,i){for(var a=-1/0,o=r.length,u=0;u<o;u++)a=Math.max(a,r[u].max);return a},min:function(t,s,n,r,e,i){for(var a=1/0,o=r.length,u=0;u<o;u++)a=Math.min(a,r[u].min);return a},avg:function(t,s,n,e,i,a){var o=r.count(0,0,0,s),u=r.count(0,0,0,n),h=r.count(0,0,0,e),f=h-o+u;t=void 0===t?0:t,t*=f;for(var c=0;c<s.length;c++)t+=s[c].v;for(var v=0;v<n.length;v++)t-=n[v].v;return t/=h,isNaN(t)?0:t},stdev:function(t,s,n,e,i,a){a.stdev=a.stdev||{avg:1,sqsum:0,sum:0,stdev:0};for(var o=r.count(0,0,0,s),u=r.count(0,0,0,n),h=(r.count(0,0,0,e),e.length),f=(a.avg,a.stdev.avg,a.stdev.sqsum),c=a.stdev.sum,v=i.avg||0,p=f,l=c,_=0;_<n.length;_++){var m=n[_].v/(n[_].l||1);p-=m*m,l-=m}for(var y=0;y<s.length;y++){var g=s[y].v/(s[y].l||1);p+=g*g,l+=g}var d=Math.sqrt((p-2*v*l+h*v*v)/h);return{avg:v,sqsum:p,sum:l,stdev:d}}};s.exports=r},{}]},{},[1]);
"use strict";function _classCallCheck(t,s){if(!(t instanceof s))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function t(t,s){for(var n=0;n<s.length;n++){var r=s[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(s,n,r){return n&&t(s.prototype,n),r&&t(s,r),s}}(),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};!function t(s,n,r){function e(a,o){if(!n[a]){if(!s[a]){var u="function"==typeof require&&require;if(!o&&u)return u(a,!0);if(i)return i(a,!0);var h=new Error("Cannot find module '"+a+"'");throw h.code="MODULE_NOT_FOUND",h}var f=n[a]={exports:{}};s[a][0].call(f.exports,function(t){var n=s[a][1][t];return e(n||t)},f,f.exports,t,s,n,r)}return n[a].exports}for(var i="function"==typeof require&&require,a=0;a<r.length;a++)e(r[a]);return e}({1:[function(t,s,n){!function(s){var n=t("./main.js");s.SWindow=n}(window)},{"./main.js":3}],2:[function(t,s,n){s.exports={sum:function(t,s,n,r,e,i){t=void 0===t?{}:t;for(var a=s.length,o=n.length,u=0;u<a;u++)for(var h in s[u].v)t[h]=t[h]||0,t[h]+=s[u].v[h];for(var f=0;f<o;f++)for(var c in n[f].v)t[c]=t[c]||0,t[c]-=n[f].v[c];return t},freq:function(t,s,n,r,e,i){var a=e.sum,o=0,u={};for(var h in a)o+=a[h];for(var f in a)u[f]=a[f]/o;return u},mode:function(t,s,n,r,e,i){var a=e.sum,o=[];for(var u in a)o.push({k:u,t:a[u]});return o.sort(function(t,s){return t.t-s.t}),(o.pop()||{}).k}}},{}],3:[function(t,s,n){function r(t){if("object"!=(void 0===t?"undefined":_typeof(t)))return t;var s={};for(var n in t)s[n]=r(t[n]);return s}function e(t,s,n,r,e){p[t][s]={fn:r,deps:n},e&&c[t].push(s)}function i(t,s,n){var r=p[n][t].deps;return!!r.length&&(r.indexOf(s)>=0||r.reduce(function(t,r){return t||i(r,s,n)},!1))}function a(t,s){var n={},r=!1;t.forEach(function(t){return n[t]=!0});do{r=!1,t.forEach(function(e){p[s][e].deps.forEach(function(s){n[s]||(n[s]=!0,t.push(s),r=!0)})})}while(r);if(t.length>1){var e=null,a=!1;do{a=!1;for(var o=0;o<t.length;o++)for(var u=o;u<t.length;u++)i(t[o],t[u],s)&&(e=t[o],t[o]=t[u],t[u]=e,a=!0)}while(a)}}var o=t("./nops.js"),u=t("./cops.js"),h=[],f={numeric:"numeric",category:"category"},c={numeric:["count","sum","max","min","avg","stdev"],category:["sum","freq","mode"]},v={type:f.numeric,ops:c.numeric,step:1e3},p={numeric:{count:{fn:o.count,deps:[]},sum:{fn:o.sum,deps:[]},max:{fn:o.max,deps:[]},min:{fn:o.min,deps:[]},avg:{fn:o.avg,deps:[]},stdev:{fn:o.stdev,deps:["avg"]}},category:{sum:{fn:u.sum,deps:[]},freq:{fn:u.freq,deps:["sum"]},mode:{fn:u.mode,deps:["sum"]}}};setInterval(function(){var t=Date.now();h.filter(function(t){return!t._pause}).forEach(function(s){for(var n=s._arr,e=s._time,i=s._type,a=[],o=r(s.stats);n.length&&t-n[0].t>e;)a.push(n.shift());s._ops.forEach(function(t){s.stats[t]=p[i][t].fn(s.stats[t],[],a,s._arr,s.stats,o)})})},1e3);var l=function(){function t(s,n){_classCallCheck(this,t),n=n||v,this._options=n,this._arr=[],this._time=s||1e4,this._type=n.type||v.type,this._ops=n.ops||c[this._type],this._step=n.step||v.step,this._pause=!1,this._active=!0,this._oldstats={},this.stats=r(n.stats||{}),a(this._ops,this._type),h.push(this)}return _createClass(t,[{key:"clean",value:function(){this._arr=[],this._oldstats={},this.stats=r(this._options.stats||{})}},{key:"push",value:function(t){if(this._active&&!this._pause)return t=t instanceof Array?t:[t],this._type==f.numeric?this._pushNum(t):this._pushCat(t)}},{key:"pause",value:function(){this._pause=!0}},{key:"resume",value:function(t){var s=this._arr;if(t&&s.length){var n=Date.now()-s[s.length].t;s.length.forEach(function(t){return t.t+=n})}this._pause=!1}},{key:"destroy",value:function(){var t=h.indexOf(this);h.splice(t,1),this._active=!1}},{key:"_pushNum",value:function(t){var s=this,n=Date.now(),e=this._arr,i=this._type,a=r(this.stats);t=t.map(function(t){return{t:n,v:t,l:1,max:t,min:t}}),e.length||e.push({t:n,v:0,l:0,max:-1/0,min:1/0});var o=r(e[e.length-1]);if(n-o.t<this._step){t.forEach(function(t){o.v+=t.v,o.l+=1,o.max=Math.max(o.max,t.v),o.min=Math.min(o.min,t.v)});var u=[e.pop()],h=[o];e.push(o),this._ops.forEach(function(t){s.stats[t]=p[i][t].fn(s.stats[t],h,u,e,s.stats,a)})}else t.forEach(function(t){e.push(t)}),this._ops.forEach(function(n){s.stats[n]=p[i][n].fn(s.stats[n],t,[],e,s.stats,a)});return this}},{key:"_pushCat",value:function(t){var s=this,n=Date.now(),e=this._arr,i=this._type,a=r(this.stats),o={};t.forEach(function(t){o[t]=o[t]||0,o[t]++}),e.length||e.push({t:n,v:{}});var u=r(e[e.length-1]);if(n-u.t<this._step){for(var h in o)u.v[h]=u.v[h]||0,u.v[h]+=o[h];var f=[e.pop()],c=[u];e.push(u),this._ops.forEach(function(t){s.stats[t]=p[i][t].fn(s.stats[t],c,f,e,s.stats,a)})}else{var v={t:n,v:o};e.push(v),this._ops.forEach(function(t){s.stats[t]=p[i][t].fn(s.stats[t],[v],[],e,s.stats,a)})}return this}},{key:"toJSON",value:function(){return this.stats}},{key:"length",get:function(){return this._arr.length}}]),t}(),_=function(){function t(s,n){_classCallCheck(this,t),n=n||v,this._options=n,this._arr=[],this._size=s||1e3,this._type=n.type||v.type,this._ops=n.ops||c[this._type],this.stats=r(n.stats||{}),a(this._ops,this._type)}return _createClass(t,[{key:"clean",value:function(){this._arr=[],this._oldstats={},this.stats=r(this._options.stats||{})}},{key:"push",value:function(t){return t=t instanceof Array?t:[t],this._type==f.numeric?this._pushNum(t):this._pushCat(t)}},{key:"_pushNum",value:function(t){var s=this,n=this._arr,e=[],i=this._type,a=r(this.stats);for((t=t.map(function(t){return{v:t,l:1,max:t,min:t}})).forEach(function(t){return s._arr.push(t)});this._arr.length>this._size;)e.push(this._arr.shift());return this._ops.forEach(function(r){s.stats[r]=p[i][r].fn(s.stats[r],t,e,n,s.stats,a)}),this}},{key:"_pushCat",value:function(t){var s=this,n=this._arr,e=[],i=this._type,a=r(this.stats),o={v:{}};for(t.forEach(function(t){o.v[t]=o.v[t]||0,o.v[t]++}),this._arr.push(o);this._arr.length>this._size;)e.push(this._arr.shift());return this._ops.forEach(function(t){s.stats[t]=p[i][t].fn(s.stats[t],[o],e,n,s.stats,a)}),this}},{key:"toJSON",value:function(){return this.stats}},{key:"length",get:function(){return this._arr.length}}]),t}();s.exports={TimeStats:l,SizeStats:_,register:e}},{"./cops.js":2,"./nops.js":4}],4:[function(t,s,n){var r={count:function(t,s,n,r,e,i){for(var a=0,o=r.length,u=0;u<o;u++)a+=r[u].l||1;return a},sum:function(t,s,n,r,e,i){t=void 0===t?0:t;for(var a=s.length,o=n.length,u=0;u<a;u++)t+=s[u].v;for(var h=0;h<o;h++)t-=n[h].v;return t},max:function(t,s,n,r,e,i){for(var a=-1/0,o=r.length,u=0;u<o;u++)a=Math.max(a,r[u].max);return a},min:function(t,s,n,r,e,i){for(var a=1/0,o=r.length,u=0;u<o;u++)a=Math.min(a,r[u].min);return a},avg:function(t,s,n,e,i,a){var o=r.count(0,0,0,s),u=r.count(0,0,0,n),h=r.count(0,0,0,e),f=h-o+u;t=void 0===t?0:t,t*=f;for(var c=0;c<s.length;c++)t+=s[c].v;for(var v=0;v<n.length;v++)t-=n[v].v;return t/=h,isNaN(t)?0:t},stdev:function(t,s,n,e,i,a){a.stdev=a.stdev||{avg:1,sqsum:0,sum:0,stdev:0};for(var o=r.count(0,0,0,s),u=r.count(0,0,0,n),h=(r.count(0,0,0,e),e.length),f=(a.avg,a.stdev.avg,a.stdev.sqsum),c=a.stdev.sum,v=i.avg||0,p=f,l=c,_=0;_<n.length;_++){var m=n[_].v/(n[_].l||1);p-=m*m,l-=m}for(var y=0;y<s.length;y++){var g=s[y].v/(s[y].l||1);p+=g*g,l+=g}var d=Math.sqrt((p-2*v*l+h*v*v)/h);return{avg:v,sqsum:p,sum:l,stdev:d}}};s.exports=r},{}]},{},[1]);

@@ -0,0 +0,0 @@ const SWindow = require("../main.js");

@@ -0,0 +0,0 @@ const

@@ -0,0 +0,0 @@ const TimeStats = require("../main.js").TimeStats;

@@ -0,0 +0,0 @@ module.exports = function(grunt) {

@@ -276,2 +276,6 @@ const NOps = require("./nops.js");

}
toJSON() {
return this.stats;
}
}

@@ -357,2 +361,6 @@

}
toJSON() {
return this.stats;
}
}

@@ -359,0 +367,0 @@

@@ -0,0 +0,0 @@ const OPS = {

{
"name": "swstats",
"version": "0.6.1",
"version": "0.6.2",
"description": "Sliding window statistics",

@@ -5,0 +5,0 @@ "author": "David Gómez Matarrodona <solzimer@gmail.com>",

@@ -28,3 +28,3 @@ # swstats

// Create a time window of 10 secons. Each value pushed to
// Create a time window of 10 seconds. Each value pushed to
// the window will be stored in a unique slot (step:1)

@@ -92,3 +92,3 @@ // Window will slide on each second

max: 0.9865126881294235,
min: 0.0023880687887007923,
min: 0.0023880687887007923,
stdev:

@@ -141,3 +141,3 @@ { avg: 0.4980235682615189,

### destroy()
Kill the window, so no new values will be added, and no slide will occur. Yoy can still access to its stats.
Kill the window, so no new values will be added, and no slide will occur. You can still access to its stats.

@@ -144,0 +144,0 @@ ### timeWindow.length

@@ -0,0 +0,0 @@ const

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet