new: usr: add new profile charts and stats - & add new logo to the tech stack #5

This commit is contained in:
Lang
2026-04-18 22:12:07 +02:00
parent 9aef27a0eb
commit 09b0d21621
8 changed files with 275 additions and 43 deletions
+58
View File
@@ -260,6 +260,21 @@ class PlayedGameRepository extends ServiceEntityRepository
}
}
public function findTotalMinesForUser(User $user): int
{
$conn = $this->getEntityManager()->getConnection();
$result = $conn->executeQuery(
'SELECT
COALESCE(SUM(CASE WHEN g.red_id = :uid THEN g.red_points ELSE g.blue_points END), 0) AS total_pts
FROM played_game g
WHERE (g.red_id = :uid OR g.blue_id = :uid)',
['uid' => $user->getId()],
)->fetchAssociative();
return (int) ($result['total_pts'] ?? 0);
}
public function findAvgScoreForUser(User $user): int
{
$conn = $this->getEntityManager()->getConnection();
@@ -284,6 +299,49 @@ class PlayedGameRepository extends ServiceEntityRepository
return (int) round((float) $result['total_pts'] / (int) $result['total_games']);
}
/**
* Aggregates bonus points and bonus stats across all finished games for a user.
*
* @return array{totalBonusPoints:float,avgBonusPoints:float,bestChain:int,totalBlindHits:int,totalEdgeMines:int}
*/
public function findBonusStatsForUser(User $user): array
{
$userId = $user->getId();
$qb = $this->createQueryBuilder('g');
$qb->where($qb->expr()->orX(
$qb->expr()->eq('g.red', ':u'),
$qb->expr()->eq('g.blue', ':u'),
))->setParameter('u', $user);
/** @var PlayedGame[] $games */
$games = $qb->getQuery()->getResult();
$totalBonusPoints = 0.0;
$bestChain = 0;
$totalBlindHits = 0;
$totalEdgeMines = 0;
$gameCount = 0;
foreach ($games as $game) {
$isRed = $game->getRed()?->getId() === $userId;
$totalBonusPoints += (float) (($isRed ? $game->getRedBonusPoints() : $game->getBlueBonusPoints()) ?? 0.0);
$stats = ($isRed ? $game->getRedBonusStats() : $game->getBlueBonusStats()) ?? [];
$bestChain = max($bestChain, (int) ($stats['chainBest'] ?? 0));
$totalBlindHits += (int) ($stats['blindHits'] ?? 0);
$totalEdgeMines += (int) ($stats['edgeMines'] ?? 0);
$gameCount++;
}
return [
'totalBonusPoints' => round($totalBonusPoints, 1),
'avgBonusPoints' => 0 < $gameCount ? round($totalBonusPoints / $gameCount, 1) : 0.0,
'bestChain' => $bestChain,
'totalBlindHits' => $totalBlindHits,
'totalEdgeMines' => $totalEdgeMines,
];
}
public function findBestScoreForUser(User $user): int
{
try {