Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanong committed Oct 11, 2013
0 parents commit 5e531a2
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 0 deletions.
71 changes: 71 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so

# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Logs and databases #
######################
*.log
*.sql
*.sqlite

# OS generated files #
######################
.DS_Store*
ehthumbs.db
Icon?
Thumbs.db

# Node.js #
###########
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

node_modules
npm-debug.log

# Components #
##############

/build
/components

# ImageMagick #
###############

*.cache
*.mpc

# Other #
#########
test/*.2
test/*/*.2
test/*.mp4
test/images/originalSideways.jpg.2
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test.js
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_js:
- "0.10"
language: node_js
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BIN = ./node_modules/.bin/

test:
@${BIN}mocha --reporter spec

.PHONY: test
11 changes: 11 additions & 0 deletions component.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "wilson-score",
"description": "Because averages suck",
"version": "0.0.1",
"license": "MIT",
"scripts": [
"index.js"
],
"main": "index.js",
"repo": "jonathanong/wilson-score"
}
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = function (up, total, z) {
// http://amix.dk/blog/post/19588
// 95% = 1.644853
// 99% = 2.326348
z = z || 2.326348
if (total <= 0 || total < up)
return 0

var phat = up/total, z2 = z*z;
return (phat + z2/(2*total) - z*Math.sqrt((phat*(1 - phat) + z2/(4*total))/total))/(1 + z2/total)
}
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "wilson-score",
"description": "Because averages suck",
"version": "0.0.1",
"author": {
"name": "Jonathan Ong",
"email": "[email protected]",
"url": "http://jongleberry.com",
"twitter": "https://twitter.com/jongleberry"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/jonathanong/wilson-score.git"
},
"bugs": {
"mail": "[email protected]",
"url": "https://github.com/jonathanong/wilson-score/issues"
},
"devDependencies": {
"mocha": "*"
},
"scripts": {
"test": "make test;"
}
}
13 changes: 13 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var assert = require('assert')

var wilson = require('./')

describe('Wilson Score', function () {
it('should be lower than the average', function () {
assert.ok(wilson(3, 5) < 3 / 5)
})

it('should be 0 if there are no ups', function () {
assert.equal(wilson(0, 100), 0)
})
})

0 comments on commit 5e531a2

Please sign in to comment.