Skip to content

Commit

Permalink
Changed ranking system
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosx001 committed Aug 28, 2021
1 parent 1a3edca commit 6bfa6ee
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 79 deletions.
101 changes: 23 additions & 78 deletions src/calculateRank.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
// https://stackoverflow.com/a/5263759/10629172
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);
}

function calculateRank({
totalRepos,
totalCommits,
Expand All @@ -25,69 +7,32 @@ function calculateRank({
issues,
stargazers,
}) {
const COMMITS_OFFSET = 1.65;
const CONTRIBS_OFFSET = 1.65;
const ISSUES_OFFSET = 1;
const STARS_OFFSET = 0.75;
const PRS_OFFSET = 0.5;
const FOLLOWERS_OFFSET = 0.45;
const REPO_OFFSET = 1;

const ALL_OFFSETS =
CONTRIBS_OFFSET +
ISSUES_OFFSET +
STARS_OFFSET +
PRS_OFFSET +
FOLLOWERS_OFFSET +
REPO_OFFSET;
const COMMITS = 30;
const CONTRIBS = 25;
const REPO = 20;
const ISSUES = 20;
const STARS = 15;
const PRS = 10;
const FOLLOWERS = 5;

const RANK_S_VALUE = 1;
const RANK_DOUBLE_A_VALUE = 25;
const RANK_A2_VALUE = 45;
const RANK_A3_VALUE = 60;
const RANK_B_VALUE = 100;

const TOTAL_VALUES =
RANK_S_VALUE + RANK_A2_VALUE + RANK_A3_VALUE + RANK_B_VALUE;

// prettier-ignore
const score = (
totalCommits * COMMITS_OFFSET +
contributions * CONTRIBS_OFFSET +
issues * ISSUES_OFFSET +
stargazers * STARS_OFFSET +
prs * PRS_OFFSET +
followers * FOLLOWERS_OFFSET +
totalRepos * REPO_OFFSET
) / 100;

const normalizedScore = normalcdf(score, TOTAL_VALUES, ALL_OFFSETS) * 100;

let level = "";

if (normalizedScore < RANK_S_VALUE) {
level = "S+";
}
if (
normalizedScore >= RANK_S_VALUE &&
normalizedScore < RANK_DOUBLE_A_VALUE
) {
level = "S";
}
if (
normalizedScore >= RANK_DOUBLE_A_VALUE &&
normalizedScore < RANK_A2_VALUE
) {
level = "A++";
totalCommits * COMMITS +
contributions * CONTRIBS +
issues * ISSUES +
stargazers * STARS +
prs * PRS +
followers * FOLLOWERS +
totalRepos * REPO
);

if (score < 100) {
let level = "0"
return {level, "score": score}
}
if (normalizedScore >= RANK_A2_VALUE && normalizedScore < RANK_A3_VALUE) {
level = "A+";
}
if (normalizedScore >= RANK_A3_VALUE && normalizedScore < RANK_B_VALUE) {
level = "B+";
}

return { level, score: normalizedScore };
let c = - 5 - score
let discriminant = Math.sqrt(Math.pow(100, 2) - 4 * 5 * c)
let level = parseInt((discriminant - 100) / 10).toString()
return { level, "score": score};
}

module.exports = calculateRank;
2 changes: 1 addition & 1 deletion src/cards/stats-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {

// the better user's score the the rank will be closer to zero so
// subtracting 100 to get the progress in 100%
const progress = 100 - rank.score;
const progress = 100; // FIX LATER - rank.score;
const cssStyles = getStyles({
titleColor,
textColor,
Expand Down

0 comments on commit 6bfa6ee

Please sign in to comment.