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] 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 29ff87f9..21448f92 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 ce0d3d49..6da4fefd 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 ae18c9e6..ba3ab527 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 28373b62..1830df75 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 9824422c..3d6f9f5e 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 461f3e18..cb3e1418 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 ccd95a50..074ef0b9 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 db55390d..4e8f4d80 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,