wip
This commit is contained in:
1 parent
10baadb780
commit
874f6f75c8
7 files changed
+85
-132
No files matched your search
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages\Selections;
|
||||
|
||||
use App\Models\StatistikoEvent;
|
||||
use App\Models\SofaScorePlayerPosition;
|
||||
use App\Models\SofaScorePlayerPerSeason;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
|
||||
class LoadPlayer
|
||||
{
|
||||
public static function load(Get $get)
|
||||
{
|
||||
$team_id = $get('team_id');
|
||||
|
||||
$season = $get('season');
|
||||
|
||||
$team_position = $get('team_position');
|
||||
|
||||
$season_or_date = $filter['season_or_date'] ?? 'season';
|
||||
|
||||
if ($season_or_date != 'season' or !count($season)) {
|
||||
$season[] = date('Y');
|
||||
}
|
||||
|
||||
$matches = StatistikoEvent::where(function ($query) use ($team_id, $team_position) {
|
||||
switch ($team_position) {
|
||||
case 'home':
|
||||
return $query->where('home_id', '=', $team_id);
|
||||
case 'away':
|
||||
return $query->where('away_id', '=', $team_id);
|
||||
default:
|
||||
return $query->where('home_id', '=', $team_id)
|
||||
->orWhere('away_id', '=', $team_id);
|
||||
}
|
||||
})->pluck('match_id')->toArray();
|
||||
|
||||
$matches_count = count($matches);
|
||||
|
||||
$ss_positions_map = SofaScorePlayerPosition::pluck('name', 'ss_code')->toArray();
|
||||
|
||||
// needs to run daily for pre-calculaton
|
||||
$player = SofaScorePlayerPerSeason::with('details')->where('ss_team_id', $team_id)->whereIn('season', $season)->get();
|
||||
|
||||
$arr = [];
|
||||
foreach ($player as $val) {
|
||||
|
||||
switch ($team_position) {
|
||||
case 'home':
|
||||
$events_played = $val->events_played_home;
|
||||
$minues_played = $val->minutes_played_home;
|
||||
break;
|
||||
case 'away':
|
||||
$events_played = $val->events_played_away;
|
||||
$minues_played = $val->minutes_played_away;
|
||||
break;
|
||||
default:
|
||||
$events_played = $val->events_played_home + $val->events_played_away;
|
||||
$minues_played = $val->minutes_played_home + $val->minutes_played_home;
|
||||
break;
|
||||
}
|
||||
|
||||
$colorlevel = round($matches_count / 3);
|
||||
|
||||
$preferred_foot = $val->details->preferred_foot;
|
||||
|
||||
$position = $ss_positions_map[$val->details->position] ?? 'No Specific Position';
|
||||
|
||||
$infostring = $events_played . ' Ev';
|
||||
if ($preferred_foot)
|
||||
$infostring .= ' - ' . $preferred_foot;
|
||||
if ($events_played)
|
||||
$infostring .= ' - ' . round($minues_played / $events_played) . 'min';
|
||||
|
||||
if ($events_played < $colorlevel) {
|
||||
$arr[$position][$val->ss_player_id] = '<span class="text-red-600 dark:text-red-500 cursor-pointer"><b>' . $val->details->player_name . '</b><br>' . $infostring . '</span>';
|
||||
} else if ($events_played < $colorlevel * 2) {
|
||||
$arr[$position][$val->ss_player_id] = '<span class="text-blue-600 dark:text-blue-500 cursor-pointer"><b>' . $val->details->player_name . '</b><br>' . $infostring . '</span>';
|
||||
} else {
|
||||
$arr[$position][$val->ss_player_id] = '<span class="text-green-600 dark:text-green-500 cursor-pointer"><b>' . $val->details->player_name . '</b><br>' . $infostring . '</span>';
|
||||
}
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function convertToHoursMins(int $time, $format = '%02dh:%02dm')
|
||||
{
|
||||
if ($time < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
$hours = floor($time / 60);
|
||||
$minutes = $time % 60;
|
||||
|
||||
return sprintf($format, $hours, $minutes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages\Selections;
|
||||
|
||||
use App\Models\StatistikoEvent;
|
||||
|
||||
class LoadSeasons
|
||||
{
|
||||
public static function load($league_id = 0)
|
||||
{
|
||||
// $res = CompetitionGroup::with('country')->where('id', $league_id)->first();
|
||||
// $season_mode = $res->country->season_mode;
|
||||
|
||||
$res = StatistikoEvent::where('league_id', $league_id)
|
||||
->groupBy('season')
|
||||
->orderBy('starttime', 'ASC')
|
||||
->get();
|
||||
|
||||
if (! $res) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$arr = [];
|
||||
foreach ($res as $val) {
|
||||
$arr[$val->season] = $val->season;
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
@@ -2,28 +2,28 @@
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use BackedEnum;
|
||||
use Filament\Support\RawJs;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Schemas\Schema;
|
||||
use App\Actions\LoadStatisticFixturesLeaguesOptions;
|
||||
use App\Actions\LoadStatisticFixturesMatchOptions;
|
||||
use App\Filament\Pages\Selections\LoadPlayer;
|
||||
use App\Filament\Pages\Selections\LoadSeasons;
|
||||
use App\Models\SofaScoreRosa;
|
||||
use App\Models\StatisticFixtures;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use BackedEnum;
|
||||
use BezhanSalleh\FilamentShield\Traits\HasPageShield;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Radio;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Slider;
|
||||
use Filament\Schemas\Components\Grid;
|
||||
use App\Actions\Selections\LoadPlayer;
|
||||
use App\Actions\Selections\LoadSeasons;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Pages\Dashboard as BaseDashboard;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
|
||||
use Filament\Schemas\Components\Grid;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Components\Utilities\Set;
|
||||
use App\Actions\LoadStatisticFixturesMatchOptions;
|
||||
use App\Actions\LoadStatisticFixturesLeaguesOptions;
|
||||
use BezhanSalleh\FilamentShield\Traits\HasPageShield;
|
||||
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\RawJs;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
class Statistic extends BaseDashboard
|
||||
{
|
||||
@@ -237,6 +237,7 @@ class Statistic extends BaseDashboard
|
||||
->color('success')
|
||||
->tooltip(fn() => $this->tooltip_player_info())
|
||||
)
|
||||
->extraAttributes(fn() => ['id' => 'player_selector'])
|
||||
->options(function (Get $get) {
|
||||
return LoadPlayer::load($get);
|
||||
}),
|
||||
|
||||
Reference in new issue
Block a user