forked from mirrored/github-readme-stats
Separate PRs and issues
This commit is contained in:
+19
-20
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
+51
-37
@@ -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,13 +19,27 @@ 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("average user gets A rank (include_all_commits)", () => {
|
||||
expect(
|
||||
calculateRank({
|
||||
all_commits: true,
|
||||
commits: 500,
|
||||
prs: 50,
|
||||
issues: 10,
|
||||
repos: 0,
|
||||
stars: 100,
|
||||
followers: 25,
|
||||
}),
|
||||
).toStrictEqual({ level: "A", score: 50 });
|
||||
});
|
||||
@@ -33,42 +47,42 @@ describe("Test calculateRank", () => {
|
||||
it("more than average user gets A+ rank", () => {
|
||||
expect(
|
||||
calculateRank({
|
||||
totalRepos: 50,
|
||||
totalCommits: 1500,
|
||||
contributions: 1500,
|
||||
followers: 150,
|
||||
prs: 50,
|
||||
issues: 50,
|
||||
stargazers: 300,
|
||||
all_commits: false,
|
||||
commits: 200,
|
||||
prs: 100,
|
||||
issues: 20,
|
||||
repos: 0,
|
||||
stars: 200,
|
||||
followers: 50,
|
||||
}),
|
||||
).toStrictEqual({ level: "A+", score: 11.458333333333332 });
|
||||
).toStrictEqual({ level: "A+", score: 25 });
|
||||
});
|
||||
|
||||
it("expert user gets S rank", () => {
|
||||
expect(
|
||||
calculateRank({
|
||||
totalRepos: 100,
|
||||
totalCommits: 2000,
|
||||
contributions: 2000,
|
||||
followers: 500,
|
||||
prs: 100,
|
||||
issues: 100,
|
||||
stargazers: 500,
|
||||
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 });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user