- Notifications
You must be signed in to change notification settings - Fork7
Calculate average score and rating based on Wilson Score Equation
License
ndaidong/average-rating
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Calculate average and scoring based on Wilson Score Equation
https://jsr.io/@ndaidong/average-rating
deno add @ndaidong/average-rating# npm (use any of npx, yarn dlx, pnpm dlx, or bunx)npx jsr add @ndaidong/average-rating
// es6 moduleimport{average,rate,score}from"@ndaidong/average-rating";// CommonJSconst{ score, rate, average,}=require("@ndaidong/average-rating");score(80,20);// => 0.71rate([134055,57472,143135,365957,1448459]);// => 0.84average([134055,57472,143135,365957,1448459]);// => 4.4
You can use JSR packages without an install step usingjsr:
specifiers:
import{average}from"jsr:@ndaidong/average-rating";average([134055,57472,143135,365957,1448459]);// => 4.4
You can also usenpm:
specifiers as before:
import{average}from"npm:@ndaidong/average-rating";average([134055,57472,143135,365957,1448459]);// => 4.4
Or import from esm.sh
import{average}from"https://esm.sh/@ndaidong/average-rating";average([134055,57472,143135,365957,1448459]);// => 4.4
https://www.npmjs.com/package/@ndaidong/average-rating
npm i @ndaidong/average-rating# pnpmpnpm i @ndaidong/average-rating# yarnyarn add @ndaidong/average-rating# bunbun add @ndaidong/average-rating
import{average}from"@ndaidong/average-rating";average([134055,57472,143135,365957,1448459]);// => 4.4
You can also use CJS style:
const{ average}=require("@ndaidong/average-rating");average([134055,57472,143135,365957,1448459]);// => 4.4
<scripttype="module">import{average}from"https://esm.sh/@ndaidong/average-rating";// import { average } from 'https://unpkg.com/@ndaidong/average-rating/esm/mod.js';average([134055,57472,143135,365957,1448459])// => 4.4</script>
This method returns a normalized value between 0 and 1, but it's applicable for systemswith only positive and negative ratings (like/dislike, thumbs up/thumbs down).Examples include videos on YouTube or answers on Stack Overflow.In these systems, users can express their opinion by voting for either a positive or negative option.
Let's illustrate how this method works with a blog post that received 80 likes and 20 dislikes:
import{score}from"@ndaidong/average-rating";score(80,20);// => 0.71
This method returns a normalized value between 0 and 1, commonly used in rating systems with 5 levels.Examples include applications on Google Play Store or books on Amazon.In these systems, each item receives a user rating between 1 and 5 stars.
Let's take a product with a large volume of reviews as an example. Here's how we calculate its rating:
- 134,055 customers rated it 1 star
- 57,472 gave it a 2-star rating
- There are 143,135 ratings of 3 stars
- It received a 4-star rating from 365,957 users
- And a whopping 1,448,459 customers rated it 5 stars
import{rate}from"@ndaidong/average-rating";rate([134055,57472,143135,365957,1448459]);// => 0.84
- Since v1.1.5, this
rate
method accepts custom range of ratings. 5 or morevalues are OK.
constinput=[3,4,2,6,12,46,134,213,116,91,45,15,58,96,1654];// 15 valuesrate(input);// => 0.85rate([3,4,2,6,12,46,134,213,116,91]);// => 0.74
Return a value from 0 to 5.
Calculate normal average value for the systems of 5 rating levels.
import{average}from"@ndaidong/average-rating";average([134055,57472,143135,365957,1448459]);// => 4.4
Since v3.x.x, we switched toDenoplatform, and useDNT to build Node.jspackages.
git clone https://github.com/ndaidong/average-rating.gitcd average-rating# testdenotest# build npm packagesdeno task buildcd npmnode test_runner.js
The MIT License (MIT)
About
Calculate average score and rating based on Wilson Score Equation
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.