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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ewlr

v0.1.2

Published

Exponentially Weighted Loss Rate.

Readme

ewlr

Stability: 1 - Experimental

NPM version

Exponentially Weighted Loss Rate.

Contents

Installation

npm install ewlr

Overview

EWLR is an Exponentially Weighted Loss Rate calculation module to estimate event loss rate.

Usage

To run the below example run:

npm run readme
"use strict";

var EWLR = require('../index.js');

// keep track of last tick and tick interval
var lastTick = EWLR.getTime();
var tickInterval = 1000; // 1 second (in milliseconds)

var ewlr = new EWLR();

// update with success
ewlr.update();

// update with failure
ewlr.update(1, 1);

// update with 20% loss rate
ewlr.update(1000, 200);

// or a less precise 20% loss rate
for (var i = 0; i < 1000; i++) {
    ewlr.update(1, (Math.random() < 0.2 ? 1 : 0));
}

// tick the required number of times in order to get an accurate loss rate
var shouldTick = EWLR.tickIfNecessary(lastTick, tickInterval);
if (shouldTick) {
    lastTick = shouldTick.newLastTick;
    for (var i = 0; i < shouldTick.requiredTicks; i++) {
        ewlr.tick();
    }
}

console.dir(ewlr.rate()); // may be 0 if we haven't tick()'ed yet

setTimeout(function () {
    shouldTick = EWLR.tickIfNecessary(lastTick, tickInterval);
    if (shouldTick) {
        lastTick = shouldTick.newLastTick;
        for (var i = 0; i < shouldTick.requiredTicks; i++) {
            ewlr.tick();
        }
    }

    console.dir(ewlr.rate());
}, 3000); // will get 3 ticks if we wait 3 seconds

Tests

npm test

Documentation

EWLR

Public API

EWLR.getTime()

  • Return: Number Time in milliseconds (for example: 109.372263)

EWLR.tickIfNecessary(lastTick, tickInterval)

  • lastTick: Number Time of last tick in milliseconds.
  • tickInterval: Number Tick interval in milliseconds.
  • Return: undefined If no tick necessary.
  • Return: Object If tick is necessary
    • lastTick: Number Time of new last tick to set in milliseconds
    • requiredTicks: Number The number of ticks to execute to catch up.

Determines if and how many ticks are necessary.

new EWLR(config)

  • config: Object
    • timePeriod: Number (Default: 1000) Time period in milliseconds.
    • tickInterval: Number (Default: 1000) Tick inteval in milliseconds.

Creates a new EWLR instance.

ewlr.rate()

  • Return: Object
    • rate: Number Rate of events. Rate is returned so that it can be determined if lossRate is meaningful. For example, if rate is 2.504763981949714e-32, the loss rate (even if 20%), may not be meaningful since the tiny rate may mean that no updates have happened for a long time.
    • lossRate: Number Normalized ([0..1]) loss rate of events
    • lossRate: Number Normalized ([0..1]) loss rate of events

Returns the event rate and the normalized loss rate. The rate is only meant as a liveness/recency measure to see if lossRate is meaningful.

ewlr.tick()

Update the rate and loss rate estimates in accordance with time period and tick interval.

ewlr.update([n], [lost])

  • n: Integer (Default: 1) Number of events to update with.
  • lost: Integer (Default: 0) Number of lost events to update with (0 < lost <= n)