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

optimized-averages

v1.0.0

Published

A small utility to optimize data averaging by ignoring irrelevant data that can go kick rocks.

Downloads

3

Readme

Optimized Averages

A small utility to optimize data averaging by ignoring irrelevant data that can go kick rocks. Mostly built for handling the data being received by beacons during user location calculation instances.

The distance provided by the beacons comes constantly and can be consistently inconsistent, which is what led to the creation of this small utility. Say the user is 2m away from the beacon, but you receive the following distances from the beacon:

[14.78, 2.25, 2.45, 1.87, 1.89, 2.11, 9.33, 1.97, 2.06, 1.93, 2.22, 2.22, 11.17]

Some of these are unlike the others. Namely the 14, 9, and the 11. They do not belong. That's fine though, we can get rid of those.

> optimizedAverage( beaconDistances );
< 2.10

Usage

The optimizer will go through the array and tally how many times a number occurs within the array, which it then uses to determine what the most probable distance is (which would be 2 in the example above, as it appears 6 times while 1 merely appeared 4) and then promptly removes any numbers that are greater than double the probable distance and less than half the probable distance (this may change to a configurable buffer in the future if the need is expressed).

var data = [14.78, 2.25, 2.45, 1.87, 1.89, 2.11, 9.33, 1.97, 2.06, 1.93, 2.22, 2.22, 11.17];
var avg = optimizedAverage( data );
// Pre-optimized average: 4.33
// Items removed: 3 [14.78, 9.33, 11.17]
// Optimized average: 2.10

Installation

The utility is both exported as a module for Browserify / Node fun and exposed to the global scope if it's included in the browser, so installation is fairly straight forward.

Browser

  1. Clone down the repo or npm install optimized-averages
  2. Move the minified file into your libs/scripts folder
  3. Toss it on the page yo!
  4. Average like a beast via optimizedAverage( arrayOfNumbersGoesHerePlz );

NPM / Browserify

  1. Install the util as a dependency: npm install --save-dev optimized-averages
  2. Require it up! var optimizedAverage = require('optimized-averages');
  3. Average like an absolute savage optimizedAverage( anArrayPlzINeedAnArrayImHunger );

Thoughts?

If you think this could be extended into something rad feel free to shoot me a message or log an issue. PR's are of course welcome as well.