-
Notifications
You must be signed in to change notification settings - Fork 391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add seasonal leaderboards #11804
Add seasonal leaderboards #11804
Conversation
@venix12 able to add some screenshots showing what we're adding here? 😄 |
updated the opening message accordingly 👁️ |
app/Models/Season.php
Outdated
{ | ||
return cache_remember_mutexed( | ||
"divisions:{$this->id}", | ||
$GLOBALS['cfg']['osu']['seasons']['divisions_cache_duration'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recently saw the duration being pulled from config/env in other places (tags) so just mimicked that, but wondering if this is actually needed here to begin with 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no it's not. the other place involves some aggregation and stuff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by "it's not" I mean the whole caching...
what's this division/threshold/absolute threshold thing here? What's the difference between absolute and not? |
Divisions are tiers that are assigned to each of season's players based on their rank. The divsisions (set per-season) are assigned for top x% of season players, therefore:
threshold column should probably use decimal(4,3) or so instead of float now that i think about this 🤔 |
database/migrations/2025_01_06_203319_create_divisions_table.php
Outdated
Show resolved
Hide resolved
database/migrations/2025_01_06_203319_create_divisions_table.php
Outdated
Show resolved
Hide resolved
app/Models/Season.php
Outdated
public function divisionsWithAbsoluteThresholds(): array | ||
{ | ||
$divisions = $this->divisions()->orderBy('threshold')->get(); | ||
$userCount = $this->userScores()->count(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should have forRanking
filter just like the actual table
also the value is already queried by the pagination thing...
@if (isset($currentDivision)) | ||
{{ $currentDivision['division']->name }} | ||
@endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just use ?->name
and skip the null check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that will throw error on trying to access division key on null, won't it? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I was trying it on a different thing before where the variable is assigned actual model. an ?? ''
at the end works
@@ -0,0 +1,37 @@ | |||
<?php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
migration date needs an update
$table->integer('season_id')->unsigned(); | ||
$table->string('name'); | ||
$table->string('image_url'); | ||
$table->decimal('threshold', 4, 3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this results in string (including when casted as decimal) which isn't wanted. Operating on it properly is also a bit verbose. And then the result is rounded anyway...
A double is probably fine (or cast to double)
app/Models/SeasonDivision.php
Outdated
* @property string $image_url | ||
* @property string $name | ||
* @property int $season_id | ||
* @property int $threshold |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not int
app/Models/Season.php
Outdated
foreach ($divisions as $division) { | ||
$divisionsWithMaxRanks[] = [ | ||
'division' => $division, | ||
'max_rank' => $division->threshold * $userCount, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can use an explicit rounding and casting to int
app/Models/SeasonDivision.php
Outdated
* @property string $image_url | ||
* @property string $name | ||
* @property int $season_id | ||
* @property double $threshold |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's all float in php
app/Models/Season.php
Outdated
foreach ($divisions as $division) { | ||
$divisionsWithMaxRanks[] = [ | ||
'division' => $division, | ||
'max_rank' => get_int($division->threshold * $userCount), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it works but it's not quite what get_int is for... ಠ_ಠ (it's more for validating unknown variable/string, not a known float)
|
||
<tr class="{{ class_with_modifiers('ranking-page-table__row', ['inactive' => !$score->user->isActive()]) }}"> | ||
<td class="ranking-page-table__column ranking-page-table__column--rank"> | ||
#{{ $rank }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can use i18n formatting
<tbody> | ||
@foreach ($scores as $index => $score) | ||
@php | ||
$rank = $scores->firstItem() + $index; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor thing but maybe store the firstItem
value beforehand
@@ -34,6 +34,10 @@ class="btn-osu-big btn-osu-big--rounded-thin" | |||
<div class="js-react--seasons-show"></div> | |||
@endsection | |||
|
|||
@section('scores') | |||
@include('seasons._rankings_table', [$divisions, $scores]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's not how passing variable works. It should be ['var' => $thing]
to access it as $var
in the included view. It only seemed to work because all variables from current context are passed through.
Depends on #11768.
Part of #8736.
This adds per-season rankings to current seasons page, including seasonal total score (as of #11768) and assigned division display (calculation of which is part of this PR).
image_url
column ofdivisions
table isn't currently being utilized for purpose of the ranking display, but will be used for user profile division display in the future.