<commit_before><?php

// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

namespace App\Http\Controllers;

use App\Models\Beatmap;
use App\Models\Country;
use App\Models\CountryStatistics;
use App\Models\Spotlight;
use App\Models\UserStatistics;
use DB;
use Illuminate\Pagination\LengthAwarePaginator;

/**
 * @group Ranking
 */
class RankingController extends Controller
{
    private $country;
    private $countryStats;
    private $params;
    private $friendsOnly;

    const PAGE_SIZE = 50;
    const MAX_RESULTS = 10000;
    const RANKING_TYPES = ['performance', 'charts', 'score', 'country'];
    const SPOTLIGHT_TYPES = ['charts'];

    public function __construct()
    {
        parent::__construct();

        $this->middleware('require-scopes:public');

        $this->middleware(function ($request, $next) {
            $this->params = get_params(array_merge($request->all(), $request->route()->parameters()), null, [
                'country', // overridden later for view
                'filter',
                'mode',
                'spotlight:int', // will be overriden by spotlight object for view
                'type',
                'variant',
            ]);

            // these parts of the route are optional.
            $mode = $this->params['mode'] ?? null;
            $type = $this->params['type'] ?? null;

            $this->params['filter'] = $this->params['filter'] ?? null;
            $this->friendsOnly = auth()->check() && $this->params['filter'] === 'friends';
            $this->setVariantParam();

            view()->share('hasPager', !in_array($type, static::SPOTLIGHT_TYPES, true));
            view()->share('spotlight', null); // so variable capture in selector function doesn't die when spotlight is null.
            view()->share($this->params); // won't set null values

            if ($mode === null) {
                return ujs_redirect(route('rankings', ['mode' => default_mode(), 'type' => 'performance']));
            }

            if (!Beatmap::isModeValid($mode)) {
                abort(404);
            }

            if ($type === null) {
                return ujs_redirect(route('rankings', ['mode' => $mode, 'type' => 'performance']));
            }

            if (!in_array($type, static::RANKING_TYPES, true)) {
                abort(404);
            }

            if (isset($this->params['country']) && $type === 'performance') {
                $this->countryStats = CountryStatistics::where('display', 1)
                    ->where('country_code', $this->params['country'])
                    ->where('mode', Beatmap::modeInt($mode))
                    ->first();

                if ($this->countryStats === null) {
                    return ujs_redirect(route('rankings', ['mode' => $mode, 'type' => $type]));
                }

                $this->country = $this->countryStats->country;
            }

            view()->share('country', $this->country);

            return $next($request);
        });
    }

    /**
     * Get Ranking
     *
     * Gets the current ranking for the specified type and game mode.
     *
     * ---
     *
     * ### Response Format
     *
     * Returns [Rankings](#rankings)
     *
     * @urlParam mode required [GameMode](#gamemode). Example: mania
     * @urlParam type required [RankingType](#rankingtype). Example: performance
     *
     * @queryParam country Filter ranking by country code. Only available for `type` of `performance`. Example: JP
     * @queryParam filter Either `all` or `friends`. Example: all
     * @queryParam spotlight The id of the spotlight if `type` is `charts`. Example: --skip--
     * @queryParam variant Either `4k` or `7k`. Only available for `type` of `performance` and `mode` of `mania`. Example: 4k
     */
    public function index($mode, $type)
    {
        if ($type === 'charts') {
            return $this->spotlight($mode);
        }

        $modeInt = Beatmap::modeInt($mode);

        if ($type === 'country') {
            $stats = CountryStatistics::where('display', 1)
                ->with('country')
                ->where('mode', $modeInt)
                ->orderBy('performance', 'desc');<commit_msg>Add cursor to parameter list<commit_after><?php

// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

namespace App\Http\Controllers;

use App\Models\Beatmap;
use App\Models\Country;
use App\Models\CountryStatistics;
use App\Models\Spotlight;
use App\Models\UserStatistics;
use DB;
use Illuminate\Pagination\LengthAwarePaginator;

/**
 * @group Ranking
 */
class RankingController extends Controller
{
    private $country;
    private $countryStats;
    private $params;
    private $friendsOnly;

    const PAGE_SIZE = 50;
    const MAX_RESULTS = 10000;
    const RANKING_TYPES = ['performance', 'charts', 'score', 'country'];
    const SPOTLIGHT_TYPES = ['charts'];

    public function __construct()
    {
        parent::__construct();

        $this->middleware('require-scopes:public');

        $this->middleware(function ($request, $next) {
            $this->params = get_params(array_merge($request->all(), $request->route()->parameters()), null, [
                'country', // overridden later for view
                'filter',
                'mode',
                'spotlight:int', // will be overriden by spotlight object for view
                'type',
                'variant',
            ]);

            // these parts of the route are optional.
            $mode = $this->params['mode'] ?? null;
            $type = $this->params['type'] ?? null;

            $this->params['filter'] = $this->params['filter'] ?? null;
            $this->friendsOnly = auth()->check() && $this->params['filter'] === 'friends';
            $this->setVariantParam();

            view()->share('hasPager', !in_array($type, static::SPOTLIGHT_TYPES, true));
            view()->share('spotlight', null); // so variable capture in selector function doesn't die when spotlight is null.
            view()->share($this->params); // won't set null values

            if ($mode === null) {
                return ujs_redirect(route('rankings', ['mode' => default_mode(), 'type' => 'performance']));
            }

            if (!Beatmap::isModeValid($mode)) {
                abort(404);
            }

            if ($type === null) {
                return ujs_redirect(route('rankings', ['mode' => $mode, 'type' => 'performance']));
            }

            if (!in_array($type, static::RANKING_TYPES, true)) {
                abort(404);
            }

            if (isset($this->params['country']) && $type === 'performance') {
                $this->countryStats = CountryStatistics::where('display', 1)
                    ->where('country_code', $this->params['country'])
                    ->where('mode', Beatmap::modeInt($mode))
                    ->first();

                if ($this->countryStats === null) {
                    return ujs_redirect(route('rankings', ['mode' => $mode, 'type' => $type]));
                }

                $this->country = $this->countryStats->country;
            }

            view()->share('country', $this->country);

            return $next($request);
        });
    }

    /**
     * Get Ranking
     *
     * Gets the current ranking for the specified type and game mode.
     *
     * ---
     *
     * ### Response Format
     *
     * Returns [Rankings](#rankings)
     *
     * @urlParam mode required [GameMode](#gamemode). Example: mania
     * @urlParam type required [RankingType](#rankingtype). Example: performance
     *
     * @queryParam country Filter ranking by country code. Only available for `type` of `performance`. Example: JP
     * @queryParam cursor [Cursor](#cursor). Example: --skip--
     * @queryParam filter Either `all` or `friends`. Example: all
     * @queryParam spotlight The id of the spotlight if `type` is `charts`. Example: --skip--
     * @queryParam variant Either `4k` or `7k`. Only available for `type` of `performance` and `mode` of `mania`. Example: 4k
     */
    public function index($mode, $type)
    {
        if ($type === 'charts') {
            return $this->spotlight($mode);
        }

        $modeInt = Beatmap::modeInt($mode);

        if ($type === 'country') {
            $stats = CountryStatistics::where('display', 1)
                ->with('country')
                ->where('mode', $modeInt)
                ->orderBy('performance', 'desc');
{'fraction_non_alphanumeric': 0.15367816091954023, 'fraction_numerical': 0.004597701149425287, 'mean_word_length': 2.162849872773537, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 87, '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': '5819557', 'n_tokens_mistral': 2471, 'n_tokens_neox': 2323, 'n_words': 618}