<commit_before><?php

namespace Zeropingheroes\Lanager\Services;

use Zeropingheroes\Lanager\Lan;
use Zeropingheroes\Lanager\SteamUserApp;
use Zeropingheroes\Lanager\User;

class GetGamesPlayedRecentlyService
{
    /**
     * Get the top 10 games that users have played in the last 2 weeks.
     *
     * @return array
     */
    public function get(): array
    {
        // Get the LAN happening now, or the most recently ended LAN
        $lan = Lan::presentAndPast()
            ->orderBy('start', 'desc')
            ->first();

        if ($lan) {
            // Get the attendees for the LAN
            $users = $lan->users()->get();
        } else {
            // Or if there isn't a current LAN set, get all users
            $users = User::all();
        }

        $steamUserApps = SteamUserApp::with('user', 'app', 'user.steamMetadata', 'user.accounts')
            ->where('playtime_two_weeks', '>', 0)
            ->whereIn('user_id', $users->pluck('id'))
            ->get();

        if (empty($steamUserApps)) {
            return [];
        }

        // Collect and combine games
        $combinedUsage = [];
        foreach ($steamUserApps as $steamUserApp) {
            $combinedUsage[$steamUserApp->steam_app_id] = $combinedUsage[$steamUserApp->steam_app_id] ?? [
                    'game' => null,
                    'users' => [],
                ];
            $combinedUsage[$steamUserApp->steam_app_id]['game'] = $combinedUsage[$steamUserApp->steam_app_id]['game'] ?? $steamUserApp->app;
            $combinedUsage[$steamUserApp->steam_app_id]['users'][] = $steamUserApp->user;
        }

        // Sort games array by user count, in descending order
        usort(
            $combinedUsage,
            function ($a, $b) {
                return count($b['users']) - count($a['users']);
            }
        );

        // Remove any recently played games that have only been played by one user
        $combinedUsage = array_filter(
            $combinedUsage,
            function ($game) {
                return count($game['users']) > 1;
            }
        );

        $combinedUsage = array_slice($combinedUsage, 0, 10);

        return $combinedUsage;
    }
}
<commit_msg>Shorten variable names<commit_after><?php

namespace Zeropingheroes\Lanager\Services;

use Zeropingheroes\Lanager\Lan;
use Zeropingheroes\Lanager\SteamUserApp;
use Zeropingheroes\Lanager\User;

class GetGamesPlayedRecentlyService
{
    /**
     * Get the top 10 games that users have played in the last 2 weeks.
     *
     * @return array
     */
    public function get(): array
    {
        // Get the LAN happening now, or the most recently ended LAN
        $lan = Lan::presentAndPast()
            ->orderBy('start', 'desc')
            ->first();

        if ($lan) {
            // Get the attendees for the LAN
            $users = $lan->users()->get();
        } else {
            // Or if there isn't a current LAN set, get all users
            $users = User::all();
        }

        $steamUserApps = SteamUserApp::with('user', 'app', 'user.steamMetadata', 'user.accounts')
            ->where('playtime_two_weeks', '>', 0)
            ->whereIn('user_id', $users->pluck('id'))
            ->get();

        if (empty($steamUserApps)) {
            return [];
        }

        // Collect and combine games
        $usage = [];
        foreach ($steamUserApps as $app) {
            $usage[$app->steam_app_id] = $usage[$app->steam_app_id] ?? [
                    'game' => null,
                    'users' => [],
                ];
            $usage[$app->steam_app_id]['game'] = $usage[$app->steam_app_id]['game'] ?? $app->app;
            $usage[$app->steam_app_id]['users'][] = $app->user;
        }

        // Sort games array by user count, in descending order
        usort(
            $usage,
            function ($a, $b) {
                return count($b['users']) - count($a['users']);
            }
        );

        // Remove any recently played games that have only been played by one user
        $usage = array_filter(
            $usage,
            function ($game) {
                return count($game['users']) > 1;
            }
        );

        $usage = array_slice($usage, 0, 10);

        return $usage;
    }
}

{'fraction_non_alphanumeric': 0.13962176044828392, 'fraction_numerical': 0.0037356992762082653, 'mean_word_length': 1.805500982318271, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4883535', 'n_tokens_mistral': 1306, 'n_tokens_neox': 1245, 'n_words': 296}