npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

flow-rolling-stats

v0.0.4

Published

Rolling time series operators for unevenly spaced data

Downloads

71

Readme

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

| Class | Operation | Comments | | -------------- | --------------------------------------------------------- | -------- | | RollingCount | Count of observations in window | | | RollingMin | Min value of observations in window | | | RollingMax | Max value of observations in window | | | RollingMean | Arithmetic mean of observations in window | | | RollingSum | Sum of observations in window | | | SmaLast | Simple moving average using last value | | | SmaNext | Simple moving average using next value | | | SmaLinear | Simple moving average using linear interpolation | | | EmaLast | Exponentially-weighted average using last value | | | EmaNext | Exponentially-weighted average using next value | | | EmaLinear | Exponentially-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.