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

@iusername/percentile

v1.0.2

Published

Calculate a percentile for given array of values

Downloads

5

Readme

介绍

本工具根据 excel 中 percentile 算法计算百分位数值

如果你是需要求数据中最接近所给百分位的值的话可以使用percentile而非@iusername/percentile

安装

npm i @iusername/percentile

// 或者
yarn add @iusername/percentile

使用

// node
const Percentile = require('@iusername/percentile')

// ES Module
import Percentile from '@iusername/percentile'

只求值一次的情况

var percentile = new Percentile()

// mock data
const data = [2, 3, 5, 5, 5, 7, 20, 21]

var res = percentile.incsOnce(data, [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100])
// res: [2, 2.7, 3.8, 5, 5, 5, 5.4, 6.8, 14.8, 20.3, 21]

var res = percentile.incOnce(data, 90)
// res: 20.3

需要多次求值时,可以通过初始化时传入 data 或者 init(data) 来缓存处理好的 data 数据减少每次求值所耗时间

const data = [2, 3, 5, 5, 5, 7, 20, 21]

var percentile = new Percentile(data)
// 或者下面注释部分也行
// PS: init 后会覆盖上一次 init 或者初始化时的缓存数据
/*
  var percentile = new Percentile()
  percentile.init(data)
*/

// inc 方式
var res = percentile.incValue(90)
// res: 20.3

var res = percentile.incValues([80, 90, 100])
// res: [14.8, 20.3, 21]

// exc 方式
var res = percentile.excValue(90)
// res: '#NUM!'

var res = percentile.incValues([80, 90, 100])
// res: [20.2, '#NUM!', '#NUM!']

实例方法

  • 方法中的参数说明
  1. data: 用于计算的原数组
  2. P:百分位值 1~100, inc时为闭区间,exc时为开区间
  3. PList: 需要一次求得的多个百分位值得数组
  4. accuracy:结果的小数位数精度值,默认为 1 表示一位小数
  • init(data: number[])

初始化 percentile对象数据,后续则不需要再传入相同数据进行计算了

  • incValue(P: number, accuracy?: number)

根据 PERCENTILE.INC 获取结果

  • incValues(PList: number[], accuracy?: number)

根据 PERCENTILE.INC 获取多个对应结果

  • excValue(P: number, accuracy?: number)

根据 PERCENTILE.EXC 获取结果

  • excValues(PList: number[], accuracy?: number)

根据 PERCENTILE.EXC 获取多个对应结果

  • incOnce(data: number[], P: number, accuracy?: number)

根据 PERCENTILE.INC 获取结果,data 不会被缓存,适用于只计算一次即可的情况,用完后实例对象会恢复原先缓存data

  • incsOnce(data: number[], PList: number[], accuracy?: number)

incOnce 的多值用法

  • excOnce(data: number[], P: number, accuracy?: number)

根据 PERCENTILE.EXC 获取结果,data 不会被缓存,适用于只计算一次即可的情况,用完后实例对象会恢复原先缓存data

  • excsOnce(data: number[], PList: number[], accuracy?: number)

excOnce 的多值用法

静态方法

  • help()

查看计算说明

!注意

计算说明

// 运行下面代码后再控制台查看
Percentile.help()

Microsoft Office 中 PERCENTILE 函数说明

PERCENTILE 函数

License

MIT