mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
feat(processor): fix contributions classification + removed unnecessary tag
This commit is contained in:
+60
-37
@@ -340,59 +340,82 @@ def _compute_collaborators_from_events(github_data: dict) -> list[CollaboratorDa
|
|||||||
|
|
||||||
|
|
||||||
def compute_focus(github_data: dict) -> list[FocusCategory]:
|
def compute_focus(github_data: dict) -> list[FocusCategory]:
|
||||||
"""Classify commits into focus categories based on repo languages and activity."""
|
"""Classify contributions into focus categories based on repo languages weighted by activity."""
|
||||||
repos = github_data["repos"]
|
repos = github_data["repos"]
|
||||||
events = github_data["events"]
|
total_contributions = github_data.get("recent_commits", 0) # Last 6 months
|
||||||
|
|
||||||
|
# Map languages to focus categories (languages can belong to multiple categories)
|
||||||
lang_to_focus = {
|
lang_to_focus = {
|
||||||
"Python": "Python",
|
"Python": ["Backend", "ML"],
|
||||||
"JavaScript": "Frontend",
|
"JavaScript": ["Frontend"],
|
||||||
"TypeScript": "Frontend",
|
"TypeScript": ["Frontend"],
|
||||||
"HTML": "Frontend",
|
"HTML": ["Frontend"],
|
||||||
"CSS": "Frontend",
|
"CSS": ["Frontend"],
|
||||||
"Go": "Backend",
|
"Vue": ["Frontend"],
|
||||||
"Rust": "Systems",
|
"React": ["Frontend"],
|
||||||
"Java": "Backend",
|
"Go": ["Backend"],
|
||||||
"C++": "Systems",
|
"Rust": ["Backend", "Systems"],
|
||||||
"C": "Systems",
|
"Java": ["Backend"],
|
||||||
"Ruby": "Backend",
|
"C++": ["Systems"],
|
||||||
"PHP": "Backend",
|
"C": ["Systems"],
|
||||||
"Shell": "DevOps",
|
"Ruby": ["Backend"],
|
||||||
"Dockerfile": "DevOps",
|
"PHP": ["Backend"],
|
||||||
"Jupyter Notebook": "ML",
|
"Shell": ["DevOps"],
|
||||||
|
"Dockerfile": ["DevOps"],
|
||||||
|
"Makefile": ["DevOps"],
|
||||||
|
"Jupyter Notebook": ["ML"],
|
||||||
|
"R": ["ML"],
|
||||||
|
"Scala": ["Backend", "ML"],
|
||||||
|
"Kotlin": ["Backend", "Mobile"],
|
||||||
|
"Swift": ["Mobile"],
|
||||||
|
"Objective-C": ["Mobile"],
|
||||||
}
|
}
|
||||||
|
|
||||||
focus_counts = defaultdict(int)
|
focus_counts = defaultdict(float)
|
||||||
|
|
||||||
# Use events-based counting to track actual activity
|
# Use top 30 most recently pushed repos
|
||||||
repo_langs = {}
|
sorted_repos = sorted(repos, key=lambda r: r.get("pushed_at", ""), reverse=True)
|
||||||
for r in repos:
|
active_repos = sorted_repos[:30]
|
||||||
|
|
||||||
|
# Count languages in active repos
|
||||||
|
lang_weights = defaultdict(int)
|
||||||
|
for r in active_repos:
|
||||||
lang = r.get("language")
|
lang = r.get("language")
|
||||||
if lang:
|
if lang:
|
||||||
repo_langs[r["full_name"]] = lang
|
lang_weights[lang] += 1
|
||||||
|
|
||||||
for ev in events:
|
total_weight = sum(lang_weights.values())
|
||||||
if ev.get("type") == "PushEvent":
|
|
||||||
repo_name = ev.get("repo", {}).get("name", "")
|
|
||||||
lang = repo_langs.get(repo_name)
|
|
||||||
focus = lang_to_focus.get(lang, "Other")
|
|
||||||
commits = len(ev.get("payload", {}).get("commits", []))
|
|
||||||
focus_counts[focus] += commits
|
|
||||||
|
|
||||||
# If no events, fallback to repo count
|
# Distribute contributions proportionally to language presence
|
||||||
if not focus_counts:
|
if total_weight > 0 and total_contributions > 0:
|
||||||
for r in repos:
|
for lang, weight in lang_weights.items():
|
||||||
|
contribution_estimate = (weight / total_weight) * total_contributions
|
||||||
|
|
||||||
|
# Add to all applicable focus categories
|
||||||
|
if lang in lang_to_focus:
|
||||||
|
for focus in lang_to_focus[lang]:
|
||||||
|
focus_counts[focus] += contribution_estimate
|
||||||
|
else:
|
||||||
|
focus_counts["Other"] += contribution_estimate
|
||||||
|
else:
|
||||||
|
# Fallback: use repo counts
|
||||||
|
for r in active_repos:
|
||||||
lang = r.get("language")
|
lang = r.get("language")
|
||||||
if lang:
|
if lang in lang_to_focus:
|
||||||
focus = lang_to_focus.get(lang, "Other")
|
for focus in lang_to_focus[lang]:
|
||||||
focus_counts[focus] += 1
|
focus_counts[focus] += 1
|
||||||
|
elif lang:
|
||||||
|
focus_counts["Other"] += 1
|
||||||
|
|
||||||
|
# Use total contributions as the base for percentages (allows overlap > 100%)
|
||||||
|
total = total_contributions if total_contributions > 0 else sum(focus_counts.values())
|
||||||
|
total = total or 1
|
||||||
|
|
||||||
total = sum(focus_counts.values()) or 1
|
|
||||||
return [
|
return [
|
||||||
FocusCategory(
|
FocusCategory(
|
||||||
category=cat,
|
category=cat,
|
||||||
percentage=round(count / total * 100, 1),
|
percentage=round(count / total * 100, 1),
|
||||||
commit_count=count,
|
commit_count=int(count),
|
||||||
)
|
)
|
||||||
for cat, count in sorted(focus_counts.items(), key=lambda x: -x[1])
|
for cat, count in sorted(focus_counts.items(), key=lambda x: -x[1])
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user