var Counter = function (a) { this.peak = 0, this.peakTime = 0, this.timeSpan = 6e4 * a, this.counterItem = [], this.rateArray = []; for (var b = 0; 30 > b; b++) this.rateArray[b] = 0; this.rateArrayPtr = 0, this.rateArrayTmr = this.dateMillis() + 6e4; var c = this; this.slopeBins = 60, this.slopeArray = [], this.slopePtr = 0; for (var b = 0; b < this.slopeBins; b++) this.slopeArray[b] = 0; setInterval(function () { var a = isNaN(c.counterItem.length) ? 0 : c.counterItem.length; c.slopeArray[c.slopePtr++] = a, c.slopePtr > c.slopeBins - 1 && (c.slopePtr = 0) }, 5e3), setInterval(function () { if (!(c.counterItem.length <= 0)) { var a = c.dateMillis() - c.timeSpan; c.counterItem.length; for (var d = 0; d < c.counterItem.length && c.counterItem[d] < a; d++) c.counterItem.splice(d, 1); c.rateArrayTmr < c.dateMillis() && (c.rateArrayTmr = c.dateMillis() + 6e4, ++c.rateArrayPtr > 29 && (c.rateArrayPtr = 0, c.rateArray[c.rateArrayPtr] = 0)) } }, 500) }; Counter.prototype.increment = function (a) { "undefined" == typeof a && (a = null), this.counterItem.push(null == a ? this.dateMillis() : a), null == a && ++this.rateArray[this.rateArrayPtr] }, Counter.prototype.reset = function () { this.counterItem = [], this.peak = 0 }, Counter.prototype.currentCount = function () { var a = this.counterItem.length; return this.peak < a && (this.peak = a), a }, Counter.prototype.peakCount = function () { return this.peak }, Counter.prototype.computeTrend2 = function () { if (null == this.slopeArray || 0 == this.slopeArray.length) return e.slope = 0, e.intercept = 0, e.r2 = 0, e; var a = this.slopePtr - this.slopeBins; 0 > a && (a += this.slopeBins); for (var b = [], c = [], d = 0; d < this.slopeBins - 1; d++) c[d] = d, b[d] = this.slopeArray[a++], a > this.slopeBins - 1 && (a = 0); var e = this.linearRegression(c, b); return e }, Counter.prototype.linearRegression = function (a, b) { for (var c = {}, d = a.length, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0; j < a.length; j++) e += b[j], f += a[j], g += b[j] * a[j], h += b[j] * b[j], i += a[j] * a[j]; return c.slope = (d * g - e * f) / (d * h - e * e), c.intercept = (f - c.slope * e) / d, c.r2 = Math.pow((d * g - e * f) / Math.sqrt((d * h - e * e) * (d * i - f * f)), 2), c }, Counter.prototype.computeTrend = function (a) { if (null == this.rateArray || 0 == this.rateArray.length) return 0; var b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = this.rateArrayPtr - a; 0 > h && (h += 29); for (var i = 0; 30 > i; i++) { var j = i, k = this.rateArray[h++]; h > 29 && (h = 0), f += j * k, b += j, c += k, d += j * j } d = this.round2Dec(d), e = d - b * b / a, g = f - b * c / a; var l = 0 != e ? 1 * this.round2Dec(g / e) : 0; return l == isNaN(l) ? 0 : l.toFixed(2) }, Counter.prototype.round2Dec = function (a) { return parseInt(100 * a) / 100 }, Counter.prototype.dateMillis = function () { return (new Date).getTime() };