From 9c01a95a2324f54f7b51d1cdac1d3213561f28fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Rozet?= Date: Sun, 18 Jul 2021 15:32:22 +0200 Subject: [PATCH] Lower average stats and S+ threshold --- src/calculateRank.js | 27 ++++++++++++--------------- tests/calculateRank.test.js | 16 ++++++++-------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/calculateRank.js b/src/calculateRank.js index a8f2fc87ed71a..df6fdcd3d81c2 100644 --- a/src/calculateRank.js +++ b/src/calculateRank.js @@ -1,24 +1,22 @@ function expsf(x, lambda=1.) { - return Math.exp(-lambda * x); + return 2 ** (-lambda * x); } function calculateRank({ - totalRepos, + totalRepos, // unused totalCommits, - contributions, + contributions, // unused followers, prs, issues, stargazers, }) { - const REPOS_MEAN = 10, REPOS_WEIGHT = 0.125; - const COMMITS_MEAN = 1000, COMMITS_WEIGHT = 0.125; - const FOLLOWERS_MEAN = 50, FOLLOWERS_WEIGHT = 0.5; - const PRS_ISSUES_MEAN = 50, PRS_ISSUES_WEIGHT = 0.25; + const COMMITS_MEAN = 500, COMMITS_WEIGHT = 0.25; + const FOLLOWERS_MEAN = 50, FOLLOWERS_WEIGHT = 0.25; + const PRS_ISSUES_MEAN = 25, PRS_ISSUES_WEIGHT = 0.25; const STARS_MEAN = 100, STARS_WEIGHT = 1.0; const TOTAL_WEIGHT = ( - REPOS_WEIGHT + COMMITS_WEIGHT + FOLLOWERS_WEIGHT + PRS_ISSUES_WEIGHT + @@ -26,14 +24,13 @@ function calculateRank({ ); 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; @@ -41,15 +38,15 @@ function calculateRank({ 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"; diff --git a/tests/calculateRank.test.js b/tests/calculateRank.test.js index be37cec23e44c..0b43f06f6f2c0 100644 --- a/tests/calculateRank.test.js +++ b/tests/calculateRank.test.js @@ -20,20 +20,20 @@ describe("Test calculateRank", () => { expect( calculateRank({ totalRepos: 10, - totalCommits: 1000, - contributions: 1000, + totalCommits: 500, + contributions: 500, followers: 50, - prs: 25, - issues: 25, + prs: 12, + issues: 13, stargazers: 100, }), - ).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, @@ -41,6 +41,6 @@ describe("Test calculateRank", () => { issues: 2, stargazers: 109100, }), - ).toStrictEqual({ level: "S", score: 7.092453734726941}); + ).toStrictEqual({level: "S+", score: 1.8875322153011722}); }); });