mirror of
https://github.com/Aviortheking/codestats-readme.git
synced 2025-04-22 10:42:08 +00:00
Merge pull request #49 from anuraghazra/ranking-algo
improve: improved rating algorithm wip fix: fixed #39
This commit is contained in:
commit
987fb0c30d
@ -1,3 +1,21 @@
|
|||||||
|
// 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({
|
function calculateRank({
|
||||||
totalRepos,
|
totalRepos,
|
||||||
totalCommits,
|
totalCommits,
|
||||||
@ -13,12 +31,24 @@ function calculateRank({
|
|||||||
const STARS_OFFSET = 0.75;
|
const STARS_OFFSET = 0.75;
|
||||||
const PRS_OFFSET = 0.5;
|
const PRS_OFFSET = 0.5;
|
||||||
const FOLLOWERS_OFFSET = 0.45;
|
const FOLLOWERS_OFFSET = 0.45;
|
||||||
|
const REPO_OFFSET = 1;
|
||||||
|
|
||||||
const FIRST_STEP = 0;
|
const ALL_OFFSETS =
|
||||||
const SECOND_STEP = 5;
|
CONTRIBS_OFFSET +
|
||||||
const THIRD_STEP = 20;
|
ISSUES_OFFSET +
|
||||||
const FOURTH_STEP = 50;
|
STARS_OFFSET +
|
||||||
const FIFTH_STEP = 130;
|
PRS_OFFSET +
|
||||||
|
FOLLOWERS_OFFSET +
|
||||||
|
REPO_OFFSET;
|
||||||
|
|
||||||
|
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
|
// prettier-ignore
|
||||||
const score = (
|
const score = (
|
||||||
@ -27,26 +57,37 @@ function calculateRank({
|
|||||||
issues * ISSUES_OFFSET +
|
issues * ISSUES_OFFSET +
|
||||||
stargazers * STARS_OFFSET +
|
stargazers * STARS_OFFSET +
|
||||||
prs * PRS_OFFSET +
|
prs * PRS_OFFSET +
|
||||||
followers * FOLLOWERS_OFFSET
|
followers * FOLLOWERS_OFFSET +
|
||||||
) / totalRepos;
|
totalRepos * REPO_OFFSET
|
||||||
|
) / 100;
|
||||||
|
|
||||||
|
const normalizedScore = normalcdf(score, TOTAL_VALUES, ALL_OFFSETS) * 100;
|
||||||
|
|
||||||
let level = "";
|
let level = "";
|
||||||
|
|
||||||
if (score == FIRST_STEP) {
|
if (normalizedScore < RANK_S_VALUE) {
|
||||||
level = "B";
|
|
||||||
} else if (score > FIRST_STEP && score <= SECOND_STEP) {
|
|
||||||
level = "B+";
|
|
||||||
} else if (score > SECOND_STEP && score <= THIRD_STEP) {
|
|
||||||
level = "A";
|
|
||||||
} else if (score > THIRD_STEP && score <= FOURTH_STEP) {
|
|
||||||
level = "A+";
|
|
||||||
} else if (score > FOURTH_STEP && score <= FIFTH_STEP) {
|
|
||||||
level = "A++";
|
|
||||||
} else if (score > FIFTH_STEP) {
|
|
||||||
level = "S+";
|
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++";
|
||||||
|
}
|
||||||
|
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 };
|
return { level, score: normalizedScore };
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = calculateRank;
|
module.exports = calculateRank;
|
||||||
|
@ -26,7 +26,7 @@ const fetcher = (variables, token) => {
|
|||||||
followers {
|
followers {
|
||||||
totalCount
|
totalCount
|
||||||
}
|
}
|
||||||
repositories(first: 100, orderBy: { direction: DESC, field: STARGAZERS }) {
|
repositories(first: 100, ownerAffiliations: OWNER, isFork: false, orderBy: {direction: DESC, field: STARGAZERS}) {
|
||||||
totalCount
|
totalCount
|
||||||
nodes {
|
nodes {
|
||||||
stargazers {
|
stargazers {
|
||||||
|
@ -127,14 +127,9 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
|
|||||||
</text>
|
</text>
|
||||||
</g>`;
|
</g>`;
|
||||||
|
|
||||||
// re-adjust circle progressbar's value until the ranking algo is improved
|
// the better user's score the the rank will be closer to zero so
|
||||||
let progress = rank.score;
|
// subtracting 100 to get the progress in 100%
|
||||||
if (rank.score > 86) {
|
let progress = 100 - rank.score;
|
||||||
progress = (40 + rank.score) * 0.6;
|
|
||||||
}
|
|
||||||
if (rank.score < 40) {
|
|
||||||
progress = 40 + rank.score;
|
|
||||||
}
|
|
||||||
|
|
||||||
const styles = getStyles({
|
const styles = getStyles({
|
||||||
titleColor,
|
titleColor,
|
||||||
|
@ -13,6 +13,6 @@ describe("Test calculateRank", () => {
|
|||||||
prs: 300,
|
prs: 300,
|
||||||
issues: 200,
|
issues: 200,
|
||||||
})
|
})
|
||||||
).toStrictEqual({ level: "S+", score: 192.13 });
|
).toStrictEqual({ level: "A+", score: 49.16605417270399 });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user