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] 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 1830df75..7648ad41 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 17f1add6..8fecffa4 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 074ef0b9..3bfd7f43 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 }); }); });