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

estimate-progress

v1.0.0

Published

Takes progress bar data that is too jumpy and makes the data smoother

Downloads

7

Readme

estimate-progress

Takes progress bar data that is too jumpy and makes the data "smoother".

Installation

npm install estimate-progress

Note: uses syntactical ES5 but one API from ES6 (Array.fill).

Problem

Suppose you have progress bar data that looks like this:

{
  start: number, // what number the progress started from
  current: number, // the current status of the progression
  target: number, // the goal number, once this is reached, supposedly we're done
}

And assume that start <= current <= target. If either the start or target of the progress data changes often, then the rendered progress bar will be "jumpy", going back to previous numbers.

Solution

This library is a heuristic to estimate the "real final" target and keep the start fixed to the minimum observed. In particular, the calculation of the target estimation is simple unacademic math, using two techniques:

  • Inertia: smoothens the rate of change of the moving target
  • Margin: this is like a moving average but not actually an average, it just calculates the rate of change of the target N steps back, and uses that difference to extrapolate N steps into the future

The result is that the progress is much less jumpy, and as a side effect, the estimated progress data always completes some seconds after the actual completion (due to inertia).

example progress bars

Usage

const estimateProgress = require('estimate-progress');

const getEstimatedProgress = estimateProgress(() => actualProgress);

console.log(getEstimatedProgress()); // {start: 2, current: 5, target: 9}

API

estimateProgress(getter1, /* both optional: */ margin, inertia): getter2

  • getter1: the first argument is a getter function that returns the actual progress data. It's necessary that this is a getter of data and not the actual data because we do calculations over time, and we assume the progress data evolves over time. This is the only required argument. Progress data should always be an object {start, current, target}
  • margin: how many steps behind (and ahead) to use for calculations. By default, this is 10. Use big numbers (~50) if you think the progress will take minutes, use small numbers (~8) if you think the progress will take seconds. The bigger the margin number, the more memory is used.
  • inertia: how conservatively should we move towards the moving target. This is a number between 0 and 1, by default 0.75. Use values close to 0 if you want the estimated progress to complete almost at the same time as the input progress. Use values close to 1 if you want the estimated progress to move smoothly (yet complete much after the input progress completes).

Returns a getter function that behaves like the input getter function.

License

MIT