[OW] Finalize Leaderboards

parent 73680d21
Pipeline #873 passed with stages
in 2 minutes and 18 seconds
......@@ -139,6 +139,12 @@ class Character
case 'mei':
return 'mei';
case 'tracer':
return 'tracer';
case 'orisa':
return 'orisa';
default:
return 'unknown';
}
......
<?php
namespace Onyx\Overwatch\Helpers\String;
use Illuminate\Support\Str;
/**
* Class Text
......@@ -8,6 +9,11 @@ namespace Onyx\Overwatch\Helpers\String;
*/
class Text
{
/**
* @var int
*/
public static $MINS_IN_HOUR = 60;
/**
* @param string $word
* @return string
......@@ -16,4 +22,38 @@ class Text
{
return str_replace('_', ' ', title_case($word));
}
/**
* @param string $stat
* @param string $value
* @return string
*/
public static function heuristicFormat(string $stat, string $value) : string
{
// Accuracy needs to be in percent.
if (Str::contains($stat, 'accuracy')) {
return (string) ($value * 100).'%';
}
// This is an already formatted average, just return
if (Str::contains($value, '.')) {
return (string) $value;
}
return (string) number_format($value);
}
/**
* @param string $playtime
* @return string
*/
public static function playtimeFormat(string $playtime) : string
{
$playtime = (float) $playtime;
if ($playtime < 1) {
return (self::$MINS_IN_HOUR * $playtime) . ' mins';
}
return $playtime . ' hour(s)';
}
}
......@@ -38,10 +38,12 @@ class StatsController extends Controller
$heros = CharacterModel::with(['stats.account.user'])
->where('character', $character)
->where('playtime', '>', 0)
->whereHas('stats.account.user', function(Builder $query) {
$query->where('isPanda', true);
})
->orderBy('playtime', 'desc')
->limit(20)
->get()
->toArray();
......
......@@ -2,10 +2,11 @@
<thead class="desktop only">
<tr>
<th>Gamertag</th>
<th>Season</th>
<th>Level</th>
<th>Max SR</th>
<th>Playtime</th>
<th>{{ $stat }}</th>
<th>{{ Onyx\Overwatch\Helpers\String\Text::label($stat) }}</th>
</tr>
</thead>
<tbody>
......@@ -19,6 +20,9 @@
</a>
</span>
</td>
<td>
{{ $hero['stats']['season'] }}
</td>
<td>
{{ $hero['stats']['totalLevel'] }}
</td>
......@@ -26,10 +30,10 @@
{{ $hero['stats']['max_comprank'] }}
</td>
<td>
{{ $hero['playtime'] }} hour(s)
{{ Onyx\Overwatch\Helpers\String\Text::playtimeFormat($hero['playtime']) }}
</td>
<td>
{{ array_get($hero['data'], $category.'.'.$stat, 0) }}
{{ Onyx\Overwatch\Helpers\String\Text::heuristicFormat($stat, array_get($hero['data'], $category.'.'.$stat, 0)) }}
</td>
</tr>
@endforeach
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment