Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrected rank normal distribution #817

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@actions/github": "^4.0.0",
"@testing-library/dom": "^7.20.0",
"@testing-library/jest-dom": "^5.11.0",
"axios": "^0.19.2",
"axios": "^0.21.1",
"axios-mock-adapter": "^1.18.1",
"css-to-object": "^1.1.0",
"husky": "^4.2.5",
Expand All @@ -28,7 +28,8 @@
"emoji-name-map": "^1.2.8",
"github-username-regex": "^1.0.0",
"prettier": "^2.1.2",
"word-wrap": "^1.2.3"
"word-wrap": "^1.2.3",
"mathjs": "^9.0.0"
},
"husky": {
"hooks": {
Expand Down
24 changes: 7 additions & 17 deletions src/calculateRank.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
// https://stackoverflow.com/a/5263759/10629172
const { erf } = require("mathjs");
const invSqrt2 = 1 / Math.sqrt(2);
// https://mathworld.wolfram.com/NormalDistribution.html
function normalcdf(mean, sigma, to) {
var z = (to - mean) / Math.sqrt(2 * sigma * sigma);
var t = 1 / (1 + 0.3275911 * Math.abs(z));
var a1 = 0.254829592;
var a2 = -0.284496736;
var a3 = 1.421413741;
var a4 = -1.453152027;
var a5 = 1.061405429;
var erf =
1 - ((((a5 * t + a4) * t + a3) * t + a2) * t + a1) * t * Math.exp(-z * z);
var sign = 1;
if (z < 0) {
sign = -1;
}
return (1 / 2) * (1 + sign * erf);
const a = (invSqrt2 * (to - mean)) / sigma;
return (1 + erf(a)) / 2;
}

function calculateRank({
Expand Down Expand Up @@ -57,8 +47,8 @@ function calculateRank({
issues * ISSUES_OFFSET +
stargazers * STARS_OFFSET +
prs * PRS_OFFSET +
followers * FOLLOWERS_OFFSET +
totalRepos * REPO_OFFSET
followers * FOLLOWERS_OFFSET +
totalRepos * REPO_OFFSET
) / 100;

const normalizedScore = normalcdf(score, TOTAL_VALUES, ALL_OFFSETS) * 100;
Expand Down
2 changes: 1 addition & 1 deletion tests/calculateRank.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ describe("Test calculateRank", () => {
prs: 300,
issues: 200,
}),
).toStrictEqual({ level: "A+", score: 49.16605417270399 });
).toStrictEqual({ level: "A+", score: 49.16605835034125 });
});
});