Fixes calculations (#2)

Git Level (per commit):
    - Track unique file paths in FilesModified slice
    - FilesChanged = count of unique files in THIS commit

  Aggregator Level (per contributor):
    - Collect all file paths from all commits into a SET
    - FilesChanged = size of the unique file set

  Result:
    - Contributor.FilesChanged = count of UNIQUE files they touched
    - Repository contributor = unique files in THAT repo only
This commit is contained in:
2025-12-19 10:44:00 +00:00
committed by GitHub
parent aedcf87338
commit 3bd9807e50
8 changed files with 420 additions and 57 deletions
+4 -2
View File
@@ -293,9 +293,11 @@ func (c *Calculator) checkAchievements(cm *models.ContributorMetrics) []string {
case "comment_count":
earned = float64(cm.ReviewComments) >= ach.Condition.Threshold
case "lines_added":
earned = float64(cm.LinesAdded) >= ach.Condition.Threshold
// Use meaningful lines to match scoring calculation (excludes comments/whitespace)
earned = float64(cm.MeaningfulLinesAdded) >= ach.Condition.Threshold
case "lines_deleted":
earned = float64(cm.LinesDeleted) >= ach.Condition.Threshold
// Use meaningful lines to match scoring calculation (excludes comments/whitespace)
earned = float64(cm.MeaningfulLinesDeleted) >= ach.Condition.Threshold
case "avg_review_time_hours":
// For avg review time, lower is better, so lower threshold = harder achievement
if cm.AvgReviewTime > 0 && cm.AvgReviewTime <= ach.Condition.Threshold {
@@ -452,6 +452,8 @@ func TestCalculator_AllAchievementTypes(t *testing.T) {
ReviewComments: 25,
LinesAdded: 1500,
LinesDeleted: 600,
MeaningfulLinesAdded: 1500,
MeaningfulLinesDeleted: 600,
AvgReviewTime: 1.5,
UniqueReviewees: 7,
RepositoriesContributed: []string{"owner/repo1", "owner/repo2"},