Skip to content

Commit

Permalink
Add wins to stats
Browse files Browse the repository at this point in the history
  • Loading branch information
joeke committed Jul 18, 2024
1 parent ad0bf29 commit a5c2ad7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,22 @@ private function statistics()
return ($game->player_id === auth()->user()->id && $game->opponent_id > 0) || $game->opponent_id === auth()->user()->id;
});

// Find all games where is_finished = 1 and player score is higher than opponent score
$gamesWon = $versusGames->filter(function ($game) {
$scores = collect($game->scores)->toArray();
$playerScore = collect($scores)->where('player_id', auth()->user()->id)->sum('points');
$opponentScore = collect($scores)->where('player_id', '!=', auth()->user()->id)->sum('points');

return $game->is_finished && $playerScore > $opponentScore;
});

return [
'games' => [
'total' => $games->count(),
'versus' => $versusGames->count(),
'solo' => $games->count() - $versusGames->count()
'solo' => $games->count() - $versusGames->count(),
'wins' => $gamesWon->count(),
],
'wins' => 0, // TODO
'losses' => 0, // TODO
'highRuns' => $highRuns,
'averageRun' => $allScores ? round(collect($allScores)->avg('points'), 2) : 0,
'totalPoints' => $allScores ? collect($allScores)->sum('points') : 0,
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const statistics = usePage().props.statistics;

<div class="table-list-row">
<div class="w-min">Vs opponent:</div>
<div>{{ statistics.games.versus }}</div>
<div>{{ statistics.games.versus }} (wins: {{ statistics.games.wins }})</div>
</div>

<div class="table-list-row">
Expand Down

0 comments on commit a5c2ad7

Please sign in to comment.