From 5c699563967eb6d5bcffd5543afd742fc45ec511 Mon Sep 17 00:00:00 2001 From: Zhao Fuhao <2926857163@qq.com> Date: Fri, 30 May 2025 15:32:15 +0800 Subject: [PATCH 1/4] finished report-captcha.py --- main.py | 0 report-crmeb.py | 114 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 main.py create mode 100644 report-crmeb.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..e69de29 diff --git a/report-crmeb.py b/report-crmeb.py new file mode 100644 index 0000000..341b3e0 --- /dev/null +++ b/report-crmeb.py @@ -0,0 +1,114 @@ +from git import Repo +from pathlib import Path +from datetime import datetime +import ast # 用于安全地将字符串转换为Python字典 +import numpy as np # 用于数值计算和统计分析 + +# 设置项目信息和链接 +gitee_link = "https://gitee.com/" +repo_name = "CRMEB" +repo_link = gitee_link + "zhongBangKeJi/CRMEB" +commits_link = gitee_link + "ZhongBangKeJi/CRMEB/commits/master" +authors_link = gitee_link + "ZhongBangKeJi/CRMEB/contributors" +branches_link = gitee_link + "ZhongBangKeJi/CRMEB/branches" +branch_link = gitee_link + "ZhongBangKeJi/CRMEB/tree/" + +# 初始化Markdown报告 +md = f"# {repo_name} Project Data Analysis\n\n" +md += "---\n\n" + +# 克隆或加载本地仓库(已存在则直接加载) +if Path(repo_name).exists(): + repo = Repo(repo_name) +else: + print("Cloning Repo...") + repo = Repo.clone_from(repo_link, repo_name) + print("Finished Cloning!") + +# 项目基本信息 +repo_commits = list(repo.iter_commits()) +first_commit = repo_commits[-1] +latest_commit = repo_commits[0] +start_date = datetime.fromtimestamp(first_commit.authored_date) +latest_date = datetime.fromtimestamp(latest_commit.authored_date) + +# 添加项目概览到报告 +md += f"**Start Date:** {start_date}\n\n" +md += f"**Latest Update:** {latest_date}\n\n" +md += f"[**Commits:** {len(repo_commits)}]({commits_link})\n\n" + +# 分支信息处理 +gitee = repo.remotes[0] +gitee_branches = [ + ref.name[7:] for ref in gitee.refs if ref.name != "origin/HEAD" +] +gitee_branches.remove("master") +repo_branches = ["master"] + gitee_branches +md += f"[**Branches:** {len(repo_branches)}]({branches_link})\n\n" + +# 作者贡献统计 +author_data = {} +for commit in repo_commits: + author = commit.author.name + author_data[author] = author_data.get(author, 0) + 1 + +author_data = sorted(author_data.items(), key=lambda x: x[1], reverse=True) +md += f"[**Authors:** {len(author_data)}]({authors_link})\n\n" + +# 添加分支列表到报告 +md += "## Branches\n\n" +for branch in repo_branches: + md += f"- [{branch}]({branch_link + branch})\n\n" + +# 添加作者排行榜到报告 +md += "## Top 10 Authors\n\n" +for i in range(min(10, len(author_data))): + author = author_data[i] + name = author[0].replace(" ", "") + commits = author[1] + md += f"{i + 1}. [{name}]({gitee_link + name}): {commits} commits\n\n" + +# -------------------- 新增:提交统计分析 -------------------- +# 初始化数据存储列表 +lines_changed = [] # 每次提交修改的行数 +files_changed = [] # 每次提交修改的文件数 +commit_stats = [] # 提交统计原始数据 + +# 从缓存文件读取或重新收集提交统计数据 +if Path("commit_stats.txt").exists(): + print("READING FROM CACHE") + with open("commit_stats.txt", "r") as file: + commit_stats = file.readlines() +else: + print("WRITING TO CACHE") + with open("commit_stats.txt", "w") as file: + for commit in repo_commits: + stats = str(commit.stats.total) # 获取提交的统计信息 + commit_stats.append(stats) + file.write(f"{stats}\n") # 保存到缓存文件避免重复计算 + +# 解析统计数据 +for stats in commit_stats: + stat = ast.literal_eval(stats) # 将字符串安全转换为字典 + lines_changed.append(stat['lines']) + files_changed.append(stat['files']) + +# 添加提交统计分析到报告 +md += "## Commit Stats\n\n" + +# 使用NumPy计算统计指标(转换为整数便于阅读) +lines_changed = np.array(lines_changed) +files_changed = np.array(files_changed) +mean_lines_changed = int(np.mean(lines_changed)) +median_lines_changed = int(np.median(lines_changed)) +mean_files_changed = int(np.mean(files_changed)) +median_files_changed = int(np.median(files_changed)) + +# 将统计结果添加到报告 +md += f"**Average Lines Changed / Commit:** {mean_lines_changed}\n\n" +md += f"**Median Lines Changed / Commit:** {median_lines_changed}\n\n" +md += f"**Average Files Changed / Commit:** {mean_files_changed}\n\n" +md += f"**Median Files Changed / Commit:** {median_files_changed}\n\n" + +# 写入Markdown文件 +Path("report-crmeb.md").write_text(md, "UTF-8") \ No newline at end of file -- Gitee From b2a410e3524baf8a8347ad5c50ec65b24e3dfb6d Mon Sep 17 00:00:00 2001 From: Zhao Fuhao <2926857163@qq.com> Date: Fri, 30 May 2025 07:46:05 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20main?= =?UTF-8?q?.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 main.py diff --git a/main.py b/main.py deleted file mode 100644 index e69de29..0000000 -- Gitee From 971f1c43dc145762e4d498ee25bd0b254e204164 Mon Sep 17 00:00:00 2001 From: Zhao Fuhao <2926857163@qq.com> Date: Fri, 30 May 2025 15:54:18 +0800 Subject: [PATCH 3/4] finished report-crmeb.md --- report-crmeb.md | 86 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 report-crmeb.md diff --git a/report-crmeb.md b/report-crmeb.md new file mode 100644 index 0000000..113e67e --- /dev/null +++ b/report-crmeb.md @@ -0,0 +1,86 @@ +# CRMEB Project Data Analysis + +--- + +**Start Date:** 2018-08-22 14:58:30 + +**Latest Update:** 2025-05-28 14:48:46 + +[**Commits:** 3824](https://gitee.com/ZhongBangKeJi/CRMEB/commits/master) + +[**Branches:** 19](https://gitee.com/ZhongBangKeJi/CRMEB/branches) + +[**Authors:** 40](https://gitee.com/ZhongBangKeJi/CRMEB/contributors) + +## Branches + +- [master](https://gitee.com/ZhongBangKeJi/CRMEB/tree/master) + +- [3.2](https://gitee.com/ZhongBangKeJi/CRMEB/tree/3.2) + +- [develop](https://gitee.com/ZhongBangKeJi/CRMEB/tree/develop) + +- [release](https://gitee.com/ZhongBangKeJi/CRMEB/tree/release) + +- [v2.5](https://gitee.com/ZhongBangKeJi/CRMEB/tree/v2.5) + +- [v2.6](https://gitee.com/ZhongBangKeJi/CRMEB/tree/v2.6) + +- [v3.0](https://gitee.com/ZhongBangKeJi/CRMEB/tree/v3.0) + +- [v3.1.0](https://gitee.com/ZhongBangKeJi/CRMEB/tree/v3.1.0) + +- [v3.2.9](https://gitee.com/ZhongBangKeJi/CRMEB/tree/v3.2.9) + +- [v4.1.0](https://gitee.com/ZhongBangKeJi/CRMEB/tree/v4.1.0) + +- [v4.3.0](https://gitee.com/ZhongBangKeJi/CRMEB/tree/v4.3.0) + +- [v4.4.0](https://gitee.com/ZhongBangKeJi/CRMEB/tree/v4.4.0) + +- [v4.5.0dev](https://gitee.com/ZhongBangKeJi/CRMEB/tree/v4.5.0dev) + +- [v4.6.0](https://gitee.com/ZhongBangKeJi/CRMEB/tree/v4.6.0) + +- [v4.7.0dev](https://gitee.com/ZhongBangKeJi/CRMEB/tree/v4.7.0dev) + +- [v5.0.0dev](https://gitee.com/ZhongBangKeJi/CRMEB/tree/v5.0.0dev) + +- [v5.1.0dev](https://gitee.com/ZhongBangKeJi/CRMEB/tree/v5.1.0dev) + +- [v5.2.0dev](https://gitee.com/ZhongBangKeJi/CRMEB/tree/v5.2.0dev) + +- [v5.2.2](https://gitee.com/ZhongBangKeJi/CRMEB/tree/v5.2.2) + +## Top 10 Authors + +1. [evoxwht](https://gitee.com/evoxwht): 803 commits + +2. [From-wh](https://gitee.com/From-wh): 697 commits + +3. [sugar1569](https://gitee.com/sugar1569): 623 commits + +4. [吴昊天](https://gitee.com/吴昊天): 580 commits + +5. [liaofei](https://gitee.com/liaofei): 469 commits + +6. [聆听](https://gitee.com/聆听): 215 commits + +7. [xurongyao](https://gitee.com/xurongyao): 194 commits + +8. [Gosowong](https://gitee.com/Gosowong): 66 commits + +9. [wuhaotian](https://gitee.com/wuhaotian): 49 commits + +10. [等风来](https://gitee.com/等风来): 42 commits + +## Commit Stats + +**Average Lines Changed / Commit:** 5922 + +**Median Lines Changed / Commit:** 10 + +**Average Files Changed / Commit:** 48 + +**Median Files Changed / Commit:** 1 + -- Gitee From 0ef5f291643a36b48dcd6871fad1f9490e89dd45 Mon Sep 17 00:00:00 2001 From: Zhao Fuhao <2926857163@qq.com> Date: Fri, 30 May 2025 15:55:08 +0800 Subject: [PATCH 4/4] finished report-crmeb.py --- report-crmeb.py | 1 + 1 file changed, 1 insertion(+) diff --git a/report-crmeb.py b/report-crmeb.py index 341b3e0..7aedd58 100644 --- a/report-crmeb.py +++ b/report-crmeb.py @@ -87,6 +87,7 @@ else: commit_stats.append(stats) file.write(f"{stats}\n") # 保存到缓存文件避免重复计算 + # 解析统计数据 for stats in commit_stats: stat = ast.literal_eval(stats) # 将字符串安全转换为字典 -- Gitee