Skip to content

Commit

Permalink
Minor changes to how the % shows for the bugs and suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKyle committed Aug 22, 2024
1 parent 8c53823 commit 012d5fa
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions app/Admin/Services/FeedbackService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,35 @@ public function gatherFeedbackData(): array {
$today = now()->startOfDay();
$yesterday = now()->subDay()->startOfDay();

$totalBugCount = SuggestionAndBugs::where('type', FeedbackType::BUG)->count();
$totalSuggestionCount = SuggestionAndBugs::where('type', FeedbackType::SUGGESTION)->count();

$bugsCountToday = SuggestionAndBugs::where('type', FeedbackType::BUG)->where('created_at', '>=', $today)->count();
$bugsCountYesterday = SuggestionAndBugs::where('type', FeedbackType::BUG)->where('created_at', '>=', $yesterday)->where('created_at', '<', $today)->count();

$suggestionCountToday = SuggestionAndBugs::where('type', FeedbackType::SUGGESTION)->where('created_at', '>=', $today)->count();
$suggestionCountYesterday = SuggestionAndBugs::where('type', FeedbackType::SUGGESTION)->where('created_at', '>=', $yesterday)->where('created_at', '<', $today)->count();

$bugsDifference = $this->calculateDifference($bugsCountToday, $bugsCountYesterday);
$suggestionDifference = $this->calculateDifference($suggestionCountToday, $suggestionCountYesterday);
$bugsDifference = $this->calculatePercentageDifference($bugsCountToday, $bugsCountYesterday);
$suggestionDifference = $this->calculatePercentageDifference($suggestionCountToday, $suggestionCountYesterday);


return [
'bugsCount' => $bugsCountToday,
'bugsDifference' => $bugsDifference,
'suggestionCount' => $suggestionCountToday,
'suggestionDifference' => $suggestionDifference,
'bugsCount' => $totalBugCount,
'bugsDifference' => abs($bugsDifference),
'suggestionCount' => $totalSuggestionCount,
'suggestionDifference' => abs($suggestionDifference),
];

}

private function calculateDifference($todayCount, $yesterdayCount): float {
if ($yesterdayCount == 0) {
return $todayCount == 0 ? 0 : 100;
private function calculatePercentageDifference(int $countToday, int $countYesterday): float {
if ($countYesterday === 0) {
return $countToday > 0 ? ($countToday / 100) : 0.0;
}

$difference = (($todayCount - $yesterdayCount) / $yesterdayCount) * 100;
$difference = $countToday - $countYesterday;
$percentageDifference = ($difference / $countYesterday) * 100;

return round($difference, 2);
return $percentageDifference;
}
}

0 comments on commit 012d5fa

Please sign in to comment.