From 2c4331d0613bb828005edf910a09fdc21b6ac967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Rozet?= Date: Tue, 13 Jul 2021 16:41:01 +0200 Subject: [PATCH 01/13] Revise rank calculation --- src/calculateRank.js | 109 +++++++++++++----------------------- tests/calculateRank.test.js | 46 ++++++++++++--- 2 files changed, 75 insertions(+), 80 deletions(-) diff --git a/src/calculateRank.js b/src/calculateRank.js index 76909d09547cd..2cee48f722ac7 100644 --- a/src/calculateRank.js +++ b/src/calculateRank.js @@ -1,19 +1,5 @@ -// 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 expsf(x, lambda=1.) { + return Math.exp(-lambda * x); } function calculateRank({ @@ -25,69 +11,50 @@ 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 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; + const REPOS_MEAN = 10, REPOS_WEIGHT = 0.125; + const CONTRIBS_MEAN = 1000, CONTRIBS_WEIGHT = 0.125; + 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 TOTAL_WEIGHT = ( + REPOS_WEIGHT + + CONTRIBS_WEIGHT + + FOLLOWERS_WEIGHT + + PRS_ISSUES_WEIGHT + + STARS_WEIGHT + ); + + const rank = ( + REPOS_WEIGHT * expsf(totalRepos / REPOS_MEAN) + + CONTRIBS_WEIGHT * expsf(contributions / CONTRIBS_MEAN) + + FOLLOWERS_WEIGHT * expsf(followers / FOLLOWERS_MEAN) + + PRS_ISSUES_WEIGHT * expsf((prs + issues) / PRS_ISSUES_MEAN) + + STARS_WEIGHT * expsf(stargazers / STARS_MEAN) + ) / TOTAL_WEIGHT; + + const RANK_S_PLUS = 0.01; + 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 (normalizedScore < RANK_S_VALUE) { + if (rank < RANK_S_PLUS) level = "S+"; - } - if ( - normalizedScore >= RANK_S_VALUE && - normalizedScore < RANK_DOUBLE_A_VALUE - ) { + else if (rank < RANK_S) level = "S"; - } - if ( - normalizedScore >= RANK_DOUBLE_A_VALUE && - normalizedScore < RANK_A2_VALUE - ) { - level = "A++"; - } - if (normalizedScore >= RANK_A2_VALUE && normalizedScore < RANK_A3_VALUE) { + else if (rank < RANK_A_PLUS) level = "A+"; - } - if (normalizedScore >= RANK_A3_VALUE && normalizedScore < RANK_B_VALUE) { + else if (rank < RANK_A) + level = "A"; + else if (rank < RANK_B_PLUS) level = "B+"; - } + else + level = "B"; - return { level, score: normalizedScore }; + return {level, score: rank * 100}; } module.exports = calculateRank; diff --git a/tests/calculateRank.test.js b/tests/calculateRank.test.js index 4b9fd072b4aa4..be37cec23e44c 100644 --- a/tests/calculateRank.test.js +++ b/tests/calculateRank.test.js @@ -2,17 +2,45 @@ require("@testing-library/jest-dom"); const calculateRank = require("../src/calculateRank"); describe("Test calculateRank", () => { - it("should calculate rank correctly", () => { + it("new user gets B rank", () => { expect( calculateRank({ - totalCommits: 100, - totalRepos: 5, - followers: 100, - contributions: 61, - stargazers: 400, - prs: 300, - issues: 200, + totalRepos: 0, + totalCommits: 0, + contributions: 0, + followers: 0, + prs: 0, + issues: 0, + stargazers: 0, }), - ).toStrictEqual({ level: "A+", score: 49.16605417270399 }); + ).toStrictEqual({level: "B", score: 100.}); + }); + + it("average user gets A rank", () => { + expect( + calculateRank({ + totalRepos: 10, + totalCommits: 1000, + contributions: 1000, + followers: 50, + prs: 25, + issues: 25, + stargazers: 100, + }), + ).toStrictEqual({"A", score: 36.787944117144235}); + }); + + it("Linus Torvalds gets S rank", () => { + expect( + calculateRank({ + totalRepos: 4, // few repos + totalCommits: 20000, + contributions: 20000, + followers: 132000, + prs: 71, + issues: 2, + stargazers: 109100, + }), + ).toStrictEqual({ level: "S", score: 7.092453734726941}); }); }); From 7a652bf1440b2acdc7a33fd4d372b21b158e65d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Rozet?= Date: Wed, 14 Jul 2021 00:16:37 +0200 Subject: [PATCH 02/13] Replace contributions by commits --- src/calculateRank.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/calculateRank.js b/src/calculateRank.js index 2cee48f722ac7..a8f2fc87ed71a 100644 --- a/src/calculateRank.js +++ b/src/calculateRank.js @@ -12,25 +12,25 @@ function calculateRank({ stargazers, }) { const REPOS_MEAN = 10, REPOS_WEIGHT = 0.125; - const CONTRIBS_MEAN = 1000, CONTRIBS_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 STARS_MEAN = 100, STARS_WEIGHT = 1.0; const TOTAL_WEIGHT = ( REPOS_WEIGHT + - CONTRIBS_WEIGHT + + COMMITS_WEIGHT + FOLLOWERS_WEIGHT + PRS_ISSUES_WEIGHT + STARS_WEIGHT ); const rank = ( - REPOS_WEIGHT * expsf(totalRepos / REPOS_MEAN) + - CONTRIBS_WEIGHT * expsf(contributions / CONTRIBS_MEAN) + - FOLLOWERS_WEIGHT * expsf(followers / FOLLOWERS_MEAN) + - PRS_ISSUES_WEIGHT * expsf((prs + issues) / PRS_ISSUES_MEAN) + - STARS_WEIGHT * expsf(stargazers / STARS_MEAN) + 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; 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 03/13] 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}); }); }); From 7fd6551bbbfd382a98e52056ee5f5cf4155e1bad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Rozet?= Date: Tue, 9 Nov 2021 11:04:17 +0100 Subject: [PATCH 04/13] Fix calculateRank.test.js Missing key in dictionary constructor Co-authored-by: Rick Staa --- tests/calculateRank.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/calculateRank.test.js b/tests/calculateRank.test.js index 0b43f06f6f2c0..c114702c2357d 100644 --- a/tests/calculateRank.test.js +++ b/tests/calculateRank.test.js @@ -27,7 +27,7 @@ describe("Test calculateRank", () => { issues: 13, stargazers: 100, }), - ).toStrictEqual({"A", score: 50.}); + ).toStrictEqual({level: "A", score: 50.}); }); it("Linus Torvalds gets S+ rank", () => { From e10cae6df22a7432876141e2745a0ed873189c91 Mon Sep 17 00:00:00 2001 From: rickstaa Date: Fri, 23 Sep 2022 09:26:18 +0200 Subject: [PATCH 05/13] refactor: run prettier --- src/calculateRank.js | 42 ++++++++++++++++++------------------- tests/calculateRank.test.js | 6 +++--- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/calculateRank.js b/src/calculateRank.js index a835e5dd2fbd8..dc9d32ff8787a 100644 --- a/src/calculateRank.js +++ b/src/calculateRank.js @@ -1,39 +1,39 @@ -function expsf(x, lambda=1.) { +function expsf(x, lambda = 1) { return 2 ** (-lambda * x); } function calculateRank({ - totalRepos, // unused + totalRepos, // unused totalCommits, - contributions, // unused + contributions, // unused followers, prs, issues, stargazers, }) { - 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 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 = ( - COMMITS_WEIGHT + - FOLLOWERS_WEIGHT + - PRS_ISSUES_WEIGHT + - STARS_WEIGHT - ); + const TOTAL_WEIGHT = + COMMITS_WEIGHT + FOLLOWERS_WEIGHT + PRS_ISSUES_WEIGHT + STARS_WEIGHT; - const rank = ( - 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 = + (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.025; const RANK_S = 0.1; const RANK_A_PLUS = 0.25; - const RANK_A = 0.50; + const RANK_A = 0.5; const RANK_B_PLUS = 0.75; const level = (() => { @@ -45,7 +45,7 @@ function calculateRank({ return "B"; })(); - return {level, score: rank * 100}; + return { level, score: rank * 100 }; } module.exports = calculateRank; diff --git a/tests/calculateRank.test.js b/tests/calculateRank.test.js index c114702c2357d..5c9c42478a567 100644 --- a/tests/calculateRank.test.js +++ b/tests/calculateRank.test.js @@ -13,7 +13,7 @@ describe("Test calculateRank", () => { issues: 0, stargazers: 0, }), - ).toStrictEqual({level: "B", score: 100.}); + ).toStrictEqual({ level: "B", score: 100 }); }); it("average user gets A rank", () => { @@ -27,7 +27,7 @@ describe("Test calculateRank", () => { issues: 13, stargazers: 100, }), - ).toStrictEqual({level: "A", score: 50.}); + ).toStrictEqual({ level: "A", score: 50 }); }); it("Linus Torvalds gets S+ rank", () => { @@ -41,6 +41,6 @@ describe("Test calculateRank", () => { issues: 2, stargazers: 109100, }), - ).toStrictEqual({level: "S+", score: 1.8875322153011722}); + ).toStrictEqual({ level: "S+", score: 1.8875322153011722 }); }); }); From 9900d74f3e5c7ae0e805035f878c08f9999e0d93 Mon Sep 17 00:00:00 2001 From: rickstaa Date: Sat, 8 Apr 2023 09:42:52 +0200 Subject: [PATCH 06/13] feat: change star weight to 0.75 --- src/calculateRank.js | 2 +- tests/calculateRank.test.js | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/calculateRank.js b/src/calculateRank.js index 77ec325cf5779..23b96722d6522 100644 --- a/src/calculateRank.js +++ b/src/calculateRank.js @@ -18,7 +18,7 @@ function calculateRank({ const PRS_ISSUES_MEAN = 25, PRS_ISSUES_WEIGHT = 0.25; const STARS_MEAN = 100, - STARS_WEIGHT = 1.0; + STARS_WEIGHT = 0.75; const TOTAL_WEIGHT = COMMITS_WEIGHT + FOLLOWERS_WEIGHT + PRS_ISSUES_WEIGHT + STARS_WEIGHT; diff --git a/tests/calculateRank.test.js b/tests/calculateRank.test.js index 940183568bcad..8c4b59ad62377 100644 --- a/tests/calculateRank.test.js +++ b/tests/calculateRank.test.js @@ -30,6 +30,34 @@ describe("Test calculateRank", () => { ).toStrictEqual({ level: "A", score: 50 }); }); + it("more than average user gets A+ rank", () => { + expect( + calculateRank({ + totalRepos: 50, + totalCommits: 1500, + contributions: 1500, + followers: 150, + prs: 50, + issues: 50, + stargazers: 300, + }), + ).toStrictEqual({ level: "A+", score: 11.458333333333332 }); + }); + + it("expert user gets S rank", () => { + expect( + calculateRank({ + totalRepos: 100, + totalCommits: 2000, + contributions: 2000, + followers: 500, + prs: 100, + issues: 100, + stargazers: 500, + }), + ).toStrictEqual({ level: "S", score: 2.685546875 }); + }); + it("Linus Torvalds gets S+ rank", () => { expect( calculateRank({ @@ -41,6 +69,6 @@ describe("Test calculateRank", () => { issues: 2, stargazers: 109100, }), - ).toStrictEqual({ level: "S+", score: 1.8875322153011722 }); + ).toStrictEqual({ level: "S+", score: 2.2021209178513677 }); }); }); From 6fe9bb0e920e90f271b74dcddcd2acdf829c7ae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Rozet?= Date: Sat, 29 Apr 2023 11:24:28 +0000 Subject: [PATCH 07/13] Separate PRs and issues --- src/calculateRank.js | 39 ++++++++-------- src/fetchers/stats-fetcher.js | 33 +++++-------- tests/calculateRank.test.js | 88 ++++++++++++++++++++--------------- 3 files changed, 82 insertions(+), 78 deletions(-) diff --git a/src/calculateRank.js b/src/calculateRank.js index 23b96722d6522..473eb9fd53aa0 100644 --- a/src/calculateRank.js +++ b/src/calculateRank.js @@ -3,32 +3,31 @@ function expsf(x, lambda = 1) { } function calculateRank({ - totalRepos, // unused - totalCommits, - contributions, // unused - followers, + all_commits, + commits, prs, issues, - stargazers, + repos, // unused + stars, + followers, }) { - 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 = 0.75; + const COMMITS_MEAN = all_commits ? 500 : 100, COMMITS_WEIGHT = 1; + const PRS_MEAN = 50, PRS_WEIGHT = 2; + const ISSUES_MEAN = 10, ISSUES_WEIGHT = 1; + const STARS_MEAN = 100, STARS_WEIGHT = 3; + const FOLLOWERS_MEAN = 25, FOLLOWERS_WEIGHT = 1; - const TOTAL_WEIGHT = - COMMITS_WEIGHT + FOLLOWERS_WEIGHT + PRS_ISSUES_WEIGHT + STARS_WEIGHT; + const TOTAL_WEIGHT = COMMITS_WEIGHT + + PRS_WEIGHT + ISSUES_WEIGHT + STARS_WEIGHT + FOLLOWERS_WEIGHT; const rank = - (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; + ( + COMMITS_WEIGHT * expsf(commits, 1 / COMMITS_MEAN) + + PRS_WEIGHT * expsf(prs, 1 / PRS_MEAN) + + ISSUES_WEIGHT * expsf(issues, 1 / ISSUES_MEAN) + + STARS_WEIGHT * expsf(stars, 1 / STARS_MEAN) + + FOLLOWERS_WEIGHT * expsf(followers, 1 / FOLLOWERS_MEAN) + ) / TOTAL_WEIGHT; const RANK_S_PLUS = 0.025; const RANK_S = 0.1; diff --git a/src/fetchers/stats-fetcher.js b/src/fetchers/stats-fetcher.js index a7df1e504db2f..794fffd2a97fa 100644 --- a/src/fetchers/stats-fetcher.js +++ b/src/fetchers/stats-fetcher.js @@ -192,7 +192,7 @@ const fetchStats = async ( totalIssues: 0, totalStars: 0, contributedTo: 0, - rank: { level: "C", score: 0 }, + rank: { level: "B", score: 0 }, }; let res = await statsFetcher(username); @@ -220,6 +220,8 @@ const fetchStats = async ( const user = res.data.data.user; + stats.name = user.name || user.login; + // populate repoToHide map for quick lookup // while filtering out let repoToHide = {}; @@ -229,25 +231,14 @@ const fetchStats = async ( }); } - stats.name = user.name || user.login; - stats.totalIssues = user.openIssues.totalCount + user.closedIssues.totalCount; - - // normal commits - stats.totalCommits = user.contributionsCollection.totalCommitContributions; - - // if include_all_commits then just get that, - // since totalCommitsFetcher already sends totalCommits no need to += if (include_all_commits) { stats.totalCommits = await totalCommitsFetcher(username); - } - - // if count_private then add private commits to totalCommits so far. - if (count_private) { - stats.totalCommits += - user.contributionsCollection.restrictedContributionsCount; + } else { + stats.totalCommits = user.contributionsCollection.totalCommitContributions; } stats.totalPRs = user.pullRequests.totalCount; + stats.totalIssues = user.openIssues.totalCount + user.closedIssues.totalCount; stats.contributedTo = user.repositoriesContributedTo.totalCount; // Retrieve stars while filtering out repositories to be hidden @@ -259,15 +250,15 @@ const fetchStats = async ( return prev + curr.stargazers.totalCount; }, 0); - // @ts-ignore // TODO: Fix this. + // @ts-ignore stats.rank = calculateRank({ - totalCommits: stats.totalCommits, - totalRepos: user.repositories.totalCount, - followers: user.followers.totalCount, - contributions: stats.contributedTo, - stargazers: stats.totalStars, + all_commits: include_all_commits, + commits: stats.totalCommits, prs: stats.totalPRs, issues: stats.totalIssues, + repos: user.repositories.totalCount, + stars: stats.totalStars, + followers: user.followers.totalCount, }); return stats; diff --git a/tests/calculateRank.test.js b/tests/calculateRank.test.js index 8c4b59ad62377..ccd95a50de83f 100644 --- a/tests/calculateRank.test.js +++ b/tests/calculateRank.test.js @@ -5,13 +5,13 @@ describe("Test calculateRank", () => { it("new user gets B rank", () => { expect( calculateRank({ - totalRepos: 0, - totalCommits: 0, - contributions: 0, - followers: 0, + all_commits: false, + commits: 0, prs: 0, issues: 0, - stargazers: 0, + repos: 0, + stars: 0, + followers: 0, }), ).toStrictEqual({ level: "B", score: 100 }); }); @@ -19,56 +19,70 @@ describe("Test calculateRank", () => { it("average user gets A rank", () => { expect( calculateRank({ - totalRepos: 10, - totalCommits: 500, - contributions: 500, - followers: 50, - prs: 12, - issues: 13, - stargazers: 100, + all_commits: false, + commits: 100, + prs: 50, + issues: 10, + repos: 0, + stars: 100, + followers: 25, }), ).toStrictEqual({ level: "A", score: 50 }); }); - it("more than average user gets A+ rank", () => { + it("average user gets A rank (include_all_commits)", () => { expect( calculateRank({ - totalRepos: 50, - totalCommits: 1500, - contributions: 1500, - followers: 150, + all_commits: true, + commits: 500, prs: 50, - issues: 50, - stargazers: 300, + issues: 10, + repos: 0, + stars: 100, + followers: 25, }), - ).toStrictEqual({ level: "A+", score: 11.458333333333332 }); + ).toStrictEqual({ level: "A", score: 50 }); }); - it("expert user gets S rank", () => { + it("more than average user gets A+ rank", () => { expect( calculateRank({ - totalRepos: 100, - totalCommits: 2000, - contributions: 2000, - followers: 500, + all_commits: false, + commits: 200, prs: 100, - issues: 100, - stargazers: 500, + issues: 20, + repos: 0, + stars: 200, + followers: 50, + }), + ).toStrictEqual({ level: "A+", score: 25 }); + }); + + it("expert user gets S rank", () => { + expect( + calculateRank({ + all_commits: false, + commits: 400, + prs: 200, + issues: 40, + repos: 0, + stars: 400, + followers: 100, }), - ).toStrictEqual({ level: "S", score: 2.685546875 }); + ).toStrictEqual({ level: "S", score: 6.25 }); }); - it("Linus Torvalds gets S+ rank", () => { + it("ezyang gets S+ rank", () => { expect( calculateRank({ - totalRepos: 4, - totalCommits: 20000, - contributions: 20000, - followers: 132000, - prs: 71, - issues: 2, - stargazers: 109100, + all_commits: false, + commits: 1000, + prs: 4000, + issues: 2000, + repos: 0, + stars: 5000, + followers: 2000, }), - ).toStrictEqual({ level: "S+", score: 2.2021209178513677 }); + ).toStrictEqual({ level: "S+", score: 0.012207031250033307 }); }); }); From 8e007fe6f03386089b14d093296ef893da687dbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Rozet?= Date: Mon, 1 May 2023 10:04:20 +0000 Subject: [PATCH 08/13] Tweak weights --- api/index.js | 2 -- docs/readme_fr.md | 13 ---------- readme.md | 14 ----------- src/calculateRank.js | 30 ++++++++++++++--------- src/fetchers/stats-fetcher.js | 2 -- tests/api.test.js | 46 ++++++----------------------------- tests/calculateRank.test.js | 2 +- tests/fetchStats.test.js | 44 +++++++-------------------------- 8 files changed, 36 insertions(+), 117 deletions(-) diff --git a/api/index.js b/api/index.js index 29ff87f9af863..21448f92c50d2 100644 --- a/api/index.js +++ b/api/index.js @@ -19,7 +19,6 @@ export default async (req, res) => { card_width, hide_rank, show_icons, - count_private, include_all_commits, line_height, title_color, @@ -52,7 +51,6 @@ export default async (req, res) => { try { const stats = await fetchStats( username, - parseBoolean(count_private), parseBoolean(include_all_commits), parseArray(exclude_repo), ); diff --git a/docs/readme_fr.md b/docs/readme_fr.md index ce0d3d495cc10..6da4fefd28b2b 100644 --- a/docs/readme_fr.md +++ b/docs/readme_fr.md @@ -90,18 +90,6 @@ Pour masquer des statistiques spécifiques, vous pouvez passer un paramètre de ![Les Stats GitHub de Anurag](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=contribs,prs) ``` -### Ajouter le compte des contributions privées au compte des commits totaux - -Vous pouvez ajouter le compte de toutes vos contributions privées au compte total des engagements en utilisant le paramètre de requête `?count_private=true`. - -_Note: Si vous déployez vous-même ce projet, les contributions privées seront comptées par défaut ; sinon, vous devez choisir de partager les comptes de vos contributions privées._ - -> Options: `&count_private=true` - -```md -![Les Stats GitHub de Anurag](https://github-readme-stats.vercel.app/api?username=anuraghazra&count_private=true) -``` - ### Afficher les icônes Pour activer les icônes, vous pouvez passer `show_icons=true` dans le paramètre de requête, comme ceci : @@ -160,7 +148,6 @@ Vous pouvez fournir plusieurs valeurs (suivie d'une virgule) dans l'option bg_co - `hide_rank` - Masquer le rang _(boolean)_ - `show_icons` - Afficher les icônes _(boolean)_ - `include_all_commits` - Compter le total de commits au lieu de ne compter que les commits de l'année en cours _(boolean)_ -- `count_private` - Compter les commits privés _(boolean)_ - `line_height` - Fixer la hauteur de la ligne entre les textes _(number)_ #### Repo Card Exclusive Options: diff --git a/readme.md b/readme.md index ae18c9e6002c6..ba3ab527f82b3 100644 --- a/readme.md +++ b/readme.md @@ -120,19 +120,6 @@ You can pass a query parameter `&hide=` to hide any specific stats with comma-se ![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&hide=contribs,prs) ``` -### Adding private contributions count to total commits count - -You can add the count of all your private contributions to the total commits count by using the query parameter `&count_private=true`. - -> **Note** -> If you are deploying this project yourself, the private contributions will be counted by default. If you are using the public Vercel instance, you need to choose to [share your private contributions](https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-github-profile/managing-contribution-settings-on-your-profile/showing-your-private-contributions-and-achievements-on-your-profile). - -> Options: `&count_private=true` - -```md -![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&count_private=true) -``` - ### Showing icons To enable icons, you can pass `&show_icons=true` in the query param, like so: @@ -283,7 +270,6 @@ You can provide multiple comma-separated values in the bg_color option to render - `rank_icon` - Shows alternative rank icon (i.e. `github` or `default`). Default: `default`. - `show_icons` - _(boolean)_. Default: `false`. - `include_all_commits` - Count total commits instead of just the current year commits _(boolean)_. Default: `false`. -- `count_private` - Count private commits _(boolean)_. Default: `false`. - `line_height` - Sets the line height between text _(number)_. Default: `25`. - `exclude_repo` - Exclude stars from specified repositories _(Comma-separated values)_. Default: `[] (blank array)`. - `custom_title` - Sets a custom title for the card. Default: ` GitHub Stats`. diff --git a/src/calculateRank.js b/src/calculateRank.js index 28373b624aea5..1830df7589310 100644 --- a/src/calculateRank.js +++ b/src/calculateRank.js @@ -24,23 +24,31 @@ function calculateRank({ stars, followers, }) { - const COMMITS_MEAN = all_commits ? 500 : 100, COMMITS_WEIGHT = 1; - const PRS_MEAN = 50, PRS_WEIGHT = 2; - const ISSUES_MEAN = 10, ISSUES_WEIGHT = 1; - const STARS_MEAN = 100, STARS_WEIGHT = 3; - const FOLLOWERS_MEAN = 25, FOLLOWERS_WEIGHT = 1; + const COMMITS_MEAN = all_commits ? 500 : 100, + COMMITS_WEIGHT = 2; + const PRS_MEAN = 50, + PRS_WEIGHT = 4; + const ISSUES_MEAN = 10, + ISSUES_WEIGHT = 1; + const STARS_MEAN = 100, + STARS_WEIGHT = 6; + const FOLLOWERS_MEAN = 25, + FOLLOWERS_WEIGHT = 1; - const TOTAL_WEIGHT = COMMITS_WEIGHT + - PRS_WEIGHT + ISSUES_WEIGHT + STARS_WEIGHT + FOLLOWERS_WEIGHT; + const TOTAL_WEIGHT = + COMMITS_WEIGHT + + PRS_WEIGHT + + ISSUES_WEIGHT + + STARS_WEIGHT + + FOLLOWERS_WEIGHT; const rank = - ( - COMMITS_WEIGHT * expsf(commits, 1 / COMMITS_MEAN) + + (COMMITS_WEIGHT * expsf(commits, 1 / COMMITS_MEAN) + PRS_WEIGHT * expsf(prs, 1 / PRS_MEAN) + ISSUES_WEIGHT * expsf(issues, 1 / ISSUES_MEAN) + STARS_WEIGHT * expsf(stars, 1 / STARS_MEAN) + - FOLLOWERS_WEIGHT * expsf(followers, 1 / FOLLOWERS_MEAN) - ) / TOTAL_WEIGHT; + FOLLOWERS_WEIGHT * expsf(followers, 1 / FOLLOWERS_MEAN)) / + TOTAL_WEIGHT; const RANK_S_PLUS = 0.025; const RANK_S = 0.1; diff --git a/src/fetchers/stats-fetcher.js b/src/fetchers/stats-fetcher.js index 9824422cb9473..3d6f9f5e7eaae 100644 --- a/src/fetchers/stats-fetcher.js +++ b/src/fetchers/stats-fetcher.js @@ -173,13 +173,11 @@ const totalCommitsFetcher = async (username) => { * Fetch stats for a given username. * * @param {string} username GitHub username. - * @param {boolean} count_private Include private contributions. * @param {boolean} include_all_commits Include all commits. * @returns {Promise} Stats data. */ const fetchStats = async ( username, - count_private = false, include_all_commits = false, exclude_repo = [], ) => { diff --git a/tests/api.test.js b/tests/api.test.js index 461f3e18abb6d..cb3e1418a34eb 100644 --- a/tests/api.test.js +++ b/tests/api.test.js @@ -12,17 +12,18 @@ const stats = { totalCommits: 200, totalIssues: 300, totalPRs: 400, - contributedTo: 500, + contributedTo: 50, rank: null, }; + stats.rank = calculateRank({ - totalCommits: stats.totalCommits, - totalRepos: 1, - followers: 0, - contributions: stats.contributedTo, - stargazers: stats.totalStars, + all_commits: false, + commits: stats.totalCommits, prs: stats.totalPRs, issues: stats.totalIssues, + repos: 1, + stars: stats.totalStars, + followers: 0, }); const data_stats = { @@ -32,7 +33,6 @@ const data_stats = { repositoriesContributedTo: { totalCount: stats.contributedTo }, contributionsCollection: { totalCommitContributions: stats.totalCommits, - restrictedContributionsCount: 100, }, pullRequests: { totalCount: stats.totalPRs }, openIssues: { totalCount: stats.totalIssues }, @@ -229,38 +229,6 @@ describe("Test /api/", () => { } }); - it("should add private contributions", async () => { - const { req, res } = faker( - { - username: "anuraghazra", - count_private: true, - }, - data_stats, - ); - - await api(req, res); - - expect(res.setHeader).toBeCalledWith("Content-Type", "image/svg+xml"); - expect(res.send).toBeCalledWith( - renderStatsCard( - { - ...stats, - totalCommits: stats.totalCommits + 100, - rank: calculateRank({ - totalCommits: stats.totalCommits + 100, - totalRepos: 1, - followers: 0, - contributions: stats.contributedTo, - stargazers: stats.totalStars, - prs: stats.totalPRs, - issues: stats.totalIssues, - }), - }, - {}, - ), - ); - }); - it("should allow changing ring_color", async () => { const { req, res } = faker( { diff --git a/tests/calculateRank.test.js b/tests/calculateRank.test.js index ccd95a50de83f..074ef0b9459d2 100644 --- a/tests/calculateRank.test.js +++ b/tests/calculateRank.test.js @@ -83,6 +83,6 @@ describe("Test calculateRank", () => { stars: 5000, followers: 2000, }), - ).toStrictEqual({ level: "S+", score: 0.012207031250033307 }); + ).toStrictEqual({ level: "S+", score: 0.013950892857180923 }); }); }); diff --git a/tests/fetchStats.test.js b/tests/fetchStats.test.js index db55390d1d13e..4e8f4d8065c42 100644 --- a/tests/fetchStats.test.js +++ b/tests/fetchStats.test.js @@ -10,10 +10,7 @@ const data_stats = { user: { name: "Anurag Hazra", repositoriesContributedTo: { totalCount: 61 }, - contributionsCollection: { - totalCommitContributions: 100, - restrictedContributionsCount: 50, - }, + contributionsCollection: { totalCommitContributions: 100 }, pullRequests: { totalCount: 300 }, openIssues: { totalCount: 100 }, closedIssues: { totalCount: 100 }, @@ -160,38 +157,15 @@ describe("Test fetchStats", () => { ); }); - it("should fetch and add private contributions", async () => { - let stats = await fetchStats("anuraghazra", true); - const rank = calculateRank({ - all_commits: false, - commits: 150, - prs: 300, - issues: 200, - repos: 5, - stars: 300, - followers: 100, - }); - - expect(stats).toStrictEqual({ - contributedTo: 61, - name: "Anurag Hazra", - totalCommits: 150, - totalIssues: 200, - totalPRs: 300, - totalStars: 300, - rank, - }); - }); - it("should fetch total commits", async () => { mock .onGet("https://api.github.com/search/commits?q=author:anuraghazra") .reply(200, { total_count: 1000 }); - let stats = await fetchStats("anuraghazra", true, true); + let stats = await fetchStats("anuraghazra", true); const rank = calculateRank({ - all_commits: false, - commits: 1050, + all_commits: true, + commits: 1000, prs: 300, issues: 200, repos: 5, @@ -202,7 +176,7 @@ describe("Test fetchStats", () => { expect(stats).toStrictEqual({ contributedTo: 61, name: "Anurag Hazra", - totalCommits: 1050, + totalCommits: 1000, totalIssues: 200, totalPRs: 300, totalStars: 300, @@ -215,10 +189,10 @@ describe("Test fetchStats", () => { .onGet("https://api.github.com/search/commits?q=author:anuraghazra") .reply(200, { total_count: 1000 }); - let stats = await fetchStats("anuraghazra", true, true, ["test-repo-1"]); + let stats = await fetchStats("anuraghazra", true, ["test-repo-1"]); const rank = calculateRank({ - all_commits: false, - commits: 1050, + all_commits: true, + commits: 1000, prs: 300, issues: 200, repos: 5, @@ -229,7 +203,7 @@ describe("Test fetchStats", () => { expect(stats).toStrictEqual({ contributedTo: 61, name: "Anurag Hazra", - totalCommits: 1050, + totalCommits: 1000, totalIssues: 200, totalPRs: 300, totalStars: 200, From c251dba21f42eebdd12d178696d693c7642bbdb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Rozet?= Date: Thu, 18 May 2023 11:17:30 +0000 Subject: [PATCH 09/13] Add count_private back --- api/index.js | 2 ++ docs/readme_fr.md | 1 + readme.md | 1 + src/fetchers/stats-fetcher.js | 2 ++ tests/api.test.js | 1 + tests/fetchStats.test.js | 9 ++++++--- 6 files changed, 13 insertions(+), 3 deletions(-) diff --git a/api/index.js b/api/index.js index 21448f92c50d2..29ff87f9af863 100644 --- a/api/index.js +++ b/api/index.js @@ -19,6 +19,7 @@ export default async (req, res) => { card_width, hide_rank, show_icons, + count_private, include_all_commits, line_height, title_color, @@ -51,6 +52,7 @@ export default async (req, res) => { try { const stats = await fetchStats( username, + parseBoolean(count_private), parseBoolean(include_all_commits), parseArray(exclude_repo), ); diff --git a/docs/readme_fr.md b/docs/readme_fr.md index 6da4fefd28b2b..ba9d8da3188bc 100644 --- a/docs/readme_fr.md +++ b/docs/readme_fr.md @@ -148,6 +148,7 @@ Vous pouvez fournir plusieurs valeurs (suivie d'une virgule) dans l'option bg_co - `hide_rank` - Masquer le rang _(boolean)_ - `show_icons` - Afficher les icônes _(boolean)_ - `include_all_commits` - Compter le total de commits au lieu de ne compter que les commits de l'année en cours _(boolean)_ +- `count_private` - Compter les contributions privées _(boolean)_ - `line_height` - Fixer la hauteur de la ligne entre les textes _(number)_ #### Repo Card Exclusive Options: diff --git a/readme.md b/readme.md index ba3ab527f82b3..45fba4a3f14ac 100644 --- a/readme.md +++ b/readme.md @@ -270,6 +270,7 @@ You can provide multiple comma-separated values in the bg_color option to render - `rank_icon` - Shows alternative rank icon (i.e. `github` or `default`). Default: `default`. - `show_icons` - _(boolean)_. Default: `false`. - `include_all_commits` - Count total commits instead of just the current year commits _(boolean)_. Default: `false`. +- `count_private` - Count private contributions _(boolean)_. Default: `false`. - `line_height` - Sets the line height between text _(number)_. Default: `25`. - `exclude_repo` - Exclude stars from specified repositories _(Comma-separated values)_. Default: `[] (blank array)`. - `custom_title` - Sets a custom title for the card. Default: ` GitHub Stats`. diff --git a/src/fetchers/stats-fetcher.js b/src/fetchers/stats-fetcher.js index 3d6f9f5e7eaae..aff7fcbde9804 100644 --- a/src/fetchers/stats-fetcher.js +++ b/src/fetchers/stats-fetcher.js @@ -173,11 +173,13 @@ const totalCommitsFetcher = async (username) => { * Fetch stats for a given username. * * @param {string} username GitHub username. + * @param {boolean} count_private Include private contributions. * @param {boolean} include_all_commits Include all commits. * @returns {Promise} Stats data. */ const fetchStats = async ( username, + count_private = false, // unused include_all_commits = false, exclude_repo = [], ) => { diff --git a/tests/api.test.js b/tests/api.test.js index cb3e1418a34eb..0f82de5e6bda1 100644 --- a/tests/api.test.js +++ b/tests/api.test.js @@ -33,6 +33,7 @@ const data_stats = { repositoriesContributedTo: { totalCount: stats.contributedTo }, contributionsCollection: { totalCommitContributions: stats.totalCommits, + restrictedContributionsCount: 100, }, pullRequests: { totalCount: stats.totalPRs }, openIssues: { totalCount: stats.totalIssues }, diff --git a/tests/fetchStats.test.js b/tests/fetchStats.test.js index 4e8f4d8065c42..879173dfb44d6 100644 --- a/tests/fetchStats.test.js +++ b/tests/fetchStats.test.js @@ -10,7 +10,10 @@ const data_stats = { user: { name: "Anurag Hazra", repositoriesContributedTo: { totalCount: 61 }, - contributionsCollection: { totalCommitContributions: 100 }, + contributionsCollection: { + totalCommitContributions: 100, + restrictedContributionsCount: 50, + }, pullRequests: { totalCount: 300 }, openIssues: { totalCount: 100 }, closedIssues: { totalCount: 100 }, @@ -162,7 +165,7 @@ describe("Test fetchStats", () => { .onGet("https://api.github.com/search/commits?q=author:anuraghazra") .reply(200, { total_count: 1000 }); - let stats = await fetchStats("anuraghazra", true); + let stats = await fetchStats("anuraghazra", true, true); const rank = calculateRank({ all_commits: true, commits: 1000, @@ -189,7 +192,7 @@ describe("Test fetchStats", () => { .onGet("https://api.github.com/search/commits?q=author:anuraghazra") .reply(200, { total_count: 1000 }); - let stats = await fetchStats("anuraghazra", true, ["test-repo-1"]); + let stats = await fetchStats("anuraghazra", true, true, ["test-repo-1"]); const rank = calculateRank({ all_commits: true, commits: 1000, From 0917e03fbba3c500305366aef0cc7ed710208da1 Mon Sep 17 00:00:00 2001 From: Rick Staa Date: Fri, 19 May 2023 08:51:58 +0200 Subject: [PATCH 10/13] fix: enable 'count_private' again --- src/fetchers/stats-fetcher.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/fetchers/stats-fetcher.js b/src/fetchers/stats-fetcher.js index aff7fcbde9804..1163238723dd7 100644 --- a/src/fetchers/stats-fetcher.js +++ b/src/fetchers/stats-fetcher.js @@ -179,7 +179,7 @@ const totalCommitsFetcher = async (username) => { */ const fetchStats = async ( username, - count_private = false, // unused + count_private = false, include_all_commits = false, exclude_repo = [], ) => { @@ -221,6 +221,7 @@ const fetchStats = async ( const user = res.data.data.user; stats.name = user.name || user.login; + stats.totalCommits = user.contributionsCollection.totalCommitContributions; // populate repoToHide map for quick lookup // while filtering out @@ -231,10 +232,15 @@ const fetchStats = async ( }); } + // Use include_all_commits fetch all commit using the REST API. if (include_all_commits) { stats.totalCommits = await totalCommitsFetcher(username); - } else { - stats.totalCommits = user.contributionsCollection.totalCommitContributions; + } + + // if count_private then add private contributions to totalCommits. + if (count_private) { + stats.totalCommits += + user.contributionsCollection.restrictedContributionsCount; } stats.totalPRs = user.pullRequests.totalCount; From 7164451e597d8f7f772328c5a34874c32d9c5569 Mon Sep 17 00:00:00 2001 From: Rick Staa Date: Fri, 19 May 2023 09:11:55 +0200 Subject: [PATCH 11/13] test: fix tests --- tests/fetchStats.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/fetchStats.test.js b/tests/fetchStats.test.js index 879173dfb44d6..870dd3d1c287d 100644 --- a/tests/fetchStats.test.js +++ b/tests/fetchStats.test.js @@ -165,7 +165,7 @@ describe("Test fetchStats", () => { .onGet("https://api.github.com/search/commits?q=author:anuraghazra") .reply(200, { total_count: 1000 }); - let stats = await fetchStats("anuraghazra", true, true); + let stats = await fetchStats("anuraghazra", false, true); const rank = calculateRank({ all_commits: true, commits: 1000, @@ -192,7 +192,7 @@ describe("Test fetchStats", () => { .onGet("https://api.github.com/search/commits?q=author:anuraghazra") .reply(200, { total_count: 1000 }); - let stats = await fetchStats("anuraghazra", true, true, ["test-repo-1"]); + let stats = await fetchStats("anuraghazra", false, true, ["test-repo-1"]); const rank = calculateRank({ all_commits: true, commits: 1000, From 8d8d972ec6aac3ec5112dc37ff3c41bffe491a17 Mon Sep 17 00:00:00 2001 From: Rick Staa Date: Fri, 19 May 2023 09:23:06 +0200 Subject: [PATCH 12/13] refactor: improve code formatting --- src/fetchers/stats-fetcher.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fetchers/stats-fetcher.js b/src/fetchers/stats-fetcher.js index 1163238723dd7..17f1add66e1cd 100644 --- a/src/fetchers/stats-fetcher.js +++ b/src/fetchers/stats-fetcher.js @@ -236,7 +236,7 @@ const fetchStats = async ( if (include_all_commits) { stats.totalCommits = await totalCommitsFetcher(username); } - + // if count_private then add private contributions to totalCommits. if (count_private) { stats.totalCommits += From 53005a5849ec8e4ad13edbf275355e70338aa24f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Rozet?= Date: Fri, 19 May 2023 08:50:18 +0000 Subject: [PATCH 13/13] Higher targets --- src/calculateRank.js | 10 +++++----- src/fetchers/stats-fetcher.js | 22 ++++++++-------------- tests/calculateRank.test.js | 26 +++++++++++++------------- 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/src/calculateRank.js b/src/calculateRank.js index 1830df7589310..7648ad412ed67 100644 --- a/src/calculateRank.js +++ b/src/calculateRank.js @@ -24,14 +24,14 @@ function calculateRank({ stars, followers, }) { - const COMMITS_MEAN = all_commits ? 500 : 100, + const COMMITS_MEAN = all_commits ? 1000 : 250, COMMITS_WEIGHT = 2; const PRS_MEAN = 50, - PRS_WEIGHT = 4; - const ISSUES_MEAN = 10, + PRS_WEIGHT = 3; + const ISSUES_MEAN = 25, ISSUES_WEIGHT = 1; - const STARS_MEAN = 100, - STARS_WEIGHT = 6; + const STARS_MEAN = 250, + STARS_WEIGHT = 4; const FOLLOWERS_MEAN = 25, FOLLOWERS_WEIGHT = 1; diff --git a/src/fetchers/stats-fetcher.js b/src/fetchers/stats-fetcher.js index 17f1add66e1cd..8fecffa466f8d 100644 --- a/src/fetchers/stats-fetcher.js +++ b/src/fetchers/stats-fetcher.js @@ -221,23 +221,15 @@ const fetchStats = async ( const user = res.data.data.user; stats.name = user.name || user.login; - stats.totalCommits = user.contributionsCollection.totalCommitContributions; - // populate repoToHide map for quick lookup - // while filtering out - let repoToHide = {}; - if (exclude_repo) { - exclude_repo.forEach((repoName) => { - repoToHide[repoName] = true; - }); - } - - // Use include_all_commits fetch all commit using the REST API. + // if include_all_commits, fetch all commits using the REST API. if (include_all_commits) { stats.totalCommits = await totalCommitsFetcher(username); + } else { + stats.totalCommits = user.contributionsCollection.totalCommitContributions; } - // if count_private then add private contributions to totalCommits. + // if count_private, add private contributions to totalCommits. if (count_private) { stats.totalCommits += user.contributionsCollection.restrictedContributionsCount; @@ -247,10 +239,12 @@ const fetchStats = async ( stats.totalIssues = user.openIssues.totalCount + user.closedIssues.totalCount; stats.contributedTo = user.repositoriesContributedTo.totalCount; - // Retrieve stars while filtering out repositories to be hidden + // Retrieve stars while filtering out repositories to be hidden. + let repoToHide = new Set(exclude_repo); + stats.totalStars = user.repositories.nodes .filter((data) => { - return !repoToHide[data.name]; + return !repoToHide.has(data.name); }) .reduce((prev, curr) => { return prev + curr.stargazers.totalCount; diff --git a/tests/calculateRank.test.js b/tests/calculateRank.test.js index 074ef0b9459d2..3bfd7f4376248 100644 --- a/tests/calculateRank.test.js +++ b/tests/calculateRank.test.js @@ -20,11 +20,11 @@ describe("Test calculateRank", () => { expect( calculateRank({ all_commits: false, - commits: 100, + commits: 250, prs: 50, - issues: 10, + issues: 25, repos: 0, - stars: 100, + stars: 250, followers: 25, }), ).toStrictEqual({ level: "A", score: 50 }); @@ -34,11 +34,11 @@ describe("Test calculateRank", () => { expect( calculateRank({ all_commits: true, - commits: 500, + commits: 1000, prs: 50, - issues: 10, + issues: 25, repos: 0, - stars: 100, + stars: 250, followers: 25, }), ).toStrictEqual({ level: "A", score: 50 }); @@ -48,11 +48,11 @@ describe("Test calculateRank", () => { expect( calculateRank({ all_commits: false, - commits: 200, + commits: 500, prs: 100, - issues: 20, + issues: 50, repos: 0, - stars: 200, + stars: 500, followers: 50, }), ).toStrictEqual({ level: "A+", score: 25 }); @@ -62,11 +62,11 @@ describe("Test calculateRank", () => { expect( calculateRank({ all_commits: false, - commits: 400, + commits: 1000, prs: 200, - issues: 40, + issues: 100, repos: 0, - stars: 400, + stars: 1000, followers: 100, }), ).toStrictEqual({ level: "S", score: 6.25 }); @@ -83,6 +83,6 @@ describe("Test calculateRank", () => { stars: 5000, followers: 2000, }), - ).toStrictEqual({ level: "S+", score: 0.013950892857180923 }); + ).toStrictEqual({ level: "S+", score: 1.1363983154296875 }); }); });