Higher targets

This commit is contained in:
François Rozet
2023-05-19 08:50:18 +00:00
parent 8d8d972ec6
commit 53005a5849
3 changed files with 26 additions and 32 deletions
+5 -5
View File
@@ -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;
+8 -14
View File
@@ -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;
+13 -13
View File
@@ -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 });
});
});