Browse Source

add 得分

fish 8 months ago
parent
commit
549453aa1f
4 changed files with 153 additions and 1 deletions
  1. 29 1
      README.md
  2. 87 0
      c.js
  3. 22 0
      index.js
  4. 15 0
      package.json

+ 29 - 1
README.md

@@ -1,3 +1,31 @@
 # github_score
 
-github 得分公式
+github 得分公式:
+
+$$
+rank=1 - \frac{1}{W} \sum_{i=1}^{n} w_i \cdot f_i \left( \frac{x_i}{m_i} \right)
+$$
+其中:
+
+-   WWW 是总权重
+-   wiw_iwi 是第 iii 个参数的权重
+-   fif_ifi 是第 iii 个参数的得分函数(`exponential_cdf` 或 `log_normal_cdf`)
+-   xix_ixi 是第 iii 个参数的实际值
+-   mim_imi 是第 iii 个参数的中位数
+
+通过这个公式计算出总得分(`rank`),然后根据 `rank` 值确定用户的等级。
+
+其中:
+(`COMMITS_WEIGHT`、`PRS_WEIGHT`、`ISSUES_WEIGHT`、`REVIEWS_WEIGHT`、`STARS_WEIGHT`、`FOLLOWERS_WEIGHT`),这些权重分别是:2、3、1、1、4、1。
+
+
+https://github-readme-stats.vercel.app/api?username=jianboy&hide_title=true&hide_border=true&show_icons=true&include_all_commits=true&count_private=true&line_height=21&text_color=000&icon_color=000&bg_color=0,ea6161,ffc64d,fffc4d,52fa5a&theme=graywhite
+
+
+## License
+
+## Reference
+
+
+https://github.com/anuraghazra/github-readme-stats/blob/master/src/calculateRank.js
+

+ 87 - 0
c.js

@@ -0,0 +1,87 @@
+/**
+ * Calculates the exponential cdf.
+ *
+ * @param {number} x The value.
+ * @returns {number} The exponential cdf.
+ */
+function exponential_cdf(x) {
+    return 1 - 2 ** -x;
+}
+
+/**
+ * Calculates the log normal cdf.
+ *
+ * @param {number} x The value.
+ * @returns {number} The log normal cdf.
+ */
+function log_normal_cdf(x) {
+    // approximation
+    return x / (1 + 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.reviews The number of reviews.
+ * @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, percentile: number}}} The users rank.
+ */
+function calculateRank({
+    all_commits,
+    commits,
+    prs,
+    issues,
+    reviews,
+    // eslint-disable-next-line no-unused-vars
+    repos, // unused
+    stars,
+    followers,
+}) {
+    const COMMITS_MEDIAN = all_commits ? 1000 : 250,
+        COMMITS_WEIGHT = 2;
+    const PRS_MEDIAN = 50,
+        PRS_WEIGHT = 3;
+    const ISSUES_MEDIAN = 25,
+        ISSUES_WEIGHT = 1;
+    const REVIEWS_MEDIAN = 2,
+        REVIEWS_WEIGHT = 1;
+    const STARS_MEDIAN = 50,
+        STARS_WEIGHT = 4;
+    const FOLLOWERS_MEDIAN = 10,
+        FOLLOWERS_WEIGHT = 1;
+
+    const TOTAL_WEIGHT =
+        COMMITS_WEIGHT +
+        PRS_WEIGHT +
+        ISSUES_WEIGHT +
+        REVIEWS_WEIGHT +
+        STARS_WEIGHT +
+        FOLLOWERS_WEIGHT;
+
+    const THRESHOLDS = [1, 12.5, 25, 37.5, 50, 62.5, 75, 87.5, 100];
+    const LEVELS = ["S", "A+", "A", "A-", "B+", "B", "B-", "C+", "C"];
+
+    const rank =
+        1 -
+        (COMMITS_WEIGHT * exponential_cdf(commits / COMMITS_MEDIAN) +
+            PRS_WEIGHT * exponential_cdf(prs / PRS_MEDIAN) +
+            ISSUES_WEIGHT * exponential_cdf(issues / ISSUES_MEDIAN) +
+            REVIEWS_WEIGHT * exponential_cdf(reviews / REVIEWS_MEDIAN) +
+            STARS_WEIGHT * log_normal_cdf(stars / STARS_MEDIAN) +
+            FOLLOWERS_WEIGHT * log_normal_cdf(followers / FOLLOWERS_MEDIAN)) /
+        TOTAL_WEIGHT;
+
+    const level = LEVELS[THRESHOLDS.findIndex((t) => rank * 100 <= t)];
+
+    return { level, percentile: rank * 100 };
+}
+
+module.exports = { calculateRank };
+// export default calculateRank;

+ 22 - 0
index.js

@@ -0,0 +1,22 @@
+// 导入 calculateRank 函数
+// import { calculateRank } from './c.js'; // js不支持es6语法
+const { calculateRank } = require('./c.js'); // 替换为实际文件路径
+
+// 定义输入参数对象
+const params = {
+    all_commits: true, // 示例值,可以是 true 或 false
+    commits: 19000,      // 示例提交次数
+    prs: 778,           // 示例 PR 数量
+    issues: 15,        // 示例问题数量
+    reviews: 50,        // 示例评审数量
+    repos: 1,         // 示例仓库数量(未使用)
+    stars: 71000,        // 示例星标数量
+    followers: 12000      // 示例关注者数量
+};
+
+// 调用 calculateRank 函数
+const result = calculateRank(params);
+
+// 输出结果
+console.log(`Level: ${result.level}`);
+console.log(`Percentile: ${result.percentile}`);

+ 15 - 0
package.json

@@ -0,0 +1,15 @@
+{
+  "name": "github_score",
+  "version": "1.0.0",
+  "description": "",
+  "main": "index.js",
+  "directories": {
+    "doc": "docs",
+    "test": "test"
+  },
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "author": "",
+  "license": "ISC"
+}