mirror of
https://github.com/System-End/github-readme-stats.git
synced 2026-04-20 00:35:23 +00:00
* Revise rank calculation * Replace contributions by commits * Lower average stats and S+ threshold * Fix calculateRank.test.js Missing key in dictionary constructor Co-authored-by: Rick Staa <rick.staa@outlook.com> * refactor: run prettier * feat: change star weight to 0.75 * Separate PRs and issues * Tweak weights * Add count_private back * fix: enable 'count_private' again * test: fix tests * refactor: improve code formatting * Higher targets --------- Co-authored-by: Rick Staa <rick.staa@outlook.com>
72 lines
1.9 KiB
JavaScript
72 lines
1.9 KiB
JavaScript
function expsf(x, lambda = 1) {
|
|
return 2 ** (-lambda * x);
|
|
}
|
|
|
|
/**
|
|
* Calculates the users rank.
|
|
*
|
|
* @param {object} params Parameters on which the user's rank depends.
|
|
* @param {boolean} params.all_commits Whether `include_all_commits` was used.
|
|
* @param {number} params.commits Number of commits.
|
|
* @param {number} params.prs The number of pull requests.
|
|
* @param {number} params.issues The number of issues.
|
|
* @param {number} params.repos Total number of repos.
|
|
* @param {number} params.stars The number of stars.
|
|
* @param {number} params.followers The number of followers.
|
|
* @returns {{level: string, score: number}}} The users rank.
|
|
*/
|
|
function calculateRank({
|
|
all_commits,
|
|
commits,
|
|
prs,
|
|
issues,
|
|
repos, // unused
|
|
stars,
|
|
followers,
|
|
}) {
|
|
const COMMITS_MEAN = all_commits ? 1000 : 250,
|
|
COMMITS_WEIGHT = 2;
|
|
const PRS_MEAN = 50,
|
|
PRS_WEIGHT = 3;
|
|
const ISSUES_MEAN = 25,
|
|
ISSUES_WEIGHT = 1;
|
|
const STARS_MEAN = 250,
|
|
STARS_WEIGHT = 4;
|
|
const FOLLOWERS_MEAN = 25,
|
|
FOLLOWERS_WEIGHT = 1;
|
|
|
|
const TOTAL_WEIGHT =
|
|
COMMITS_WEIGHT +
|
|
PRS_WEIGHT +
|
|
ISSUES_WEIGHT +
|
|
STARS_WEIGHT +
|
|
FOLLOWERS_WEIGHT;
|
|
|
|
const rank =
|
|
(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;
|
|
const RANK_A_PLUS = 0.25;
|
|
const RANK_A = 0.5;
|
|
const RANK_B_PLUS = 0.75;
|
|
|
|
const level = (() => {
|
|
if (rank <= RANK_S_PLUS) return "S+";
|
|
if (rank <= RANK_S) return "S";
|
|
if (rank <= RANK_A_PLUS) return "A+";
|
|
if (rank <= RANK_A) return "A";
|
|
if (rank <= RANK_B_PLUS) return "B+";
|
|
return "B";
|
|
})();
|
|
|
|
return { level, score: rank * 100 };
|
|
}
|
|
|
|
export { calculateRank };
|
|
export default calculateRank;
|