From 1adade9ee1d002b41ee4a8d94d7b860069be43d8 Mon Sep 17 00:00:00 2001 From: angelol-git Date: Mon, 18 May 2026 17:06:16 -0400 Subject: [PATCH 1/4] fix(user): resolve Most Recent System progression --- .../GetUserProgressionStatusCountsAction.php | 21 +++++++++++++------ .../views/pages-legacy/userInfo.blade.php | 9 +------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/Platform/Actions/GetUserProgressionStatusCountsAction.php b/app/Platform/Actions/GetUserProgressionStatusCountsAction.php index e3aea11671..9ee7a5b83d 100644 --- a/app/Platform/Actions/GetUserProgressionStatusCountsAction.php +++ b/app/Platform/Actions/GetUserProgressionStatusCountsAction.php @@ -18,14 +18,15 @@ class GetUserProgressionStatusCountsAction /** * @return array{ * avgCompletionPercentage: float, - * systemProgress: array, + * systemProgress: array, + * * topSystemId: int|null, * totalCounts: array{unfinished: int, beatenSoftcore: int, beatenHardcore: int, completed: int, mastered: int}, * totalHardcoreAchievements: int, * totalSoftcoreAchievements: int, * } */ - public function execute(User $user, ?int $recentSystemId = null): array + public function execute(User $user): array { // Subsets are identified by their core achievement set being linked to another game as a non-core type. $subsetExistsSubquery = "EXISTS ( @@ -47,6 +48,7 @@ public function execute(User $user, ?int $recentSystemId = null): array $results = $this->buildQualifyingGamesQuery($user) ->selectRaw(" games.system_id, + MAX(player_games.last_played_at) as last_played_at, SUM(player_games.achievements_unlocked_hardcore) as total_hc_achievements, SUM(GREATEST(0, CAST(player_games.achievements_unlocked AS SIGNED) - CAST(player_games.achievements_unlocked_hardcore AS SIGNED))) as total_sc_achievements, SUM(mastery_hc.id IS NOT NULL) as mastered_count, @@ -100,6 +102,7 @@ public function execute(User $user, ?int $recentSystemId = null): array $beatenHc = (int) $row->beaten_hc_count; $beatenSc = (int) $row->beaten_sc_count; $unfinished = (int) $row->unfinished_count; + $lastPlayedAt = (string) $row->last_played_at; $systemProgress[$systemId] = [ 'unfinishedCount' => $unfinished, @@ -107,6 +110,7 @@ public function execute(User $user, ?int $recentSystemId = null): array 'beatenHardcoreCount' => $beatenHc, 'completedCount' => $completed, 'masteredCount' => $mastered, + 'lastPlayedAt' => $lastPlayedAt, 'systemId' => $systemId, ]; @@ -126,9 +130,13 @@ public function execute(User $user, ?int $recentSystemId = null): array $avgCompletionPercentage = $this->calculateAvgCompletionExcludingSubsets($user); - $topSystemId = ($recentSystemId !== null && isset($systemProgress[$recentSystemId])) - ? $recentSystemId - : array_key_first($systemProgress); + // topSystem is the most recent valid system where the user has earned achievements. + $topSystemId = !empty($systemProgress) + ? collect($systemProgress) + ->sortByDesc(fn ($progress) => strtotime($progress['lastPlayedAt'] ?? '') ?: 0) + ->keys() + ->first() + : null; // Sort: topSystem first, then by total games played descending. uasort($systemProgress, function ($a, $b) use ($topSystemId) { @@ -159,7 +167,7 @@ public function execute(User $user, ?int $recentSystemId = null): array * Finds badges for games not included in the main query and adds them to the counts. * This handles edge cases like demoted games, etc. * - * @param array $systemProgress + * @param array $systemProgress * @param array{unfinished: int, beatenSoftcore: int, beatenHardcore: int, completed: int, mastered: int} $totalCounts */ private function addOrphanBadgeCounts(User $user, array &$systemProgress, array &$totalCounts): void @@ -224,6 +232,7 @@ private function addOrphanBadgeCounts(User $user, array &$systemProgress, array 'completedCount' => 0, 'masteredCount' => 0, 'systemId' => $systemId, + 'lastPlayedAt' => null, ]; } diff --git a/resources/views/pages-legacy/userInfo.blade.php b/resources/views/pages-legacy/userInfo.blade.php index 5b36543617..57da656885 100644 --- a/resources/views/pages-legacy/userInfo.blade.php +++ b/resources/views/pages-legacy/userInfo.blade.php @@ -43,15 +43,8 @@ $userWallActive = $userMassData['UserWallActive']; $userIsUntracked = $userMassData['Untracked']; -$recentlyPlayedSystemId = collect($userMassData['RecentlyPlayed'] ?? []) - ->filter(fn ($game) => System::isGameSystem($game['ConsoleID'] ?? 0) && ($game['AchievementsTotal'] ?? 0) > 0) - ->sortByDesc('LastPlayed') - ->pluck('ConsoleID') - ->first(); - $progressionCounts = (new GetUserProgressionStatusCountsAction())->execute( - $userPageModel, - $recentlyPlayedSystemId + $userPageModel ); $averageCompletionPercentage = sprintf("%01.2f", $progressionCounts['avgCompletionPercentage']); From c6872e72d686825541d0f8769111e3fc3a885561 Mon Sep 17 00:00:00 2001 From: angelol-git Date: Wed, 20 May 2026 04:14:51 -0400 Subject: [PATCH 2/4] address feedback --- .../GetUserProgressionStatusCountsAction.php | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/app/Platform/Actions/GetUserProgressionStatusCountsAction.php b/app/Platform/Actions/GetUserProgressionStatusCountsAction.php index 9ee7a5b83d..7ccdfae6d7 100644 --- a/app/Platform/Actions/GetUserProgressionStatusCountsAction.php +++ b/app/Platform/Actions/GetUserProgressionStatusCountsAction.php @@ -18,8 +18,7 @@ class GetUserProgressionStatusCountsAction /** * @return array{ * avgCompletionPercentage: float, - * systemProgress: array, - * + * systemProgress: array, * topSystemId: int|null, * totalCounts: array{unfinished: int, beatenSoftcore: int, beatenHardcore: int, completed: int, mastered: int}, * totalHardcoreAchievements: int, @@ -102,7 +101,7 @@ public function execute(User $user): array $beatenHc = (int) $row->beaten_hc_count; $beatenSc = (int) $row->beaten_sc_count; $unfinished = (int) $row->unfinished_count; - $lastPlayedAt = (string) $row->last_played_at; + $lastPlayedAt = $row->last_played_at?->format('Y-m-d H:i:s'); $systemProgress[$systemId] = [ 'unfinishedCount' => $unfinished, @@ -110,6 +109,7 @@ public function execute(User $user): array 'beatenHardcoreCount' => $beatenHc, 'completedCount' => $completed, 'masteredCount' => $mastered, + 'isOrphan' => false, 'lastPlayedAt' => $lastPlayedAt, 'systemId' => $systemId, ]; @@ -131,12 +131,21 @@ public function execute(User $user): array $avgCompletionPercentage = $this->calculateAvgCompletionExcludingSubsets($user); // topSystem is the most recent valid system where the user has earned achievements. - $topSystemId = !empty($systemProgress) - ? collect($systemProgress) - ->sortByDesc(fn ($progress) => strtotime($progress['lastPlayedAt'] ?? '') ?: 0) - ->keys() - ->first() - : null; + $topSystemId = null; + $latestTimestamp = null; + + foreach ($systemProgress as $systemId => $progress) { + if ($progress['isOrphan'] || $progress['lastPlayedAt'] === null) { + continue; + } + + $timestamp = strtotime($progress['lastPlayedAt']) ?: 0; + + if ($latestTimestamp === null || $timestamp > $latestTimestamp) { + $latestTimestamp = $timestamp; + $topSystemId = $systemId; + } + } // Sort: topSystem first, then by total games played descending. uasort($systemProgress, function ($a, $b) use ($topSystemId) { @@ -167,7 +176,7 @@ public function execute(User $user): array * Finds badges for games not included in the main query and adds them to the counts. * This handles edge cases like demoted games, etc. * - * @param array $systemProgress + * @param array $systemProgress * @param array{unfinished: int, beatenSoftcore: int, beatenHardcore: int, completed: int, mastered: int} $totalCounts */ private function addOrphanBadgeCounts(User $user, array &$systemProgress, array &$totalCounts): void @@ -231,8 +240,9 @@ private function addOrphanBadgeCounts(User $user, array &$systemProgress, array 'beatenHardcoreCount' => 0, 'completedCount' => 0, 'masteredCount' => 0, - 'systemId' => $systemId, + 'isOrphan' => true, 'lastPlayedAt' => null, + 'systemId' => $systemId, ]; } From 2b965c79c103232aa773dc3662028e75b498aad3 Mon Sep 17 00:00:00 2001 From: angelol-git Date: Wed, 20 May 2026 14:19:21 -0400 Subject: [PATCH 3/4] address feedback --- .../GetUserProgressionStatusCountsAction.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/Platform/Actions/GetUserProgressionStatusCountsAction.php b/app/Platform/Actions/GetUserProgressionStatusCountsAction.php index 7ccdfae6d7..0b5f06b121 100644 --- a/app/Platform/Actions/GetUserProgressionStatusCountsAction.php +++ b/app/Platform/Actions/GetUserProgressionStatusCountsAction.php @@ -18,7 +18,7 @@ class GetUserProgressionStatusCountsAction /** * @return array{ * avgCompletionPercentage: float, - * systemProgress: array, + * systemProgress: array, * topSystemId: int|null, * totalCounts: array{unfinished: int, beatenSoftcore: int, beatenHardcore: int, completed: int, mastered: int}, * totalHardcoreAchievements: int, @@ -124,10 +124,6 @@ public function execute(User $user): array $totalSoftcoreAchievements += (int) $row->total_sc_achievements; } - // Add counts for "orphan badges" - badges for games not in the main query. - // This handles demoted games, games with < 6 achievements, etc. - $this->addOrphanBadgeCounts($user, $systemProgress, $totalCounts); - $avgCompletionPercentage = $this->calculateAvgCompletionExcludingSubsets($user); // topSystem is the most recent valid system where the user has earned achievements. @@ -135,7 +131,7 @@ public function execute(User $user): array $latestTimestamp = null; foreach ($systemProgress as $systemId => $progress) { - if ($progress['isOrphan'] || $progress['lastPlayedAt'] === null) { + if ($progress['lastPlayedAt'] === null) { continue; } @@ -147,6 +143,10 @@ public function execute(User $user): array } } + // Add counts for "orphan badges" - badges for games not in the main query. + // This handles demoted games, games with < 6 achievements, etc. + $this->addOrphanBadgeCounts($user, $systemProgress, $totalCounts); + // Sort: topSystem first, then by total games played descending. uasort($systemProgress, function ($a, $b) use ($topSystemId) { if ($a['systemId'] === $topSystemId) { @@ -176,7 +176,7 @@ public function execute(User $user): array * Finds badges for games not included in the main query and adds them to the counts. * This handles edge cases like demoted games, etc. * - * @param array $systemProgress + * @param array $systemProgress * @param array{unfinished: int, beatenSoftcore: int, beatenHardcore: int, completed: int, mastered: int} $totalCounts */ private function addOrphanBadgeCounts(User $user, array &$systemProgress, array &$totalCounts): void @@ -240,7 +240,6 @@ private function addOrphanBadgeCounts(User $user, array &$systemProgress, array 'beatenHardcoreCount' => 0, 'completedCount' => 0, 'masteredCount' => 0, - 'isOrphan' => true, 'lastPlayedAt' => null, 'systemId' => $systemId, ]; From 179d976b476cda94420f091b171d1fff70392910 Mon Sep 17 00:00:00 2001 From: angelol-git Date: Wed, 20 May 2026 14:48:54 -0400 Subject: [PATCH 4/4] remove unused bool --- app/Platform/Actions/GetUserProgressionStatusCountsAction.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Platform/Actions/GetUserProgressionStatusCountsAction.php b/app/Platform/Actions/GetUserProgressionStatusCountsAction.php index 0b5f06b121..deded2dea9 100644 --- a/app/Platform/Actions/GetUserProgressionStatusCountsAction.php +++ b/app/Platform/Actions/GetUserProgressionStatusCountsAction.php @@ -109,7 +109,6 @@ public function execute(User $user): array 'beatenHardcoreCount' => $beatenHc, 'completedCount' => $completed, 'masteredCount' => $mastered, - 'isOrphan' => false, 'lastPlayedAt' => $lastPlayedAt, 'systemId' => $systemId, ];