New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

flow-rolling-stats

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flow-rolling-stats

Rolling time series operators for unevenly spaced data

latest
Source
npmnpm
Version
0.0.4
Version published
Maintainers
1
Created
Source

Rolling Window Stats

This Javascript library provides rolling time series operators for unevenly spaced data, such as simple moving averages (SMAs), exponential moving averages (EMAs), and various rolling functions. It is based on the utsAlgorithms C library.

The implementation details are described in "Algorithms for Unevenly Spaced Time Series: Moving Averages and Other Rolling Operators", Eckner (2017).

Usage

npm install flow-rolling-stats

NPM scripts

  • npm test: Run test suite
  • npm start: Run npm run build in watch mode
  • npm run test:watch: Run test suite in interactive watch mode
  • npm run test:prod: Run linting and generate coverage
  • npm run build: Generate bundles and typings, create docs
  • npm run lint: Lints code
  • npm run commit: Commit using conventional commit style (husky will tell you to use it if you haven't)

API

Operators are implemented as Javascript classes with a standard interface and designed to be used in real-time processing pipeline where observations are received periodically at uneven time intervals.

Typical usage is shown below (where RollingMean can be replaced with any of the supported operator classes):

const windowedAvg1 = new RollingMean({
  windowSize: { duration: 15, unit: 'minutes' }
});

const windowedAvg2 = new RollingMean({
  windowSize: { duration: 15, unit: 'minutes' }
});

// Process an event as it arrives
on('event', event => {

  // Construct metric
  const metric = {
    timestamp: event.timestamp;
    avgValue1: windowedAvg1.update(event.value1, event.timestamp);
    avgValue2: windowedAvg2.update(event.value2, event.timestamp);
  };

  // Send metric to next stage of pipeline
  emit(metric);
});

Operators

ClassOperationComments
RollingCountCount of observations in window
RollingMinMin value of observations in window
RollingMaxMax value of observations in window
RollingMeanArithmetic mean of observations in window
RollingSumSum of observations in window
SmaLastSimple moving average using last value
SmaNextSimple moving average using next value
SmaLinearSimple moving average using linear interpolation
EmaLastExponentially-weighted average using last value
EmaNextExponentially-weighted average using next value
EmaLinearExponentially-weighted average using linear interpolation

Window Size

Window size is specified when constructing an operator class. Supported time units are:

  • ms
  • milliseconds
  • second(s) -minute(s)
  • hour(s)
  • days(s)

Recording Observations

Call the update method of an operation to record a new observation. Pass the observation value and timestamp (in epoch milliseconds) as parameters. The update method returns the calculated statistic after the window has been updated.

Note that value property returns the calculated statistic and can be called at any time without performing a window update.

Numerical Stability

Many of the operators maintain a sum that is updated over the lifetime of the operator. To maintain numerical stability and negate the effects of limited floating point precision the method of Kahan (1965)[1] is used to perform compensated addition.

[1] Kahan, W. (1965). Further remarks on reducing truncation errors Communications of the ACM 8 (1), 40.

FAQs

Package last updated on 23 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts