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

@fnet/relative-levels

v0.1.13

Published

The `@fnet/relative-levels` project is designed to analyze a given set of numbers and categorize them into specified levels based on their distribution. It helps users understand the relative positioning of numbers by dividing them into ranges and providi

Downloads

212

Readme

@fnet/relative-levels

The @fnet/relative-levels project is designed to analyze a given set of numbers and categorize them into specified levels based on their distribution. It helps users understand the relative positioning of numbers by dividing them into ranges and providing counts for each of these ranges. This can be particularly useful for data analysis, allowing users to identify patterns or trends within a dataset.

How It Works

The project operates by taking an array of numbers and dividing them into multiple levels based on average values. Specifically, it calculates average values for each level, dividing the numbers from the middle outward to create upper and lower levels. It then applies linear interpolation to predict average values between the calculated points. Lastly, it categorizes the input numbers into ranges determined by these predicted averages.

Key Features

  • Dynamic Level Creation: Capable of segmenting data into a customizable number of levels, with the requirement that the number must be odd and greater than two.
  • Average Calculation: Computes average values for each level and uses these to predict intermediate averages.
  • Range and Count Analysis: Provides ranges based on predicted averages and counts the number of elements falling within each range.
  • Level Identification: Offers a feature to find out which range a particular number falls into.

Conclusion

The @fnet/relative-levels project provides a straightforward way of categorizing numeric data into levels, offering insights into the distribution and range of the dataset. Its ability to predict and use linear interpolation for this purpose makes it a useful tool for those seeking to understand and segment data effectively without any unnecessary complexity.

@fnet/relative-levels Developer Guide

Overview

The @fnet/relative-levels library provides a way to categorize a list of numbers into distinct levels using averages and a quadratic prediction model. Developers can use this library to segment numerical data into ranges, analyze spread and concentration, and query level assignments for individual numbers. The core functionality is accessible through a simple interface.

Installation

To install the @fnet/relative-levels library, you can use either npm or yarn:

Using npm:

npm install @fnet/relative-levels

Using yarn:

yarn add @fnet/relative-levels

Usage

Here's a step-by-step guide on how to use the core function provided by the library:

  1. Import the Library: First, import the library into your project.

    import relativeLevels from '@fnet/relative-levels';
  2. Prepare Your Data: Ensure you have an array of numbers you wish to analyze. For example:

    const numbers = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20];
  3. Invoke the Function: Use the relativeLevels function to compute the levels. You can specify the number of levels, which must be an odd number greater than 2.

    const { ranges, get } = relativeLevels({ numbers, levels: 5 });
  4. Utilize the Results: You can then use the results to examine the ranges and counts of each level or determine the level of a specific number.

    console.log(ranges);
    // Output: An array of objects indicating the range and count of numbers within each level.
    
    const numberLevel = get(10);
    console.log(numberLevel);
    // Output: The level index of the number 10.

Examples

Below are code examples demonstrating typical use cases of the library:

Example 1: Basic Level Segmentation

import relativeLevels from '@fnet/relative-levels';

const numbers = [1, 7, 3, 5, 9];
const { ranges } = relativeLevels({ numbers, levels: 3 });

console.log(ranges);
// Example output: [
//   { range: [Number.NEGATIVE_INFINITY, 4], count: 2 },
//   { range: [4, 8], count: 2 },
//   { range: [8, Number.POSITIVE_INFINITY], count: 1 }
// ]

Example 2: Finding Level of a Number

import relativeLevels from '@fnet/relative-levels';

const numbers = [12, 15, 14, 19, 23];
const { get } = relativeLevels({ numbers, levels: 3 });

const levelIndex = get(15);
console.log(levelIndex);
// Example output: 1 (Level index for the number 15)

Acknowledgement

This guide was created to help developers integrate and utilize the @fnet/relative-levels library effectively in their projects. We appreciate any feedback for continuous improvement.

Input Schema

$schema: https://json-schema.org/draft/2020-12/schema
title: Index Function Schema
type: object
properties:
  numbers:
    type: array
    items:
      type: number
    description: The array of numbers to process.
  levels:
    type: integer
    default: 5
    description: The number of levels, must be odd and greater than 2.
    minimum: 3
    pattern: ^(?![02468]$).*$
  returns:
    type: array
    items:
      type: object
      properties:
        range:
          type: array
          items:
            anyOf:
              - type: number
              - enum:
                  - Number.NEGATIVE_INFINITY
                  - Number.POSITIVE_INFINITY
          minItems: 2
          maxItems: 2
          description: Defines the range for the level.
        count:
          type: integer
          description: The count of numbers within this range.