Skip to content

Commit

Permalink
Lower average stats and S+ threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
francois-rozet committed Jul 18, 2021
1 parent 7a652bf commit 6ccab0a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
23 changes: 10 additions & 13 deletions src/calculateRank.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function expsf(x, lambda=1.) {
return Math.exp(-lambda * x);
return 2 ** (-lambda * x);
}

function calculateRank({
Expand All @@ -11,45 +11,42 @@ function calculateRank({
issues,
stargazers,
}) {
const REPOS_MEAN = 10, REPOS_WEIGHT = 0.125;
const COMMITS_MEAN = 1000, COMMITS_WEIGHT = 0.125;
const COMMITS_MEAN = 500, COMMITS_WEIGHT = 0.25;
const FOLLOWERS_MEAN = 50, FOLLOWERS_WEIGHT = 0.5;
const PRS_ISSUES_MEAN = 50, PRS_ISSUES_WEIGHT = 0.25;
const STARS_MEAN = 100, STARS_WEIGHT = 1.0;
const PRS_ISSUES_MEAN = 25, PRS_ISSUES_WEIGHT = 0.25;
const STARS_MEAN = 50, STARS_WEIGHT = 1.0;

const TOTAL_WEIGHT = (
REPOS_WEIGHT +
COMMITS_WEIGHT +
FOLLOWERS_WEIGHT +
PRS_ISSUES_WEIGHT +
STARS_WEIGHT
);

const rank = (
REPOS_WEIGHT * expsf(totalRepos, 1 / REPOS_MEAN) +
COMMITS_WEIGHT * expsf(totalCommits, 1 / COMMITS_MEAN) +
FOLLOWERS_WEIGHT * expsf(followers, 1 / FOLLOWERS_MEAN) +
PRS_ISSUES_WEIGHT * expsf(prs + issues, 1 / PRS_ISSUES_MEAN) +
STARS_WEIGHT * expsf(stargazers, 1 / STARS_MEAN)
) / TOTAL_WEIGHT;

const RANK_S_PLUS = 0.01;
const RANK_S_PLUS = 0.025;
const RANK_S = 0.1;
const RANK_A_PLUS = 0.25;
const RANK_A = 0.50;
const RANK_B_PLUS = 0.75;

let level = "";

if (rank < RANK_S_PLUS)
if (rank <= RANK_S_PLUS)
level = "S+";
else if (rank < RANK_S)
else if (rank <= RANK_S)
level = "S";
else if (rank < RANK_A_PLUS)
else if (rank <= RANK_A_PLUS)
level = "A+";
else if (rank < RANK_A)
else if (rank <= RANK_A)
level = "A";
else if (rank < RANK_B_PLUS)
else if (rank <= RANK_B_PLUS)
level = "B+";
else
level = "B";
Expand Down
18 changes: 9 additions & 9 deletions tests/calculateRank.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@ describe("Test calculateRank", () => {
expect(
calculateRank({
totalRepos: 10,
totalCommits: 1000,
contributions: 1000,
totalCommits: 500,
contributions: 500,
followers: 50,
prs: 25,
issues: 25,
stargazers: 100,
prs: 12,
issues: 13,
stargazers: 50,
}),
).toStrictEqual({"A", score: 36.787944117144235});
).toStrictEqual({"A", score: 50.});
});

it("Linus Torvalds gets S rank", () => {
it("Linus Torvalds gets S+ rank", () => {
expect(
calculateRank({
totalRepos: 4, // few repos
totalRepos: 4,
totalCommits: 20000,
contributions: 20000,
followers: 132000,
prs: 71,
issues: 2,
stargazers: 109100,
}),
).toStrictEqual({ level: "S", score: 7.092453734726941});
).toStrictEqual({ level: "S+", score: 1.6515906883885256});
});
});

0 comments on commit 6ccab0a

Please sign in to comment.