Skip to content

Commit

Permalink
fix: division by zero in language stats (#2171)
Browse files Browse the repository at this point in the history
* fix: division by zero in language stats

Signed-off-by: Jos Ahrens <[email protected]>

* Modify minor to patch version in changeset

Co-authored-by: Vincenzo Scamporlino <[email protected]>
Signed-off-by: Jos Ahrens <[email protected]>

---------

Signed-off-by: Jos Ahrens <[email protected]>
Signed-off-by: Jos Ahrens <[email protected]>
Co-authored-by: Vincenzo Scamporlino <[email protected]>
  • Loading branch information
Zarthus and vinzscam authored Jan 16, 2025
1 parent 10226f1 commit 46c4837
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions workspaces/copilot/.changeset/six-years-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage-community/plugin-copilot': patch
---

Fix division by zero in language stats
11 changes: 8 additions & 3 deletions workspaces/copilot/plugins/copilot/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,19 @@ export function getLanguageStats(metricsArray: Metric[]): LanguageStats[] {
if (existingStats) {
existingStats.totalSuggestions += item.suggestions_count;
existingStats.totalAcceptances += item.acceptances_count;
existingStats.acceptanceRate =
existingStats.totalAcceptances / existingStats.totalSuggestions;
if (existingStats.totalSuggestions > 0) {
existingStats.acceptanceRate =
existingStats.totalAcceptances / existingStats.totalSuggestions;
}
} else {
languageStatsMap.set(item.language, {
language: item.language,
totalSuggestions: item.suggestions_count,
totalAcceptances: item.acceptances_count,
acceptanceRate: item.acceptances_count / item.suggestions_count,
acceptanceRate:
item.suggestions_count > 0
? item.acceptances_count / item.suggestions_count
: 0,
});
}
});
Expand Down

0 comments on commit 46c4837

Please sign in to comment.