This commit is contained in:
salam committed 2026-10-04 15:25:03 +02:00
1 parent 9bcd4432c6
commit 6f92f9e1d5
1209 files changed
+220940

No files matched your search

@@ -0,0 +1,58 @@
<?php
namespace App\Filament\Widgets\Boxes;
use App\Filament\Pages\Selections\Helper\GetSeason;
use App\Filament\Widgets\Boxes\Helper\ExpectationAverage;
use App\Models\StatistikoEvent;
class AverageLeagueSeason
{
public static function load(array &$expectations, array $filter)
{
$tournament_id = (int) $filter['league_id'] ?? 0;
$seasonmode = $filter['seasonmode'];
$active_season = GetSeason::active($seasonmode);
// Box 2
// average made and got for liga selected
// fixed to active season
$res = StatistikoEvent::where('league_id', $tournament_id)
->when($active_season, function ($query) use ($active_season) {
return $query->where('season', $active_season);
})->get();
$result = [];
if ($res) {
foreach ($res as $val) {
ExpectationAverage::filter($result, 'liga', 'gls', $val->gls_h, $val->gls_a);
ExpectationAverage::filter($result, 'liga', 'fls', $val->fls_h, $val->fls_a);
ExpectationAverage::filter($result, 'liga', 'ofs', $val->ofs_h, $val->ofs_a);
ExpectationAverage::filter($result, 'liga', 'crd', $val->crd_h, $val->crd_a);
ExpectationAverage::filter($result, 'liga', 'snt', $val->snt_h, $val->snt_a);
ExpectationAverage::filter($result, 'liga', 'tsh', $val->tsh_h, $val->tsh_a);
}
$bets = ['gls', 'fls', 'ofs', 'crd', 'snt', 'tsh'];
if ($result) {
foreach ($bets as $bet) {
$expectations[$bet.'_liga_season']['home'] = round(array_sum($result['liga'][$bet]['home']) / \count($result['liga'][$bet]['home']), 1);
$expectations[$bet.'_liga_season']['away'] = round(array_sum($result['liga'][$bet]['away']) / \count($result['liga'][$bet]['away']), 1);
}
} else {
foreach ($bets as $bet) {
$expectations[$bet.'_liga_season']['home'] = 0;
$expectations[$bet.'_liga_season']['away'] = 0;
}
}
$expectations['gls_liga_season']['name'] = 'Goals';
$expectations['fls_liga_season']['name'] = 'Fouls';
$expectations['ofs_liga_season']['name'] = 'Offsides';
$expectations['crd_liga_season']['name'] = 'Cards';
$expectations['snt_liga_season']['name'] = 'Shots on Target';
$expectations['tsh_liga_season']['name'] = 'Total Shots';
$expectations['active_season'] = $active_season;
}
}
}
+114
View File
@@ -0,0 +1,114 @@
<?php
namespace App\Filament\Widgets\Boxes;
use App\Filament\Pages\Selections\Helper\GetSeason;
use App\Filament\Widgets\Boxes\Helper\ExpectationAverage;
use App\Models\StatistikoEvent;
class AverageTeam
{
public static function load(array &$expectations, array $filter)
{
$tournament_id = (int) $filter['league_id'] ?? 0;
$team_position = $filter['team_position'];
$team_id = (int) $filter['team_id'] ?? 0;
$season = $filter['season'] ?? 0;
$season_or_date = $filter['season_or_date'] ?? 'season';
$start = $filter['start_date'] ?? 0;
$end = $filter['end_date'] ?? 0;
$seasonmode = $filter['seasonmode'];
if ($season_or_date != 'season') {
$season = 0;
} else {
$end = 0;
$start = 0;
$season = GetSeason::load($season, $seasonmode);
}
$active_season = GetSeason::active($seasonmode);
// Average made and got for team selected
// Box 1
// for selected Date or Time or All
// Box 2
// fixed to active season
// Box 3 wie 2
// fixed to active season but all league
$res = StatistikoEvent::where('league_id', $tournament_id)
->when($start, function ($query) use ($start) {
return $query->whereDate('starttime', '>=', $start);
})->when($end, function ($query) use ($end) {
return $query->whereDate('starttime', '<=', $end);
})->when($season, function ($query) use ($season) {
return $query->whereIn('season', $season);
})->when($team_id, function ($query) use ($team_position, $team_id) {
switch ($team_position) {
case 'home':
return $query->where('home_id', $team_id);
case 'away':
return $query->where('away_id', $team_id);
default:
return $query->orWhere('home_id', $team_id)
->orWhere('away_id', '=', $team_id);
}
})->get();
$result = [];
if ($res) {
// 1) la media dei falli di tutte le partite giocate dal Flamengo
// (esempio, giocate 6 partite con falli 17-11-15-14-15-12, la media è 14)
// 2) la media dei falli di tutte le partite giocate nel campionato Brasiliano
// (esempio 6 giornate giocate = 60 partite quindi 120 squadre, quindi 120 dati tipo 17-12-12-15-8-15-13-21-...,
// quindi la media di questi 120 dati)
foreach ($res as $val) {
if ($team_position == 'home' && $team_id == $val->home_id) {
ExpectationAverage::filter($result, 'team', 'gls', $val->gls_h, $val->gls_a);
ExpectationAverage::filter($result, 'team', 'fls', $val->fls_h, $val->fls_a);
ExpectationAverage::filter($result, 'team', 'ofs', $val->ofs_h, $val->ofs_a);
ExpectationAverage::filter($result, 'team', 'crd', $val->crd_h, $val->crd_a);
ExpectationAverage::filter($result, 'team', 'snt', $val->snt_h, $val->snt_a);
ExpectationAverage::filter($result, 'team', 'tsh', $val->tsh_h, $val->tsh_a);
} elseif ($team_position == 'away' && $team_id == $val->away_id) {
ExpectationAverage::filter($result, 'team', 'gls', $val->gls_a, $val->gls_h);
ExpectationAverage::filter($result, 'team', 'fls', $val->fls_a, $val->fls_h);
ExpectationAverage::filter($result, 'team', 'ofs', $val->ofs_a, $val->ofs_h);
ExpectationAverage::filter($result, 'team', 'crd', $val->crd_a, $val->crd_h);
ExpectationAverage::filter($result, 'team', 'snt', $val->snt_a, $val->snt_h);
ExpectationAverage::filter($result, 'team', 'tsh', $val->tsh_a, $val->tsh_h);
} else {
ExpectationAverage::filter($result, 'team', 'gls', $val->gls_a, $val->gls_h);
ExpectationAverage::filter($result, 'team', 'fls', $val->fls_a, $val->fls_h);
ExpectationAverage::filter($result, 'team', 'ofs', $val->ofs_a, $val->ofs_h);
ExpectationAverage::filter($result, 'team', 'crd', $val->crd_a, $val->crd_h);
ExpectationAverage::filter($result, 'team', 'snt', $val->snt_a, $val->snt_h);
ExpectationAverage::filter($result, 'team', 'tsh', $val->tsh_a, $val->tsh_h);
}
}
$bets = ['gls', 'fls', 'ofs', 'crd', 'snt', 'tsh'];
if ($result) {
foreach ($bets as $bet) {
$expectations[$bet.'_team']['home'] = round(array_sum($result['team'][$bet]['home']) / \count($result['team'][$bet]['home']), 1);
$expectations[$bet.'_team']['away'] = round(array_sum($result['team'][$bet]['away']) / \count($result['team'][$bet]['away']), 1);
}
} else {
foreach ($bets as $bet) {
$expectations[$bet.'_team']['home'] = 0;
$expectations[$bet.'_team']['away'] = 0;
}
}
$expectations['gls_team']['name'] = 'Goals';
$expectations['fls_team']['name'] = 'Fouls';
$expectations['ofs_team']['name'] = 'Offsides';
$expectations['crd_team']['name'] = 'Cards';
$expectations['snt_team']['name'] = 'Shots on Target';
$expectations['tsh_team']['name'] = 'Total Shots';
}
}
}
@@ -0,0 +1,94 @@
<?php
namespace App\Filament\Widgets\Boxes;
use App\Filament\Pages\Selections\Helper\GetSeason;
use App\Filament\Widgets\Boxes\Helper\ExpectationAverage;
use App\Models\StatistikoEvent;
class AverageTeamSeason
{
public static function load(array &$expectations, array $filter)
{
$tournament_id = (int) $filter['league_id'] ?? 0;
$team_position = $filter['team_position'];
$team_id = (int) $filter['team_id'] ?? 0;
$seasonmode = $filter['seasonmode'];
$active_season = GetSeason::active($seasonmode);
// Box 2
// average made and got for team selected
// fixed to active season
$res = StatistikoEvent::where('league_id', $tournament_id)
->when($active_season, function ($query) use ($active_season) {
return $query->where('season', $active_season);
})->when($team_id, function ($query) use ($team_position, $team_id) {
switch ($team_position) {
case 'home':
return $query->where('home_id', $team_id);
case 'away':
return $query->where('away_id', $team_id);
default:
return $query->orWhere('home_id', $team_id)
->orWhere('away_id', '=', $team_id);
}
})->get();
$result = [];
if ($res) {
// 1) la media dei falli di tutte le partite giocate dal Flamengo
// (esempio, giocate 6 partite con falli 17-11-15-14-15-12, la media è 14)
// 2) la media dei falli di tutte le partite giocate nel campionato Brasiliano
// (esempio 6 giornate giocate = 60 partite quindi 120 squadre, quindi 120 dati tipo 17-12-12-15-8-15-13-21-...,
// quindi la media di questi 120 dati)
foreach ($res as $val) {
if ($team_position == 'home' && $team_id == $val->home_id) {
ExpectationAverage::filter($result, 'team', 'gls', $val->gls_h, $val->gls_a);
ExpectationAverage::filter($result, 'team', 'fls', $val->fls_h, $val->fls_a);
ExpectationAverage::filter($result, 'team', 'ofs', $val->ofs_h, $val->ofs_a);
ExpectationAverage::filter($result, 'team', 'crd', $val->crd_h, $val->crd_a);
ExpectationAverage::filter($result, 'team', 'snt', $val->snt_h, $val->snt_a);
ExpectationAverage::filter($result, 'team', 'tsh', $val->tsh_h, $val->tsh_a);
} elseif ($team_position == 'away' && $team_id == $val->away_id) {
ExpectationAverage::filter($result, 'team', 'gls', $val->gls_a, $val->gls_h);
ExpectationAverage::filter($result, 'team', 'fls', $val->fls_a, $val->fls_h);
ExpectationAverage::filter($result, 'team', 'ofs', $val->ofs_a, $val->ofs_h);
ExpectationAverage::filter($result, 'team', 'crd', $val->crd_a, $val->crd_h);
ExpectationAverage::filter($result, 'team', 'snt', $val->snt_a, $val->snt_h);
ExpectationAverage::filter($result, 'team', 'tsh', $val->tsh_a, $val->tsh_h);
} else {
ExpectationAverage::filter($result, 'team', 'gls', $val->gls_a, $val->gls_h);
ExpectationAverage::filter($result, 'team', 'fls', $val->fls_a, $val->fls_h);
ExpectationAverage::filter($result, 'team', 'ofs', $val->ofs_a, $val->ofs_h);
ExpectationAverage::filter($result, 'team', 'crd', $val->crd_a, $val->crd_h);
ExpectationAverage::filter($result, 'team', 'snt', $val->snt_a, $val->snt_h);
ExpectationAverage::filter($result, 'team', 'tsh', $val->tsh_a, $val->tsh_h);
}
}
$bets = ['gls', 'fls', 'ofs', 'crd', 'snt', 'tsh'];
if ($result) {
foreach ($bets as $bet) {
$expectations[$bet.'_team_season']['home'] = round(array_sum($result['team'][$bet]['home']) / \count($result['team'][$bet]['home']), 1);
$expectations[$bet.'_team_season']['away'] = round(array_sum($result['team'][$bet]['away']) / \count($result['team'][$bet]['away']), 1);
}
} else {
foreach ($bets as $bet) {
$expectations[$bet.'_team_season']['home'] = 0;
$expectations[$bet.'_team_season']['away'] = 0;
}
}
$expectations['gls_team_season']['name'] = 'Goals';
$expectations['fls_team_season']['name'] = 'Fouls';
$expectations['ofs_team_season']['name'] = 'Offsides';
$expectations['crd_team_season']['name'] = 'Cards';
$expectations['snt_team_season']['name'] = 'Shots on Target';
$expectations['tsh_team_season']['name'] = 'Total Shots';
$expectations['active_season'] = $active_season;
}
}
}
@@ -0,0 +1,104 @@
<?php
namespace App\Filament\Widgets\Boxes;
use App\Filament\Widgets\Boxes\Helper\ExpectationCalculation;
use App\Filament\Widgets\Boxes\Helper\ExpectationCollecting;
use App\Filament\Widgets\Charts\LoadEvents\LoadEventsQueryAll;
use App\Utilities\Round;
class ExpectationsTeam
{
public static function load(array &$expectations, array $filter, object $match)
{
/**
* STATTISTIC DATA
*/
$team_id = (int) $filter['team_id'] ?? 0;
$team_position = $filter['team_position'];
$similar_past_matches = $filter['similar_past_matches'];
if ($similar_past_matches != 'none') {
$team_id = 0;
$team_position = '';
$home_team = $match->home->ss_team_name;
$away_team = $match->away->ss_team_name;
} else {
$home_team = 'In Favour';
$away_team = 'Against';
}
$res = LoadEventsQueryAll::load($filter, $match);
$count_events = $res->count();
if (! $res) {
return [];
}
$tmp = [];
foreach ($res as $value) {
ExpectationCollecting::sort($tmp, 'gls', $value->home_id, $value->away_id, $value->gls_h, $value->gls_a, $match);
ExpectationCollecting::sort($tmp, 'fls', $value->home_id, $value->away_id, $value->fls_h, $value->fls_a, $match);
ExpectationCollecting::sort($tmp, 'ofs', $value->home_id, $value->away_id, $value->ofs_h, $value->ofs_a, $match);
ExpectationCollecting::sort($tmp, 'crd', $value->home_id, $value->away_id, $value->crd_h, $value->crd_a, $match);
ExpectationCollecting::sort($tmp, 'snt', $value->home_id, $value->away_id, $value->snt_h, $value->snt_a, $match);
ExpectationCollecting::sort($tmp, 'tsh', $value->home_id, $value->away_id, $value->tsh_h, $value->tsh_a, $match);
ExpectationCollecting::sort($tmp, 'crn', $value->home_id, $value->away_id, $value->crn_h, $value->crn_a, $match);
}
$expectations = ExpectationCalculation::calc($tmp);
$expectations['gls']['name'] = 'Goals';
$expectations['fls']['name'] = 'Fouls';
$expectations['ofs']['name'] = 'Offsides';
$expectations['crd']['name'] = 'Cards';
$expectations['snt']['name'] = 'Shots on Target';
$expectations['tsh']['name'] = 'Total Shots';
$expectations['home'] = $home_team;
$expectations['away'] = $away_team;
$expectations += ['win_count' => 0, 'draw_count' => 0, 'lost_count' => 0];
foreach ($res as $value) {
if ($team_id && $team_position == 'home') {
switch ($value['result_code']) {
case '1':
$expectations['win_count']++;
break;
case 'X':
$expectations['draw_count']++;
break;
case '2':
$expectations['lost_count']++;
break;
}
} elseif ($team_id && $team_position == 'away') {
switch ($value['result_code']) {
case '1':
$expectations['win_count']++;
break;
case 'X':
$expectations['draw_count']++;
break;
case '2':
$expectations['lost_count']++;
break;
}
} else {
switch ($value['result_code']) {
case '1':
$expectations['win_count']++;
break;
case 'X':
$expectations['draw_count']++;
break;
case '2':
$expectations['lost_count']++;
break;
}
}
}
$expectations['win_odd'] = $expectations['win_count'] ? number_format(Round::odd($count_events / $expectations['win_count']), 2) : 0;
$expectations['draw_odd'] = $expectations['draw_count'] ? number_format(Round::odd($count_events / $expectations['draw_count']), 2) : 0;
$expectations['lost_odd'] = $expectations['lost_count'] ? number_format(Round::odd($count_events / $expectations['lost_count']), 2) : 0;
$expectations['count_events'] = $count_events;
}
}
@@ -0,0 +1,12 @@
<?php
namespace App\Filament\Widgets\Boxes\Helper;
class ExpectationAverage
{
public static function filter(array &$result, string $type, string $bettype, float $val_home, float $val_away)
{
$result[$type][$bettype]['home'][] = (int) $val_home;
$result[$type][$bettype]['away'][] = (int) $val_away;
}
}
@@ -0,0 +1,54 @@
<?php
namespace App\Filament\Widgets\Boxes\Helper;
use App\Models\StatistikoConfig;
class ExpectationCalculation
{
public static function calc(array $expectations)
{
$summen = [];
$config = StatistikoConfig::pluck('value', 'varname');
foreach ($config as $name => $value) {
if (isset($expectations[$name])) {
$summen[$name]['sum'] = array_sum($expectations[$name]) * $value;
$summen[$name]['cnt'] = \count($expectations[$name]);
} else {
$summen[$name]['sum'] = 0;
$summen[$name]['cnt'] = 1;
}
}
$summen2 = [];
$bets = ['gls', 'fls', 'ofs', 'crd', 'snt', 'tsh'];
foreach ($bets as $name) {
$summen2[$name]['home']['sum'] = 0;
$summen2[$name]['home']['cnt'] = 0;
$summen2[$name]['away']['sum'] = 0;
$summen2[$name]['away']['cnt'] = 0;
}
foreach ($summen as $key => $value) {
foreach ($bets as $name) {
if (strpos($key, $name) !== false) {
if (strpos($key, 'home') !== false) {
$summen2[$name]['home']['sum'] += $value['sum'];
$summen2[$name]['home']['cnt'] += +$value['cnt'];
}
if (strpos($key, 'away') !== false) {
$summen2[$name]['away']['sum'] += $value['sum'];
$summen2[$name]['away']['cnt'] += +$value['cnt'];
}
}
}
}
$asp_result = [];
foreach ($summen2 as $bettype => $value) {
$asp_result[$bettype]['home'] = round($value['home']['sum'] / $value['home']['cnt'], 1);
$asp_result[$bettype]['away'] = round($value['away']['sum'] / $value['away']['cnt'], 1);
}
return $asp_result;
}
}
@@ -0,0 +1,46 @@
<?php
namespace App\Filament\Widgets\Boxes\Helper;
class ExpectationCollecting
{
public static function sort(array &$result, string $type, int $home_id, int $away_id, float $val_home, float $val_away, object $match)
{
if ($home_id == $match->home_id) {
$result[$type.'_home_made_total'][] = $val_home;
$result[$type.'_home_made_home'][] = $val_home;
$result[$type.'_home_got_total'][] = $val_away;
$result[$type.'_home_got_home'][] = $val_away;
} elseif ($away_id == $match->home_id) {
$result[$type.'_home_made_total'][] = $val_away;
$result[$type.'_home_got_total'][] = $val_away;
} elseif ($home_id == $match->away_id) {
$result[$type.'_home_made_total'][] = $val_away;
$result[$type.'_home_got_total'][] = $val_away;
} elseif ($away_id == $match->away_id) {
$result[$type.'_home_made_total'][] = $val_home;
$result[$type.'_home_made_home'][] = $val_home;
$result[$type.'_home_got_total'][] = $val_away;
$result[$type.'_home_got_home'][] = $val_home;
}
if ($away_id == $match->away_id) {
$result[$type.'_away_made_total'][] = $val_away;
$result[$type.'_away_made_home'][] = $val_away;
$result[$type.'_away_got_total'][] = $val_home;
$result[$type.'_away_got_home'][] = $val_home;
} elseif ($home_id == $match->away_id) {
$result[$type.'_away_made_total'][] = $val_home;
$result[$type.'_away_got_total'][] = $val_home;
} elseif ($away_id == $match->home_id) {
$result[$type.'_away_made_total'][] = $val_home;
$result[$type.'_away_got_total'][] = $val_home;
} elseif ($home_id == $match->home_id) {
$result[$type.'_away_made_total'][] = $val_away;
$result[$type.'_away_made_home'][] = $val_away;
$result[$type.'_away_got_total'][] = $val_home;
$result[$type.'_away_got_home'][] = $val_away;
}
}
}
@@ -0,0 +1,49 @@
<?php
namespace App\Filament\Widgets\Boxes;
use App\Models\StatisticFixtures;
class LoadEventsBoxes
{
public static function load(array $filter, bool $hasdots)
{
$league_id = (int) $filter['league_id'] ?? 0;
$match_id = (int) $filter['match_id'] ?? 0;
$team_id = (int) $filter['team_id'] ?? 0;
$similar_past_matches = $filter['similar_past_matches'];
if (! $league_id) {
return [];
}
if (! $match_id) {
return [];
}
$match = StatisticFixtures::with('home')->with('away')->where('id', (int) $match_id)->first();
if (! $match) {
return [];
}
$expectations = [];
ExpectationsTeam::load($expectations, $filter, $match);
if ($team_id == $match->home_id) {
$expectations['active_team'] = $match->home->ss_team_name;
} else {
$expectations['active_team'] = $match->away->ss_team_name;
}
/**
* LEAGUE AVERAGES
*/
if ($team_id != 0 && $similar_past_matches == 'none') {
AverageTeam::load($expectations, $filter);
AverageTeamSeason::load($expectations, $filter);
AverageLeagueSeason::load($expectations, $filter);
}
return $expectations;
}
}
+191
View File
@@ -0,0 +1,191 @@
<?php
namespace App\Filament\Widgets;
use App\Filament\Widgets\Boxes\LoadEventsBoxes;
use Filament\Widgets\Concerns\InteractsWithPageFilters;
use Filament\Widgets\StatsOverviewWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Illuminate\Support\HtmlString;
use Livewire\Attributes\Reactive;
// use Illuminate\Support\Facades\Log;
class BoxesBettypeAll extends StatsOverviewWidget
{
use InteractsWithPageFilters;
protected ?string $pollingInterval = null;
protected int|array|null $columns = null;
#[Reactive]
public ?array $filters = [];
public ?int $count;
public function mount(array $filters)
{
$this->filters = $filters;
}
protected function getStats(): array
{
$data = LoadEventsBoxes::load($this->filters, false);
$similar_past_matches = $this->filters['similar_past_matches'];
$team_position = $this->filters['team_position'];
$team_position = in_array($this->filters['team_position'], ['home', 'away']) ? ucfirst($this->filters['team_position']) : 'Both Position';
if (! $data) {
return [];
}
// dd($this->filters);
// BOX TOTAL
$count_events = $data['count_events'];
$boxes = [];
$boxes[] = Stat::make('Total', self::template_total($count_events))
->description(fn() => $similar_past_matches == 'none' ? 'Team Selected' : 'Similar Past Matches')
->extraAttributes(['x-init' => "animate('number-of-events', $count_events);", 'class' => 'box-success justify-center']);
// BOX 1X2
$win = $data['win_odd'];
$draw = $data['draw_odd'];
$lost = $data['lost_odd'];
$boxes[] = Stat::make('Odds', self::template_odds($data, $win, $draw, $lost))
->description('Expectations')
->extraAttributes(['x-init' => "animate('win', $win, 2); animate('draw', $draw, 2); animate('lost', $lost, 2)", 'class' => 'box-blank']);
// BOX EXPECTED
if (isset($data['gls'])) {
$boxes[] = Stat::make('Expected', self::template_tabelle_1($data))
->extraAttributes(['class' => 'box-info'])
->description('Home - Away');
}
// BOX AVERAGE
if (isset($data['gls_team'])) {
$boxes[] = Stat::make('Average ' . $data['active_team'], self::template_tabelle_2($data))
->extraAttributes(['class' => 'box-blank'])
->description($team_position);
}
// BOX AVERAGE WITH TEAM FIXED TO ACTIVE SEASON
if (isset($data['gls_team_season'])) {
$boxes[] = Stat::make('Average ' . $data['active_team'], self::template_tabelle_3($data))
->extraAttributes(['class' => 'box-blank'])
->description('Season ' . $data['active_season']);
}
// BOX AVERAGE ALL LEAGUE FIXED TO ACTIVE SEASON
if (isset($data['gls_liga_season'])) {
$boxes[] = Stat::make('League Average', self::template_tabelle_4($data))
->extraAttributes(['class' => 'box-blank'])
->description('Season ' . $data['active_season']);
}
$this->columns = [
'default' => 1,
'sm' => 2,
'md' => 3,
'xl' => 6,
];
return $boxes;
}
// TEAMPLATE TOTAL EVENTS
protected function template_total(float $total_home): HtmlString
{
return new HtmlString('<div class="grid grid-cols-1 justify-center font-bold text-2xl">
<span class="text-center" id="number-of-events">' . $total_home . '</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">Events</span>
</div>');
}
// TEAMPLATE ODDS
protected function template_odds(array &$data, float $win, float $draw, float $lost): HtmlString
{
if ($this->filters['similar_past_matches'] != 'none') {
$name_win = '<b>1</b> (' . $data['win_count'] . ')';
$name_draw = '<b>X</b> (' . $data['draw_count'] . ')';
$name_lost = '<b>2</b> (' . $data['lost_count'] . ')';
} else {
$name_win = '<b>Win</b> (' . $data['win_count'] . ')';
$name_draw = '<b>Draw</b> (' . $data['draw_count'] . ')';
$name_lost = '<b>Lost</b> (' . $data['lost_count'] . ')';
}
return new HtmlString('<div class="grid grid-cols-3 gap-3">
<span class="text-center font-bold text-xl" id="win">' . number_format($win, 2) . '</span>
<span class="text-center font-bold text-xl" id="draw">' . number_format($draw, 2) . '</span>
<span class="text-center font-bold text-xl" id="lost">' . number_format($lost, 2) . '</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">' . $name_win . '</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">' . $name_draw . '</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">' . $name_lost . '</span>
</div>');
}
// TEAMPLATE BOX 1
protected function template_tabelle_1(array $data): HtmlString
{
$bets = ['gls', 'fls', 'ofs', 'crd', 'snt', 'tsh'];
$str = '<div class="grid grid-cols-4 gap-0.5 text-xs">';
// $str .= '<div class="col-span-2"></div><div>Home</div><div>Away</div>';
foreach ($bets as $name) {
$str .= '<div class="font-normal text-left col-span-2">' . $data[$name]['name'] . '</div>';
$str .= '<div class="text-right">' . number_format($data[$name]['home'], 1) . '</div>';
$str .= '<div class="text-right">' . number_format($data[$name]['away'], 1) . '</div>';
}
$str .= '</div>';
return new HtmlString($str);
}
protected function template_tabelle_2(array $data): HtmlString
{
$bets = ['gls_team', 'fls_team', 'ofs_team', 'crd_team', 'snt_team', 'tsh_team'];
$str = '<div class="grid grid-cols-4 gap-0.5 text-xs">';
// $str .= '<div class="col-span-2"></div><div>Home</div><div>Away</div>';
foreach ($bets as $name) {
$str .= '<div class="font-normal text-left col-span-2">' . $data[$name]['name'] . '</div>';
$str .= '<div class="text-right">' . number_format($data[$name]['home'], 1) . '</div>';
$str .= '<div class="text-right">' . number_format($data[$name]['away'], 1) . '</div>';
}
$str .= '</div>';
return new HtmlString($str);
}
protected function template_tabelle_3(array $data): HtmlString
{
$bets = ['gls_team_season', 'fls_team_season', 'ofs_team_season', 'crd_team_season', 'snt_team_season', 'tsh_team_season'];
$str = '<div class="grid grid-cols-4 gap-0.5 text-xs">';
// $str .= '<div class="col-span-2"></div><div>Home</div><div>Away</div>';
foreach ($bets as $name) {
$str .= '<div class="font-normal text-left col-span-2">' . $data[$name]['name'] . '</div>';
$str .= '<div class="text-right">' . number_format($data[$name]['home'], 1) . '</div>';
$str .= '<div class="text-right">' . number_format($data[$name]['away'], 1) . '</div>';
}
$str .= '</div>';
return new HtmlString($str);
}
protected function template_tabelle_4(array $data): HtmlString
{
$bets = ['gls_liga_season', 'fls_liga_season', 'ofs_liga_season', 'crd_liga_season', 'snt_liga_season', 'tsh_liga_season'];
$str = '<div class="grid grid-cols-4 gap-0.5 text-xs">';
// $str .= '<div class="col-span-2"></div><div>Home</div><div>Away</div>';
foreach ($bets as $name) {
$str .= '<div class="font-normal text-left col-span-2">' . $data[$name]['name'] . '</div>';
$str .= '<div class="text-right">' . number_format($data[$name]['home'], 1) . '</div>';
$str .= '<div class="text-right">' . number_format($data[$name]['away'], 1) . '</div>';
}
$str .= '</div>';
return new HtmlString($str);
}
}
+345
View File
@@ -0,0 +1,345 @@
<?php
namespace App\Filament\Widgets;
use App\Filament\Widgets\Charts\HelperStatisticType;
use App\Filament\Widgets\Charts\LoadEvents;
use App\Utilities\Round;
use Filament\Widgets\Concerns\InteractsWithPageFilters;
use Filament\Widgets\StatsOverviewWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Illuminate\Support\Carbon;
use Illuminate\Support\HtmlString;
use Livewire\Attributes\Reactive;
// use Illuminate\Support\Facades\Log;
class BoxesBettypeSingle extends StatsOverviewWidget
{
use InteractsWithPageFilters;
protected ?string $pollingInterval = null;
protected int|array|null $columns = null;
#[Reactive]
public ?array $filters = [];
public ?int $count;
public function mount(array $filters)
{
$this->filters = $filters;
}
protected function getStats(): array
{
$data = LoadEvents::load($this->filters, false);
$team_id = (int) $this->filters['team_id'] ?? 0;
$season = $this->filters['season'] ?? 0;
$season_or_date = $this->filters['season_or_date'];
$similar_past_matches = $this->filters['similar_past_matches'];
$date_events = '';
switch ($season_or_date) {
case 'season':
if ($season) {
$date_events = implode(', ', $season);
} else {
$date_events = 'Current Season';
}
break;
default:
$start = $this->filters['start_date'] ?? 0;
$end = $this->filters['end_date'] ?? 0;
$tmp = [];
if ($start) {
$tmp[] = 'From: '.Carbon::createFromDate($start)->format('Y-m-d');
}
if ($end) {
$tmp[] = 'To: '.Carbon::createFromDate($end)->format('Y-m-d');
}
if ($tmp) {
$date_events = implode('<br>', $tmp);
} else {
$date_events = 'All Dates';
}
break;
}
$team_position = $this->filters['team_position'] ? ucfirst($this->filters['team_position']) : 'Position Both';
if (! $data) {
return [];
}
$statistic_type = HelperStatisticType::get($this->filters);
if (! isset($data['datasets'][0])) {
$data['datasets'][0]['data'] = [];
$data['datasets'][1]['data'] = [];
$total_home = 0;
$total_away = 0;
$summe_home = 0;
$summe_away = 0;
$home_team = '';
$away_team = '';
} else {
$arr_home = $data['datasets'][0]['data'];
$arr_away = $data['datasets'][1]['data'];
$total_home = count($arr_home);
$total_away = count($arr_away);
$summe_home = array_sum($arr_home);
$summe_away = array_sum($arr_away);
$home_team = $data['home_team'];
$away_team = $data['away_team'];
}
if (isset($data['results'])) {
$win = $data['results']['w'] ? number_format(Round::odd($total_home / $data['results']['w']), 2) : 0;
$draw = $data['results']['d'] ? number_format(Round::odd($total_home / $data['results']['d']), 2) : 0;
$lost = $data['results']['l'] ? number_format(Round::odd($total_home / $data['results']['l']), 2) : 0;
} else {
$win = 0;
$draw = 0;
$lost = 0;
}
if ($total_home) {
$value_home = number_format($summe_home / $total_home, 1);
} else {
$value_home = 0;
}
if ($total_away) {
$value_away = number_format($summe_away / $total_away, 1);
} else {
$value_away = 0;
}
$max_boxes = 3;
$average_team_home = 0;
$average_team_away = 0;
$average_league_home = 0;
$average_league_away = 0;
$expectations_home = 0;
$expectations_away = 0;
$expectations_home = $data['expectations_home'] ?? 0;
$expectations_away = $data['expectations_away'] ?? 0;
foreach ($data['datasets'] as $value) {
if ($value['label'] == 'Average Team') {
$average_team_home = $value['average_team_home'] ?? 0;
$average_team_away = $value['average_team_away'] ?? 0;
$max_boxes++;
}
if ($value['label'] == 'Average League') {
$average_league_home = $value['average_league_home'] ?? 0;
$average_league_away = $value['average_league_away'] ?? 0;
$max_boxes++;
}
}
// i box 1 3 4 5 devono sempre avere 1 decimale, se il valore è 12 fai scrivere 12.0
// il box 2 sempre un numero intero
// il box 6 sempre a due decimali, se trovi 2 fai scrivere 2.00
$boxes = [];
if ($similar_past_matches != 'none') {
// BOX 2
$boxes[] = Stat::make('Total', self::template_box2($total_home))
->description(fn () => $similar_past_matches == 'all' ? 'SPM Source Database' : 'SPM Source League')
->extraAttributes([
'x-init' => "animate('number-of-events', $total_home);",
'class' => 'box-info',
]);
// BOX 3
$boxes[] = Stat::make('Average '.$statistic_type, self::template_box3('Home', 'Away', $value_home, $value_away))
->description('Team '.$team_position)
->extraAttributes([
'x-init' => "animate('average_home', $value_home, 1); animate('average_away', $value_away, 1)",
'class' => 'box-success',
]);
// BOX 6
$boxes[] = Stat::make('Odds', self::templateOdds($data, $win, $draw, $lost))
->description($team_position)
->extraAttributes([
'x-init' => "animate('win', $win); animate('draw', $draw); animate('lost', $lost)",
'class' => 'box-purple',
]);
} else {
// BOX 1
$boxes[] = Stat::make($statistic_type, self::template_box1($expectations_home, $expectations_away))
->description('Expected Values')
->extraAttributes([
'x-init' => "animate('expectations_home', $expectations_home, 1); animate('expectations_away', $expectations_away, 1)",
'class' => 'box-yellow',
]);
if ($team_id) {
// BOX 2
$boxes[] = Stat::make('Total', self::template_box2($total_home))
->description(fn () => new HtmlString($date_events))
->extraAttributes([
'x-init' => "animate('number-of-events', $total_home);",
'class' => 'box-info',
]);
// BOX 3
$boxes[] = Stat::make('Average '.$statistic_type, self::template_box3($home_team, $away_team, $value_home, $value_away))
->description('Team '.$team_position)
->extraAttributes([
'x-init' => "animate('average_home', $value_home, 1); animate('average_away', $value_away, 1)",
'class' => 'box-success',
]);
// BOX 4
$boxes[] = Stat::make('Average '.$statistic_type, self::template_box4($home_team, $away_team, $average_team_home, $average_team_away))
->description('Team Season')
->extraAttributes([
'x-init' => "animate('av_team_home', $average_team_home, 1); animate('av_team_away', $average_team_away, 1)",
'class' => 'box-success',
]);
// BOX 5
$boxes[] = Stat::make('Average '.$statistic_type, self::template_box5('Home', 'Away', $average_league_home, $average_league_away))
->description('League Season')
->extraAttributes([
'x-init' => "animate('av_league_home', $average_league_home, 1); animate('av_league_away', $average_league_away, 1)",
'class' => 'box-success',
]);
// BOX 6
$boxes[] = Stat::make('Odds', self::templateOdds($data, $win, $draw, $lost))
->description($team_position)
->extraAttributes([
'x-init' => "animate('win', $win, 2); animate('draw', $draw, 2); animate('lost', $lost, 2)",
'class' => 'box-purple',
]);
}
}
$this->columns = [
'default' => 1,
'sm' => 2,
'md' => 3,
'xl' => 6,
];
return $boxes;
}
// TEAMPLATE BOX 1
protected function template_box1(float $expectations_home, float $expectations_away): HtmlString
{
return new HtmlString('<div class="grid grid-cols-2 justify-center font-bold text-2xl">
<span class="text-center" id="expectations_home">'.$expectations_home.'</span>
<span class="text-center" id="expectations_away">'.$expectations_away.'</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">Home</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">Away</span>
</div>');
}
// TEAMPLATE BOX 2
protected function template_box2(float $total_home): HtmlString
{
return new HtmlString('<div class="grid grid-cols-1 justify-center font-bold text-2xl">
<span class="text-center" id="number-of-events">'.$total_home.'</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">Events</span>
</div>');
}
// TEAMPLATE BOX 3
protected function template_box3(string $home_team, string $away_team, float $value_home, float $value_away): HtmlString
{
return new HtmlString('<div class="grid grid-cols-2 justify-center font-bold text-2xl">
<span class="text-center" id="average_home">'.$value_home.'</span>
<span class="text-center" id="average_away">'.$value_away.'</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">'.$home_team.'</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">'.$away_team.'</span>
</div>');
}
// TEAMPLATE BOX 4
protected function template_box4(string $home_team, string $away_team, float $value_home, float $value_away): HtmlString
{
return new HtmlString('<div class="grid grid-cols-2 justify-center font-bold text-2xl">
<span class="text-center" id="av_team_home">'.$value_home.'</span>
<span class="text-center" id="av_team_away">'.$value_away.'</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">'.$home_team.'</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">'.$away_team.'</span>
</div>');
}
// TEAMPLATE BOX 5
protected function template_box5(string $home_team, string $away_team, float $value_home, float $value_away): HtmlString
{
return new HtmlString('<div class="grid grid-cols-2 justify-center font-bold text-2xl">
<span class="text-center" id="av_league_home">'.$value_home.'</span>
<span class="text-center" id="av_league_away">'.$value_away.'</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">'.$home_team.'</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">'.$away_team.'</span>
</div>');
}
// TEAMPLATE BOX 6 odds
protected function templateOdds(array &$data, float $win, float $draw, float $lost): HtmlString
{
if ($data['similar_past_matches'] != 'none') {
$name_win = '<b>1</b> ('.$data['results']['w'].')';
$name_draw = '<b>X</b> ('.$data['results']['d'].')';
$name_lost = '<b>2</b> ('.$data['results']['l'].')';
} else {
$name_win = '<b>Win</b> ('.$data['results']['w'].')';
$name_draw = '<b>Draw</b> ('.$data['results']['d'].')';
$name_lost = '<b>Lost</b> ('.$data['results']['l'].')';
}
return new HtmlString('<div class="grid grid-cols-3 justify-center">
<span class="text-center font-bold text-xl" id="win">'.number_format($win, 2).'</span>
<span class="text-center font-bold text-xl" id="draw">'.number_format($draw, 2).'</span>
<span class="text-center font-bold text-xl" id="lost">'.number_format($lost, 2).'</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">'.$name_win.'</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">'.$name_draw.'</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">'.$name_lost.'</span>
</div>');
}
protected function getMedian(array $arr)
{
sort($arr);
$size = count($arr);
if ($size % 2 == 0) {
// even
$m = ($size) / 2;
$m1 = $m - 1;
$m2 = $m;
// dd($m1, $m2, $arr);
// dd('GERADE', $arr, $size, $m, $m1, $m2);
if (isset($arr[$m1]) && isset($arr[$m2])) {
return round(($arr[$m1] + $arr[$m2]) / 2, 2);
}
} else {
// odd (add 1 because array starts with 0)
$m = (int) ceil($size / 2);
// dd($m, $arr);
// dd('UNGERADE', $m, $arr, $arr[$m]);
if (isset($arr[$m])) {
return $arr[$m];
}
}
}
}
+103
View File
@@ -0,0 +1,103 @@
<?php
namespace App\Filament\Widgets;
use App\Filament\Widgets\Charts\HelperStatisticType;
use App\Filament\Widgets\Charts\LoadEvents;
use Filament\Support\RawJs;
use Filament\Widgets\ChartWidget;
use Illuminate\Support\HtmlString;
use Livewire\Attributes\Reactive;
class ChartEvent extends ChartWidget
{
#[Reactive]
public ?array $filters = [];
public ?string $type = '';
protected ?string $pollingInterval = null;
protected $f;
public function getHeading(): HtmlString
{
return new HtmlString('
<span class="flex justify-between">
<span class="text-primary-700 dark:text-primary-400 flex flex-row gap-2">
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" fill="currentColor" viewBox="0 0 256 256"><path d="M232,64H208V48a8,8,0,0,0-8-8H56a8,8,0,0,0-8,8V64H24A16,16,0,0,0,8,80V96a40,40,0,0,0,40,40h3.65A80.13,80.13,0,0,0,120,191.61V216H96a8,8,0,0,0,0,16h64a8,8,0,0,0,0-16H136V191.58c31.94-3.23,58.44-25.64,68.08-55.58H208a40,40,0,0,0,40-40V80A16,16,0,0,0,232,64ZM48,120A24,24,0,0,1,24,96V80H48v32q0,4,.39,8Zm144-8.9c0,35.52-29,64.64-64,64.9a64,64,0,0,1-64-64V56H192ZM232,96a24,24,0,0,1-24,24h-.5a81.81,81.81,0,0,0,.5-8.9V80h24Z"></path></svg>
Events
</span>
<span>'.$this->type.'</span>
</span>
');
}
protected function getData(): array
{
$data = LoadEvents::load($this->filters, true);
$this->type = ucfirst(HelperStatisticType::get($this->filters));
if (isset($data['description'])) {
$this->description .= $data['description'];
}
return $data;
}
protected function getType(): string
{
return 'line';
}
protected function getOptions(): RawJs
{
return RawJs::make(<<<'JS'
{
interaction: {
intersect: false,
},
plugins: {
legend: {
position: 'left',
generateLabels: (chart) => {
const datasets = chart.data.datasets;
},
},
tooltip: {
callbacks: {
label: (context) => {
if(context.dataset.label == 'Average League' || context.dataset.label == 'Average Team'){
return [context.dataset.label+' '+context.dataset.data[0]];
}
else {
if(context.dataset.playing_date[context.dataIndex])
return [' '+context.parsed.y, ' '+context.dataset.playing_date[context.dataIndex], ' '+context.dataset.events[context.dataIndex], ' '+context.dataset.results_per_event[context.dataIndex]];
else
return [' '+context.parsed.y]
}
},
}
},
},
scales: {
x: {
title: {
display: true,
text: 'Number of days to date'
}
},
y: {
beginAtZero:true,
ticks: {
callback: function(value, index, ticks) {
return value % 1 === 0 ? value : '';
}
}
},
},
}
JS);
}
}
+99
View File
@@ -0,0 +1,99 @@
<?php
namespace App\Filament\Widgets;
use App\Filament\Widgets\Charts\HelperMoveingAverage;
use App\Filament\Widgets\Charts\HelperStatisticType;
use App\Filament\Widgets\Charts\LoadEvents;
use Filament\Support\RawJs;
use Filament\Widgets\ChartWidget;
use Illuminate\Support\HtmlString;
use Livewire\Attributes\Reactive;
class ChartEventMoAv extends ChartWidget
{
#[Reactive]
public ?array $filters = [];
public ?string $type = '';
protected ?string $pollingInterval = null;
public function getHeading(): HtmlString
{
return new HtmlString('
<span class="flex justify-between">
<span class="text-primary-700 dark:text-primary-400 flex flex-row gap-2">
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" fill="currentColor" viewBox="0 0 256 256"><path d="M232,64H208V48a8,8,0,0,0-8-8H56a8,8,0,0,0-8,8V64H24A16,16,0,0,0,8,80V96a40,40,0,0,0,40,40h3.65A80.13,80.13,0,0,0,120,191.61V216H96a8,8,0,0,0,0,16h64a8,8,0,0,0,0-16H136V191.58c31.94-3.23,58.44-25.64,68.08-55.58H208a40,40,0,0,0,40-40V80A16,16,0,0,0,232,64ZM48,120A24,24,0,0,1,24,96V80H48v32q0,4,.39,8Zm144-8.9c0,35.52-29,64.64-64,64.9a64,64,0,0,1-64-64V56H192ZM232,96a24,24,0,0,1-24,24h-.5a81.81,81.81,0,0,0,.5-8.9V80h24Z"></path></svg>
Events
</span>
<span>'.$this->type.' Moving Average</span>
</span>
');
}
protected function getData(): array
{
$data = LoadEvents::load($this->filters, false);
$this->type = ucfirst(HelperStatisticType::get($this->filters));
if ($data) {
if (isset($data['description'])) {
$this->description .= $data['description'];
}
HelperMoveingAverage::get($data);
}
return $data;
}
protected function getType(): string
{
return 'line';
}
protected function getOptions(): RawJs
{
return RawJs::make(<<<'JS'
{
interaction: {
intersect: false,
},
plugins: {
legend: {
position: 'left',
},
tooltip: {
callbacks: {
label: (context) => {
if(context.dataset.label == 'Average League' || context.dataset.label == 'Average Team'){
return [context.dataset.label+' '+context.dataset.data[0]];
}
else {
if(context.dataset.playing_date[context.dataIndex])
return [' '+context.parsed.y, ' '+context.dataset.playing_date[context.dataIndex], ' '+context.dataset.events[context.dataIndex], ' '+context.dataset.results_per_event[context.dataIndex]];
else
return [' '+context.parsed.y]
}
},
}
},
},
scales: {
x: {
title: {
display: true,
text: 'Number of days to date'
}
},
y: {
beginAtZero:false,
},
},
}
JS);
}
}
+79
View File
@@ -0,0 +1,79 @@
<?php
namespace App\Filament\Widgets;
use App\Filament\Widgets\Charts\LoadPerformance;
use Filament\Support\RawJs;
use Filament\Widgets\ChartWidget;
use Illuminate\Support\HtmlString;
use Livewire\Attributes\Reactive;
class ChartEventPerf extends ChartWidget
{
#[Reactive]
public ?array $filters = [];
public ?string $type = '';
protected ?string $pollingInterval = null;
public function getHeading(): HtmlString
{
return new HtmlString('
<span class="flex justify-between">
<span class="text-primary-700 dark:text-primary-400 flex flex-row gap-2">
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" fill="currentColor" viewBox="0 0 256 256"><path d="M232,64H208V48a8,8,0,0,0-8-8H56a8,8,0,0,0-8,8V64H24A16,16,0,0,0,8,80V96a40,40,0,0,0,40,40h3.65A80.13,80.13,0,0,0,120,191.61V216H96a8,8,0,0,0,0,16h64a8,8,0,0,0,0-16H136V191.58c31.94-3.23,58.44-25.64,68.08-55.58H208a40,40,0,0,0,40-40V80A16,16,0,0,0,232,64ZM48,120A24,24,0,0,1,24,96V80H48v32q0,4,.39,8Zm144-8.9c0,35.52-29,64.64-64,64.9a64,64,0,0,1-64-64V56H192ZM232,96a24,24,0,0,1-24,24h-.5a81.81,81.81,0,0,0,.5-8.9V80h24Z"></path></svg>
Events Performance
</span>
<span>'.$this->type.'</span>
</span>
');
}
protected function getData(): array
{
return LoadPerformance::load($this->filters, true);
}
protected function getType(): string
{
return 'line';
}
protected function getOptions(): RawJs
{
return RawJs::make(<<<'JS'
{
interaction: {
intersect: false,
},
plugins: {
legend: {
position: 'left',
maxWidth: ({chart}) => chart.width * 0.9
},
tooltip: {
callbacks: {
label: (context) => {
if(context.dataset.label == 'Average Team' || context.dataset.label == 'Average League' || context.dataset.label == 'Average Attak'|| context.dataset.label == 'Average Defence'|| context.dataset.label == 'Average Midfield'){
return [context.dataset.label+' '+context.dataset.data[0]];
}
else {
return [' '+context.parsed.y, ' '+context.dataset.playing_date[context.dataIndex], ' '+context.dataset.events[context.dataIndex], ' '+context.dataset.results_per_event[context.dataIndex]];
}
},
}
}
},
scales: {
x: {
title: {
display: true,
text: 'Number of days to date'
}
},
},
}
JS);
}
}
@@ -0,0 +1,87 @@
<?php
namespace App\Filament\Widgets;
use App\Filament\Widgets\Charts\HelperMoveingAveragePerformens;
use App\Filament\Widgets\Charts\LoadPerformance;
use Filament\Support\RawJs;
use Filament\Widgets\ChartWidget;
use Illuminate\Support\HtmlString;
use Livewire\Attributes\Reactive;
class ChartEventPerfMoAv extends ChartWidget
{
#[Reactive]
public ?array $filters = [];
public ?string $type = '';
protected ?string $pollingInterval = null;
public function getHeading(): HtmlString
{
return new HtmlString('
<span class="flex justify-between">
<span class="text-primary-700 dark:text-primary-400 flex flex-row gap-2">
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" fill="currentColor" viewBox="0 0 256 256"><path d="M232,64H208V48a8,8,0,0,0-8-8H56a8,8,0,0,0-8,8V64H24A16,16,0,0,0,8,80V96a40,40,0,0,0,40,40h3.65A80.13,80.13,0,0,0,120,191.61V216H96a8,8,0,0,0,0,16h64a8,8,0,0,0,0-16H136V191.58c31.94-3.23,58.44-25.64,68.08-55.58H208a40,40,0,0,0,40-40V80A16,16,0,0,0,232,64ZM48,120A24,24,0,0,1,24,96V80H48v32q0,4,.39,8Zm144-8.9c0,35.52-29,64.64-64,64.9a64,64,0,0,1-64-64V56H192ZM232,96a24,24,0,0,1-24,24h-.5a81.81,81.81,0,0,0,.5-8.9V80h24Z"></path></svg>
Events Performance
</span>
<span>'.$this->type.'Moving Average</span>
</span>
');
}
protected function getData(): array
{
$data = LoadPerformance::load($this->filters, false);
if ($data) {
HelperMoveingAveragePerformens::get($data);
}
return $data;
}
protected function getType(): string
{
return 'line';
}
protected function getOptions(): RawJs
{
return RawJs::make(<<<'JS'
{
interaction: {
intersect: false,
},
plugins: {
legend: {
position: 'left',
maxWidth: ({chart}) => chart.width * 0.9
},
tooltip: {
callbacks: {
label: (context) => {
if(context.dataset.label == 'Average Team' || context.dataset.label == 'Average Attak'|| context.dataset.label == 'Average Denfence'|| context.dataset.label == 'Average Midfield'){
return [context.dataset.label+' '+context.dataset.data[0]];
}
else {
return [' '+context.parsed.y, ' '+context.dataset.playing_date[context.dataIndex], ' '+context.dataset.events[context.dataIndex], ' '+context.dataset.results_per_event[context.dataIndex]];
}
},
}
}
},
scales: {
x: {
title: {
display: true,
text: 'Number of days to date'
}
},
},
}
JS);
}
}
+96
View File
@@ -0,0 +1,96 @@
<?php
namespace App\Filament\Widgets;
use App\Filament\Widgets\Charts\HelperStatisticType;
use App\Filament\Widgets\Charts\LoadPlayerWidgets;
use Filament\Support\RawJs;
use Filament\Widgets\ChartWidget;
use Illuminate\Support\HtmlString;
use Livewire\Attributes\Reactive;
class ChartPlayer extends ChartWidget
{
#[Reactive]
public ?array $filters = [];
public ?string $player = 'Player';
public ?string $type = '';
protected ?string $pollingInterval = null;
public function getHeading(): HtmlString
{
return new HtmlString('
<span class="flex justify-between">
<span class="text-primary-700 dark:text-primary-400 flex flex-row gap-2">
<svg viewBox="0 0 15 15" version="1.1" id="soccer" class="h-5 w-5"
xmlns="http://www.w3.org/2000/svg" fill="currentColor">
<g id="SVGRepo_bgCarrier" stroke-width="0"></g>
<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g>
<g id="SVGRepo_iconCarrier">
<path d="M11,1.5C11,2.3284,10.3284,3,9.5,3S8,2.3284,8,1.5S8.6716,0,9.5,0S11,0.6716,11,1.5z M11,11c-0.5523,0-1,0.4477-1,1
s0.4477,1,1,1s1-0.4477,1-1S11.5523,11,11,11z M12.84,6.09l-1.91-1.91l0,0C10.8399,4.0675,10.7041,4.0014,10.56,4H3.5
C3.2239,4,3,4.2239,3,4.5S3.2239,5,3.5,5h2.7L3,11.3l0,0c-0.0138,0.066-0.0138,0.134,0,0.2c-0.058,0.2761,0.1189,0.547,0.395,0.605
C3.6711,12.163,3.942,11.9861,4,11.71l0,0L5,10h2l-1.93,4.24l0,0C5.0228,14.3184,4.9986,14.4085,5,14.5
c-0.0552,0.2761,0.1239,0.5448,0.4,0.6c0.2761,0.0552,0.5448-0.1239,0.6-0.4l0,0l4.7-9.38l1.44,1.48
c0.211,0.1782,0.5264,0.1516,0.7046-0.0593C13.0037,6.5523,13.0018,6.2761,12.84,6.09z"></path>
</g>
</svg>
'.$this->player.'
</span>
<span>'.$this->type.'</span>
</span>
');
}
protected function getData(): array
{
$data = LoadPlayerWidgets::load($this->filters, true);
if ($data) {
$this->player = $data['player_name'] ?? '';
$this->type = ucfirst(HelperStatisticType::get($this->filters));
}
return $data;
}
protected function getType(): string
{
return 'line';
}
protected function getOptions(): RawJs
{
return RawJs::make(<<<'JS'
{
interaction: {
intersect: false,
},
plugins: {
legend: {
position: 'left',
},
},
scales: {
x: {
title: {
display: true,
text: 'Number of days to date'
}
},
y: {
beginAtZero:true,
ticks: {
callback: function(value, index, ticks) {
return value % 1 === 0 ? value : '';
}
}
},
},
}
JS);
}
}
+99
View File
@@ -0,0 +1,99 @@
<?php
namespace App\Filament\Widgets;
use App\Filament\Widgets\Charts\HelperMoveingAverage;
use App\Filament\Widgets\Charts\HelperStatisticType;
use App\Filament\Widgets\Charts\LoadPlayerWidgets;
use Filament\Support\RawJs;
use Filament\Widgets\ChartWidget;
use Illuminate\Support\HtmlString;
use Livewire\Attributes\Reactive;
class ChartPlayerMoAv extends ChartWidget
{
#[Reactive]
public ?array $filters = [];
public ?string $player = 'Player';
public ?string $type = '';
protected ?string $pollingInterval = null;
public function getHeading(): HtmlString
{
return new HtmlString('
<span class="flex justify-between">
<span class="text-primary-700 dark:text-primary-400 flex flex-row gap-2">
<svg viewBox="0 0 15 15" version="1.1" id="soccer" class="h-6 w-6"
xmlns="http://www.w3.org/2000/svg" fill="currentColor">
<g id="SVGRepo_bgCarrier" stroke-width="0"></g>
<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g>
<g id="SVGRepo_iconCarrier">
<path d="M11,1.5C11,2.3284,10.3284,3,9.5,3S8,2.3284,8,1.5S8.6716,0,9.5,0S11,0.6716,11,1.5z M11,11c-0.5523,0-1,0.4477-1,1
s0.4477,1,1,1s1-0.4477,1-1S11.5523,11,11,11z M12.84,6.09l-1.91-1.91l0,0C10.8399,4.0675,10.7041,4.0014,10.56,4H3.5
C3.2239,4,3,4.2239,3,4.5S3.2239,5,3.5,5h2.7L3,11.3l0,0c-0.0138,0.066-0.0138,0.134,0,0.2c-0.058,0.2761,0.1189,0.547,0.395,0.605
C3.6711,12.163,3.942,11.9861,4,11.71l0,0L5,10h2l-1.93,4.24l0,0C5.0228,14.3184,4.9986,14.4085,5,14.5
c-0.0552,0.2761,0.1239,0.5448,0.4,0.6c0.2761,0.0552,0.5448-0.1239,0.6-0.4l0,0l4.7-9.38l1.44,1.48
c0.211,0.1782,0.5264,0.1516,0.7046-0.0593C13.0037,6.5523,13.0018,6.2761,12.84,6.09z"></path>
</g>
</svg>
'.$this->player.'
</span>
<span>'.$this->type.' Moving Average</span>
</span>
');
}
protected function getData(): array
{
$data = LoadPlayerWidgets::load($this->filters, false);
if ($data) {
$this->player = $data['player_name'] ?? '';
$this->type = ucfirst(HelperStatisticType::get($this->filters));
HelperMoveingAverage::get($data);
}
return $data;
}
protected function getType(): string
{
return 'line';
}
protected function getOptions(): RawJs
{
return RawJs::make(<<<'JS'
{
interaction: {
intersect: false,
},
plugins: {
legend: {
position: 'left',
},
},
scales: {
x: {
title: {
display: true,
text: 'Number of days to date'
}
},
y: {
beginAtZero:true,
ticks: {
callback: function(value, index, ticks) {
return value % 1 === 0 ? value : '';
}
}
},
},
}
JS);
}
}
+93
View File
@@ -0,0 +1,93 @@
<?php
namespace App\Filament\Widgets;
use App\Filament\Widgets\Charts\LoadPlayerPerformance;
use Filament\Support\RawJs;
use Filament\Widgets\ChartWidget;
use Illuminate\Support\HtmlString;
use Livewire\Attributes\Reactive;
class ChartPlayerPerf extends ChartWidget
{
#[Reactive]
public ?array $filters = [];
public ?string $player = 'Player';
public ?string $type = '';
protected ?string $pollingInterval = null;
public function getHeading(): HtmlString
{
return new HtmlString('
<span class="flex justify-between">
<span class="text-primary-700 dark:text-primary-400 flex flex-row gap-2">
<svg viewBox="0 0 15 15" version="1.1" id="soccer" class="h-6 w-6"
xmlns="http://www.w3.org/2000/svg" fill="currentColor">
<g id="SVGRepo_bgCarrier" stroke-width="0"></g>
<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g>
<g id="SVGRepo_iconCarrier">
<path d="M11,1.5C11,2.3284,10.3284,3,9.5,3S8,2.3284,8,1.5S8.6716,0,9.5,0S11,0.6716,11,1.5z M11,11c-0.5523,0-1,0.4477-1,1
s0.4477,1,1,1s1-0.4477,1-1S11.5523,11,11,11z M12.84,6.09l-1.91-1.91l0,0C10.8399,4.0675,10.7041,4.0014,10.56,4H3.5
C3.2239,4,3,4.2239,3,4.5S3.2239,5,3.5,5h2.7L3,11.3l0,0c-0.0138,0.066-0.0138,0.134,0,0.2c-0.058,0.2761,0.1189,0.547,0.395,0.605
C3.6711,12.163,3.942,11.9861,4,11.71l0,0L5,10h2l-1.93,4.24l0,0C5.0228,14.3184,4.9986,14.4085,5,14.5
c-0.0552,0.2761,0.1239,0.5448,0.4,0.6c0.2761,0.0552,0.5448-0.1239,0.6-0.4l0,0l4.7-9.38l1.44,1.48
c0.211,0.1782,0.5264,0.1516,0.7046-0.0593C13.0037,6.5523,13.0018,6.2761,12.84,6.09z"></path>
</g>
</svg>
'.$this->player.'
</span>
<span>Performance</span>
</span>
');
}
protected function getData(): array
{
$data = LoadPlayerPerformance::load($this->filters, true);
if ($data) {
$this->player = $data['player_name'] ?? '';
}
return $data;
}
protected function getType(): string
{
return 'line';
}
protected function getOptions(): RawJs
{
return RawJs::make(<<<'JS'
{
interaction: {
intersect: false,
},
plugins: {
legend: {
position: 'left',
},
},
scales: {
x: {
title: {
display: true,
text: 'Number of days to date'
}
},
y: {
beginAtZero:true,
ticks: {
callback: function(value, index, ticks) {
return value % 1 === 0 ? value : '';
}
}
},
},
}
JS);
}
}
@@ -0,0 +1,97 @@
<?php
namespace App\Filament\Widgets;
use App\Filament\Widgets\Charts\HelperMoveingAverage;
use App\Filament\Widgets\Charts\LoadPlayerPerformance;
use Filament\Support\RawJs;
use Filament\Widgets\ChartWidget;
use Illuminate\Support\HtmlString;
use Livewire\Attributes\Reactive;
class ChartPlayerPerfMoAv extends ChartWidget
{
#[Reactive]
public ?array $filters = [];
public ?string $player = 'Player';
public ?string $type = '';
protected ?string $pollingInterval = null;
public function getHeading(): HtmlString
{
return new HtmlString('
<span class="flex justify-between">
<span class="text-primary-700 dark:text-primary-400 flex flex-row gap-2">
<svg viewBox="0 0 15 15" version="1.1" id="soccer" class="h-6 w-6"
xmlns="http://www.w3.org/2000/svg" fill="currentColor">
<g id="SVGRepo_bgCarrier" stroke-width="0"></g>
<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g>
<g id="SVGRepo_iconCarrier">
<path d="M11,1.5C11,2.3284,10.3284,3,9.5,3S8,2.3284,8,1.5S8.6716,0,9.5,0S11,0.6716,11,1.5z M11,11c-0.5523,0-1,0.4477-1,1
s0.4477,1,1,1s1-0.4477,1-1S11.5523,11,11,11z M12.84,6.09l-1.91-1.91l0,0C10.8399,4.0675,10.7041,4.0014,10.56,4H3.5
C3.2239,4,3,4.2239,3,4.5S3.2239,5,3.5,5h2.7L3,11.3l0,0c-0.0138,0.066-0.0138,0.134,0,0.2c-0.058,0.2761,0.1189,0.547,0.395,0.605
C3.6711,12.163,3.942,11.9861,4,11.71l0,0L5,10h2l-1.93,4.24l0,0C5.0228,14.3184,4.9986,14.4085,5,14.5
c-0.0552,0.2761,0.1239,0.5448,0.4,0.6c0.2761,0.0552,0.5448-0.1239,0.6-0.4l0,0l4.7-9.38l1.44,1.48
c0.211,0.1782,0.5264,0.1516,0.7046-0.0593C13.0037,6.5523,13.0018,6.2761,12.84,6.09z"></path>
</g>
</svg>
'.$this->player.'
</span>
<span>Performance Moving Average</span>
</span>
');
}
protected function getData(): array
{
$data = LoadPlayerPerformance::load($this->filters, false);
if ($data) {
$this->player = $data['player_name'] ?? '';
HelperMoveingAverage::get($data);
}
return $data;
}
protected function getType(): string
{
return 'line';
}
protected function getOptions(): RawJs
{
return RawJs::make(<<<'JS'
{
interaction: {
intersect: false,
},
plugins: {
legend: {
position: 'left',
},
},
scales: {
x: {
title: {
display: true,
text: 'Number of days to date'
}
},
y: {
beginAtZero:true,
ticks: {
callback: function(value, index, ticks) {
return value % 1 === 0 ? value : '';
}
}
},
},
}
JS);
}
}
@@ -0,0 +1,30 @@
<?php
namespace App\Filament\Widgets\Charts;
class HelperMoveingAverage
{
public static function get(&$data)
{
if (! $data) {
return;
}
$data['labels'] = array_slice($data['labels'], 2);
$datasets = $data['datasets'];
foreach ($datasets as $k => $dataset) {
$arr = $dataset['data'];
$new = [];
$last = count($arr);
foreach ($arr as $key => $value) {
if ($key == 1 && $last > 2) {
$new[] = round(((float) $arr[0] + (float) $value + (float) $arr[2]) / 3, 1);
} elseif ($key > 1 && $key < $last - 1) {
$new[] = round(((float) $arr[$key - 1] + (float) $value + (float) $arr[$key + 1]) / 3, 1);
}
}
$data['datasets'][$k]['data'] = $new;
}
}
}
@@ -0,0 +1,55 @@
<?php
namespace App\Filament\Widgets\Charts;
class HelperMoveingAveragePerformens
{
public static function get(&$data)
{
if (! $data) {
return;
}
$data['labels'] = array_slice($data['labels'], 2);
$datasets = $data['datasets'];
foreach ($datasets as $k => $dataset) {
$arr = $dataset['data'];
// dd($arr);
$new = [];
$last = count($arr);
foreach ($arr as $key => $value) {
if ($key == 1 && $last > 2) {
$new[] = round(($arr[0] + $value + $arr[2]) / 3, 2);
} elseif ($key > 1 && $key < $last - 1) {
$new[] = round(($arr[$key - 1] + $value + $arr[$key + 1]) / 3, 2);
}
}
$data['datasets'][$k]['data'] = $new;
}
}
public static function fillHoles(array &$arr)
{
if (! $arr) {
return;
}
if (! $arr[0]) {
// get first value in array and copy it to start if start is null
$arr[0] = current(array_filter($arr));
}
$priv = 0;
foreach ($arr as $key => $value) {
if ($value) {
$priv = $value;
} else {
if ($priv) {
$arr[$key] = $priv;
}
}
}
}
}
@@ -0,0 +1,28 @@
<?php
namespace App\Filament\Widgets\Charts;
class HelperStatisticType
{
protected static array $types = [
'gls' => 'Goals',
'crn' => 'Corner',
'fls' => 'Fouls Commited',
'ofs' => 'Offside',
'crd' => 'Cards',
'snt' => 'Shots on Target',
'tsh' => 'Total Shots',
];
public static function get($filter): string
{
$tmp = $filter['statistic_type'] ?? 'none';
if (isset(self::$types[$tmp])) {
return self::$types[$tmp];
}
return 'Goals';
}
}
+440
View File
@@ -0,0 +1,440 @@
<?php
namespace App\Filament\Widgets\Charts;
use App\Filament\Widgets\Charts\LoadEvents\LoadEventsAverages;
use App\Filament\Widgets\Charts\LoadEvents\LoadEventsQuery;
use App\Filament\Widgets\Charts\LoadEvents\LoadExpectations;
use App\Models\StatisticFixtures;
use Illuminate\Support\Carbon;
class LoadEvents
{
public static function load(array $filter, bool $hasdots)
{
$league_id = (int) $filter['league_id'] ?? 0;
$match_id = (int) $filter['match_id'] ?? 0;
$team_id = (int) $filter['team_id'] ?? 0;
$statistic_type = $filter['statistic_type'] ?? 'gls';
$team_position = $filter['team_position'];
$seasonmode = $filter['seasonmode'];
$accuracy = (float) $filter['accuracy'] ?? 0.5;
$similar_past_matches = $filter['similar_past_matches'];
if (! $league_id) {
return [];
}
if (! $match_id) {
return [];
}
if ($statistic_type == 'none') {
$statistic_type = 'gls';
}
/**
* IF WITH SIMILAR_PAST_MATCHES
*
* 'none' => 'None',
* 'league' => 'League',
* 'all' => 'All Database',
*/
$handicap_range = [];
$total_range = [];
$match = StatisticFixtures::with('home')->with('away')->where('id', (int) $match_id)->first();
// dd($match);
if (! $match) {
return [];
}
if ($similar_past_matches != 'none') {
$team_id = 0;
$team_position = '';
$exp_handicap = $match->exp_away - $match->exp_home;
$exp_total = $match->exp_away + $match->exp_home;
$handicap_range = [$exp_handicap - $accuracy, $exp_handicap + $accuracy];
$total_range = [$exp_total - $accuracy, $exp_total + $accuracy];
// dd($exp_handicap,$exp_total, $handicap_range, $total_range);
$home_team = $match->home->ss_team_name;
$away_team = $match->away->ss_team_name;
} else {
$home_team = 'In Favour';
$away_team = 'Against';
}
/**
* STATTISTIC DATA
*/
$res = LoadEventsQuery::load($filter, $handicap_range, $total_range, $match);
$dataset_home = [];
$dataset_away = [];
$dataset_exp_home = [];
$dataset_exp_away = [];
$results_per_event = [];
$playing_date = [];
$labels = [];
$events = [];
$results = ['w' => 0, 'd' => 0, 'l' => 0, 'w2' => 0, 'l2' => 0];
if (! $team_id || ! \in_array($team_position, ['home', 'away'])) {
$team_position = 'all';
}
if (! isset($res['all']) || ! isset($res[$team_position])) {
return [];
}
$expectations = LoadExpectations::load($res['all'], $match, $statistic_type);
$label1 = '';
$label2 = '';
$label3 = '';
$label4 = '';
if ($team_id) {
foreach ($res[$team_position] as $value) {
$labels[] = round($value['starttime']->diffInDays(Carbon::now()));
$playing_date[] = $value['starttime']->format('Y-m-d H:i');
$results_per_event[] = $value['val_home'].' : '.$value['val_away'];
$val_home = (int) $value['val_home'];
$val_away = (int) $value['val_away'];
if ($similar_past_matches != 'none') {
switch ($value['result_code']) {
case '1':
$results['w']++;
$results['l2']++;
break;
case 'X':
$results['d']++;
break;
case '2':
$results['l']++;
$results['w2']++;
break;
}
if ($statistic_type == 'gls') {
$dataset_exp_home[] = (float) round($value['exp_home'], 1);
$dataset_exp_away[] = (float) round($value['exp_away'], 1);
}
} else {
if ($team_position == 'home') {
switch ($value['result_code']) {
case '1':
$results['w']++;
$results['l2']++;
break;
case 'X':
$results['d']++;
break;
case '2':
$results['l']++;
$results['w2']++;
break;
}
if ($statistic_type == 'gls') {
$dataset_exp_home[] = (float) round($value['exp_home'], 1);
$dataset_exp_away[] = (float) round($value['exp_away'], 1);
}
} elseif ($team_position == 'away') {
switch ($value['result_code']) {
case '1':
$results['l']++;
$results['w2']++;
break;
case 'X':
$results['d']++;
break;
case '2':
$results['w']++;
$results['l2']++;
break;
}
if ($statistic_type == 'gls') {
$dataset_exp_home[] = (float) round($value['exp_away'], 1);
$dataset_exp_away[] = (float) round($value['exp_home'], 1);
}
} else {
// dd($team_id, $value['home_id'], $value['away_id']);
switch ($value['result_code']) {
case '1':
if ($team_id == $value['home_id']) {
$results['l2']++;
$results['w']++;
} else {
$results['w2']++;
$results['l']++;
}
break;
case 'X':
$results['d']++;
break;
case '2':
if ($team_id == $value['home_id']) {
$results['l']++;
$results['w2']++;
} else {
$results['l2']++;
$results['w']++;
}
break;
}
if ($statistic_type == 'gls') {
$dataset_exp_home[] = (float) round($value['exp_away'], 1);
$dataset_exp_away[] = (float) round($value['exp_home'], 1);
}
}
}
if (isset($val_home) && isset($val_away)) {
$events[] = $value['home'].' vs '.$value['away'];
if ($team_id == $value['home_id']) {
$dataset_home[] = $val_home;
$dataset_away[] = $val_away;
} elseif ($team_id == $value['away_id']) {
$dataset_home[] = $val_away;
$dataset_away[] = $val_home;
}
// $dataset_home[] = $val_home;
// $dataset_away[] = $val_away;
}
}
if ($similar_past_matches != 'none') {
$label1 = 'Home';
$label2 = 'Away';
} else {
if ($team_id == $match->home->ss_team_id) {
$label1 = $match->home->ss_team_name;
} else {
$label1 = $match->away->ss_team_name;
}
$label2 = 'Opponent';
}
} else {
$label1 = $match->home->ss_team_name.' +';
$label2 = $match->home->ss_team_name.' -';
$label3 = $match->away->ss_team_name.' +';
$label4 = $match->away->ss_team_name.' -';
$dataset_home2 = [];
$dataset_away2 = [];
$home_id = $match->home_id;
$away_id = $match->away_id;
foreach ($res[$team_position] as $value) {
$labels[] = round($value['starttime']->diffInDays(Carbon::now()));
switch ($value['result_code']) {
case '1':
$results['w']++;
$results['l2']++;
break;
case 'X':
$results['d']++;
break;
case '2':
$results['l']++;
$results['w2']++;
break;
}
if ($team_id) {
if ($team_id == $value['home_id']) {
$dataset_home[] = (int) $value['val_home'];
$dataset_away[] = (int) $value['val_away'];
} elseif ($team_id == $value['away_id']) {
$dataset_home[] = (int) $value['val_away'];
$dataset_away[] = (int) $value['val_home'];
}
} else {
$dataset_home[] = (int) $value['val_home'];
$dataset_away[] = (int) $value['val_away'];
}
// Home playing AWAY done and commited
if ($match->away_id == $value['home_id']) {
$dataset_home2[] = (int) $value['val_home'];
$dataset_away2[] = (int) $value['val_away'];
} else {
$dataset_home2[] = (int) $value['val_away'];
$dataset_away2[] = (int) $value['val_home'];
}
}
$n = max(count($dataset_home), count($dataset_away), count($dataset_away2), count($dataset_home2));
if ($n) {
$f = array_first($labels);
$step = round($f / $n);
$labels = [];
for ($i = $f; $i >= 0; $i -= $step) {
$labels[] = $i;
}
}
}
// dd($events, array_sum($dataset_home), array_sum($dataset_away));
// dd($events, count($dataset_home), count($dataset_away), count($dataset_home2), count($dataset_away2));
self::shortenEnding($labels, $dataset_home, $dataset_away);
// dd($dataset_home);
$data = [
'datasets' => [
[
'label' => $label1,
'events' => $events,
'playing_date' => $playing_date,
'results_per_event' => $results_per_event,
'data' => $dataset_home,
'tension' => 0.5,
'borderColor' => '#fb2c36',
'backgroundColor' => '#fb2c36',
'pointStyle' => $hasdots,
'fill' => [
'target' => 1,
'above' => '#fb2c3680',
'below' => '#fdc70080',
],
],
[
'label' => $label2,
'events' => $events,
'playing_date' => $playing_date,
'results_per_event' => $results_per_event,
'data' => $dataset_away,
'tension' => 0.5,
'borderColor' => '#fdc700',
'backgroundColor' => '#fdc700',
'pointStyle' => $hasdots,
'fill' => false,
'hidden' => true,
],
],
'labels' => $labels,
'description' => $description ?? '',
'results' => $results,
'home_team' => $home_team,
'away_team' => $away_team,
'similar_past_matches' => $similar_past_matches,
'expectations_home' => $expectations['home'],
'expectations_away' => $expectations['away'],
];
if ($team_id && $statistic_type == 'gls') {
$data['datasets'][] = [
'label' => 'Goals '.$label1,
'events' => $events,
'playing_date' => $playing_date,
'results_per_event' => $results_per_event,
'data' => $dataset_exp_home,
'tension' => 0.5,
'borderColor' => '#00c950',
'backgroundColor' => '#00c950',
'pointStyle' => $hasdots,
'hidden' => true,
];
$data['datasets'][] = [
'label' => 'Goals '.$label2,
'events' => $events,
'playing_date' => $playing_date,
'results_per_event' => $results_per_event,
'data' => $dataset_exp_away,
'tension' => 0.5,
'borderColor' => '#2b7fff',
'backgroundColor' => '#2b7fff',
'pointStyle' => $hasdots,
'hidden' => true,
];
}
if (isset($dataset_home2) && isset($dataset_away2)) {
$data['datasets'][] = [
'label' => $label3,
'events' => $events,
'playing_date' => $playing_date,
'results_per_event' => $results_per_event,
'data' => $dataset_home2,
'tension' => 0.5,
'borderColor' => '#00c950',
'backgroundColor' => '#00c950',
'pointStyle' => $hasdots,
'hidden' => true,
];
$data['datasets'][] = [
'label' => $label4,
'events' => $events,
'playing_date' => $playing_date,
'results_per_event' => $results_per_event,
'data' => $dataset_away2,
'tension' => 0.5,
'borderColor' => '#2b7fff',
'backgroundColor' => '#2b7fff',
'pointStyle' => $hasdots,
'hidden' => true,
];
}
// dd($data);
/**
* LEAGUE AVERAGES
*/
if ($team_id && $similar_past_matches == 'none') {
LoadEventsAverages::load($data, $filter, $labels, $events);
}
return $data;
}
public static function shortenEnding(array &$labels, array &$homes, array &$aways)
{
if (! isset($homes['all'])) {
return;
}
$count_home = 0;
$count_away = 0;
for ($i = \count($homes) - 1; $i > 0; $i--) {
if ($homes[$i] == null) {
$count_home++;
} else {
break;
}
}
for ($i = \count($aways) - 1; $i > 0; $i--) {
if ($aways[$i] == null) {
$count_away++;
} else {
break;
}
}
$keeps = count($homes['all']) - min($count_home, $count_away) - 1;
$homes = array_slice($homes, 0, $keeps);
$aways = array_slice($aways, 0, $keeps);
$labels = array_slice($labels, 0, $keeps);
}
}
@@ -0,0 +1,278 @@
<?php
namespace App\Filament\Widgets\Charts\LoadEvents;
use App\Models\StatistikoEvent;
class LoadEventsAverages
{
public static function load(array &$data, array $filter, array $labels, array $events)
{
$tournament_id = (int) $filter['league_id'] ?? 0;
$team_position = $filter['team_position'];
$team_id = (int) $filter['team_id'] ?? 0;
$statistic_type = $filter['statistic_type'] ?? 'gls';
$season = $filter['season'] ?? 0;
$season_or_date = $filter['season_or_date'] ?? 'season';
$start = $filter['start_date'] ?? 0;
$end = $filter['end_date'] ?? 0;
if ($season_or_date != 'season') {
$season = 0;
} else {
$end = 0;
$start = 0;
}
$res = StatistikoEvent::where('league_id', $tournament_id)
->when($start, function ($query) use ($start) {
return $query->whereDate('starttime', '>=', $start);
})->when($end, function ($query) use ($end) {
return $query->whereDate('starttime', '<=', $end);
})->when($season, function ($query) use ($season) {
return $query->whereIn('season', $season);
})
->orderBy('starttime', 'ASC')
->get();
// dd($res);
if ($res) {
$team_home = [];
$team_away = [];
$league_home = [];
$league_away = [];
// 1) la media dei falli di tutte le partite giocate dal Flamengo
// (esempio, giocate 6 partite con falli 17-11-15-14-15-12, la media è 14)
// 2) la media dei falli di tutte le partite giocate nel campionato Brasiliano
// (esempio 6 giornate giocate = 60 partite quindi 120 squadre, quindi 120 dati tipo 17-12-12-15-8-15-13-21-...,
// quindi la media di questi 120 dati)
foreach ($res as $value) {
switch ($statistic_type) {
case 'gls':
$league_home[] = (int) $value['gls_h'];
$league_away[] = (int) $value['gls_a'];
break;
case 'crn':
$league_home[] = (int) $value['crn_h'];
$league_away[] = (int) $value['crn_a'];
break;
case 'fls':
$league_home[] = (int) $value['fls_h'];
$league_away[] = (int) $value['fls_a'];
break;
case 'ofs':
$league_home[] = (int) $value['ofs_h'];
$league_away[] = (int) $value['ofs_a'];
break;
case 'crd':
$league_home[] = (int) $value['crd_h'];
$league_away[] = (int) $value['crd_a'];
break;
case 'snt':
$league_home[] = (int) $value['snt_h'];
$league_away[] = (int) $value['snt_a'];
break;
case 'tsh':
$league_home[] = (int) $value['tsh_h'];
$league_away[] = (int) $value['tsh_a'];
break;
}
if ((! $team_position || $team_position == 'all') && ($team_id == $value['home_id'] or $team_id == $value['away_id'])) {
switch ($statistic_type) {
case 'gls':
if ($team_id == $value['home_id']) {
$team_home[] = (int) $value['gls_h'];
$team_away[] = (int) $value['gls_a'];
} else {
$team_home[] = (int) $value['gls_a'];
$team_away[] = (int) $value['gls_h'];
}
break;
case 'crn':
if ($team_id == $value['home_id']) {
$team_home[] = (int) $value['crn_h'];
$team_away[] = (int) $value['crn_a'];
} else {
$team_home[] = (int) $value['crn_a'];
$team_away[] = (int) $value['crn_h'];
}
break;
case 'fls':
if ($team_id == $value['home_id']) {
$team_home[] = (int) $value['fls_h'];
$team_away[] = (int) $value['fls_a'];
} else {
$team_home[] = (int) $value['fls_a'];
$team_away[] = (int) $value['fls_h'];
}
break;
case 'ofs':
if ($team_id == $value['home_id']) {
$team_home[] = (int) $value['ofs_h'];
$team_away[] = (int) $value['ofs_a'];
} else {
$team_home[] = (int) $value['ofs_a'];
$team_away[] = (int) $value['ofs_h'];
}
break;
case 'crd':
if ($team_id == $value['home_id']) {
$team_home[] = (int) $value['crd_h'];
$team_away[] = (int) $value['crd_a'];
} else {
$team_home[] = (int) $value['crd_a'];
$team_away[] = (int) $value['crd_h'];
}
break;
case 'snt':
if ($team_id == $value['home_id']) {
$team_home[] = (int) $value['snt_h'];
$team_away[] = (int) $value['snt_a'];
} else {
$team_home[] = (int) $value['snt_a'];
$team_away[] = (int) $value['snt_h'];
}
break;
case 'tsh':
if ($team_id == $value['home_id']) {
$team_home[] = (int) $value['tsh_h'];
$team_away[] = (int) $value['tsh_a'];
} else {
$team_home[] = (int) $value['tsh_a'];
$team_away[] = (int) $value['tsh_h'];
}
break;
}
} elseif ($team_position == 'home' && $team_id == $value['home_id']) {
switch ($statistic_type) {
case 'gls':
$team_home[] = (int) $value['gls_h'];
$team_away[] = (int) $value['gls_a'];
break;
case 'crn':
$team_home[] = (int) $value['crn_h'];
$team_away[] = (int) $value['crn_a'];
break;
case 'fls':
$team_home[] = (int) $value['fls_h'];
$team_away[] = (int) $value['fls_a'];
break;
case 'ofs':
$team_home[] = (int) $value['ofs_h'];
$team_away[] = (int) $value['ofs_a'];
break;
case 'crd':
$team_home[] = (int) $value['crd_h'];
$team_away[] = (int) $value['crd_a'];
break;
case 'snt':
$team_home[] = (int) $value['snt_h'];
$team_away[] = (int) $value['snt_a'];
break;
case 'tsh':
$team_home[] = (int) $value['tsh_h'];
$team_away[] = (int) $value['tsh_a'];
break;
}
} elseif ($team_position == 'away' && $team_id == $value['away_id']) {
switch ($statistic_type) {
case 'gls':
$team_home[] = (int) $value['gls_a'];
$team_away[] = (int) $value['gls_h'];
break;
case 'crn':
$team_home[] = (int) $value['crn_a'];
$team_away[] = (int) $value['crn_h'];
break;
case 'fls':
$team_home[] = (int) $value['fls_a'];
$team_away[] = (int) $value['fls_h'];
break;
case 'ofs':
$team_home[] = (int) $value['ofs_a'];
$team_away[] = (int) $value['ofs_h'];
break;
case 'crd':
$team_home[] = (int) $value['crd_a'];
$team_away[] = (int) $value['crd_h'];
break;
case 'snt':
$team_home[] = (int) $value['snt_a'];
$team_away[] = (int) $value['snt_h'];
break;
case 'tsh':
$team_home[] = (int) $value['tsh_a'];
$team_away[] = (int) $value['tsh_h'];
break;
}
}
}
$average_team = 0;
$average_team_home = 0;
$average_team_away = 0;
$average_league = 0;
$average_league_home = 0;
$average_league_away = 0;
// dd($team_home);
if ($team_id && $team_home) {
$sum = array_sum($team_home) + array_sum($team_away);
$count = count($team_home) + count($team_away);
$average_team = round($sum / $count, 1);
$average_team_home = round(array_sum($team_home) / count($team_home), 1);
$average_team_away = round(array_sum($team_away) / count($team_away), 1);
$average_league_home = $league_home ? round(array_sum($league_home) / \count($league_home), 1) : 0;
$average_league_away = $league_away ? round(array_sum($league_away) / \count($league_away), 1) : 0;
$media_league = array_merge($league_away, $league_home);
$average_league = $media_league ? round(array_sum($media_league) / \count($media_league), 1) : 0;
}
$data_team = array_fill(0, count($labels), $average_team);
$data_league = array_fill(0, count($labels), $average_league);
$data['datasets'][] = [
'label' => 'Average Team',
'events' => $events,
'data' => $data_team,
'tension' => 0.5,
'borderColor' => '#ad46ff',
'backgroundColor' => '#ad46ff',
'borderDash' => [5, 5],
'pointStyle' => false,
'hidden' => false,
'average_team_home' => $average_team_home,
'average_team_away' => $average_team_away,
];
$data['datasets'][] = [
'label' => 'Average League',
'events' => $events,
'data' => $data_league,
'tension' => 0.5,
'borderColor' => '#00bba7',
'backgroundColor' => '#00bba7',
'borderDash' => [5, 5],
'pointStyle' => false,
'hidden' => false,
'average_league_home' => $average_league_home,
'average_league_away' => $average_league_away,
];
}
}
}
@@ -0,0 +1,205 @@
<?php
namespace App\Filament\Widgets\Charts\LoadEvents;
use App\Filament\Pages\Selections\Helper\GetSeason;
use App\Models\SofaScoreRosa;
use App\Models\StatistikoEvent;
use App\Models\StatistikoPlayer;
use Illuminate\Support\Facades\Log;
class LoadEventsQuery
{
public static function load(array $filter, array $handicap_range, array $total_range, object $match)
{
$league_id = (int) $filter['league_id'] ?? 0;
$team_id = (int) $filter['team_id'] ?? 0;
$season = $filter['season'];
$seasonmode = $filter['seasonmode'];
$season_or_date = $filter['season_or_date'];
$start = $filter['start_date'] ?? 0;
$end = $filter['end_date'] ?? 0;
if ($season_or_date == 'season') {
$start = 0;
$end = 0;
}
$ss_player_id = (int) $filter['ss_player_id'] ?? 0;
$player_on_field = $filter['player_on_field'] ?? 'all';
$similar_past_matches = $filter['similar_past_matches'];
$statistic_type = $filter['statistic_type'] ?? 'gls';
$team_position = $filter['team_position'];
$home_id = $match->home_id;
$away_id = $match->away_id;
if ($statistic_type == 'none') {
$statistic_type = 'gls';
}
if ($similar_past_matches != 'none') {
$team_position = '';
$team_id = 0;
$ss_player_id = 0;
}
// dd($season);
$season = GetSeason::load($season, $seasonmode);
/**
* IF WITH PLAYER
*/
$matches_played = [];
if ($ss_player_id) {
$matches_season = 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_played = StatistikoPlayer::query()
->whereIn('match_id', $matches_season)
->where('ss_player_id', $ss_player_id)
->when($player_on_field, function ($query) use ($player_on_field) {
// 'all' => 'All',
// 'lineup' => 'Lineup',
// 'substituted' => 'Substituted',
// 'notplayed' => 'Not Played',
switch ($player_on_field) {
case 'all':
return $query->where('minutes_played', '>', 0);
case 'lineup':
return $query->where('lineup', 'T')->where('minutes_played', '>', 0);
case 'substituted':
return $query->where('lineup', 'P')->where('minutes_played', '>', 0);
default:
return $query->where('minutes_played', '>', 0);
}
})
->pluck('match_id')->toArray();
if (! $matches_played) {
$matches_played[] = -1;
}
}
$team_map = SofaScoreRosa::pluck('ss_team_name', 'ss_team_id')->toArray();
// dd($handicap_range, $total_range);
/**
* STATTISTIC DATA
*/
// dd($team_id, $home_id, $away_id);
$res = StatistikoEvent::where(function ($query) use ($league_id, $similar_past_matches) {
switch ($similar_past_matches) {
case 'none':
case 'league':
return $query->where('league_id', $league_id);
}
})
->where(function ($query) use ($team_id, $home_id, $away_id, $similar_past_matches) {
if ($similar_past_matches == 'none') {
if ($team_id) {
return $query->orWhere('home_id', $team_id)
->orWhere('away_id', '=', $team_id);
} else {
return $query->whereIn('home_id', [$home_id, $away_id])->orWhereIn('away_id', [$home_id, $away_id]);
}
}
})
->when($matches_played, function ($query) use ($matches_played, $player_on_field) {
if ($player_on_field == 'notplayed') {
return $query->whereNotIn('match_id', $matches_played);
} else {
return $query->whereIn('match_id', $matches_played);
}
})
->when($handicap_range, function ($query) use ($handicap_range) {
return $query->whereBetween('exp_handicap', $handicap_range);
})->when($total_range, function ($query) use ($total_range) {
return $query->whereBetween('exp_total', $total_range);
})
->when($start, function ($query) use ($start) {
return $query->whereDate('starttime', '>=', $start);
})->when($end, function ($query) use ($end) {
return $query->whereDate('starttime', '<=', $end);
})
->when($season, function ($query) use ($season, $season_or_date, $similar_past_matches) {
if ($similar_past_matches == 'none' && $season_or_date == 'season') {
return $query->whereIn('season', $season);
}
})
->orderBy('starttime', 'ASC')
->get();
// dd($res);
// dd($season, $league_id, $res);
Log::info('season', $season);
$arr = [];
foreach ($res as $value) {
$tmp = [];
$tmp['match_id'] = $value->match_id;
$tmp['sport_id'] = $value->sport_id;
$tmp['league_id'] = $value->league_id;
$tmp['home_id'] = $value->home_id;
$tmp['away_id'] = $value->away_id;
$tmp['starttime'] = $value->starttime;
$tmp['season'] = $value->season;
$tmp['exp_home'] = $value->exp_home;
$tmp['exp_away'] = $value->exp_away;
$tmp['exp_handicap'] = $value->exp_handicap;
$tmp['exp_total'] = $value->exp_total;
$tmp['result_code'] = $value->result_code;
$tmp['home'] = $team_map[$value->home_id] ?? 0;
$tmp['away'] = $team_map[$value->away_id] ?? 0;
switch ($statistic_type) {
case 'gls':
$tmp['val_home'] = $value->gls_h;
$tmp['val_away'] = $value->gls_a;
break;
case 'crn':
$tmp['val_home'] = $value->crn_h;
$tmp['val_away'] = $value->crn_a;
break;
case 'fls':
$tmp['val_home'] = $value->fls_h;
$tmp['val_away'] = $value->fls_a;
break;
case 'ofs':
$tmp['val_home'] = $value->ofs_h;
$tmp['val_away'] = $value->ofs_a;
break;
case 'crd':
$tmp['val_home'] = $value->crd_h;
$tmp['val_away'] = $value->crd_a;
break;
case 'snt':
$tmp['val_home'] = $value->snt_h;
$tmp['val_away'] = $value->snt_a;
break;
case 'tsh':
$tmp['val_home'] = $value->tsh_h;
$tmp['val_away'] = $value->tsh_a;
break;
}
$arr['all'][] = $tmp;
if ($value->home_id == $team_id) {
$arr['home'][] = $tmp;
}
if ($value->away_id == $team_id) {
$arr['away'][] = $tmp;
}
}
return $arr;
}
}
@@ -0,0 +1,144 @@
<?php
namespace App\Filament\Widgets\Charts\LoadEvents;
use App\Filament\Pages\Selections\Helper\GetSeason;
use App\Models\StatistikoEvent;
use App\Models\StatistikoPlayer;
class LoadEventsQueryAll
{
public static function load(array $filter, object $match)
{
$league_id = (int) $filter['league_id'] ?? 0;
$team_id = (int) $filter['team_id'] ?? 0;
$season = $filter['season'];
$seasonmode = $filter['seasonmode'];
$season_or_date = $filter['season_or_date'];
$accuracy = (float) $filter['accuracy'] ?? 0.5;
$start = $filter['start_date'] ?? 0;
$end = $filter['end_date'] ?? 0;
if ($season_or_date == 'season') {
$start = 0;
$end = 0;
}
$ss_player_id = (int) $filter['ss_player_id'] ?? 0;
$player_on_field = $filter['player_on_field'] ?? 'all';
$similar_past_matches = $filter['similar_past_matches'];
$team_position = $filter['team_position'];
$home_id = $match->home_id;
$away_id = $match->away_id;
$handicap_range = [];
$total_range = [];
if ($similar_past_matches != 'none') {
$team_id = 0;
$team_position = '';
$exp_handicap = $match->exp_away - $match->exp_home;
$exp_total = $match->exp_away + $match->exp_home;
$handicap_range = [$exp_handicap - $accuracy, $exp_handicap + $accuracy];
$total_range = [$exp_total - $accuracy, $exp_total + $accuracy];
}
if ($similar_past_matches != 'none') {
$team_position = '';
$team_id = 0;
$ss_player_id = 0;
}
// dd($season);
$season = GetSeason::load($season, $seasonmode);
/**
* IF WITH PLAYER
*/
$matches_played = [];
if ($ss_player_id) {
$matches_season = StatistikoEvent::whereIn('season', $season)
->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_played = StatistikoPlayer::query()
->whereIn('match_id', $matches_season)
->where('ss_player_id', $ss_player_id)
->when($player_on_field, function ($query) use ($player_on_field) {
// 'all' => 'All',
// 'lineup' => 'Lineup',
// 'substituted' => 'Substituted',
// 'notplayed' => 'Not Played',
switch ($player_on_field) {
case 'all':
return $query->where('minutes_played', '>', 0);
case 'lineup':
return $query->where('lineup', 'T')->where('minutes_played', '>', 0);
case 'substituted':
return $query->where('lineup', 'P')->where('minutes_played', '>', 0);
default:
return $query->where('minutes_played', '>', 0);
}
})
->pluck('match_id')->toArray();
if (! $matches_played) {
$matches_played[] = -1;
}
}
// dd($handicap_range, $total_range);
/**
* STATTISTIC DATA
*/
return StatistikoEvent::with('home')->with('away')
->where(function ($query) use ($league_id, $similar_past_matches) {
switch ($similar_past_matches) {
case 'none':
case 'league':
return $query->where('league_id', $league_id);
}
})
->where(function ($query) use ($team_id, $home_id, $away_id, $similar_past_matches) {
if ($similar_past_matches == 'none') {
if ($team_id) {
return $query->orWhere('home_id', $team_id)
->orWhere('away_id', '=', $team_id);
} else {
return $query->whereIn('home_id', [$home_id, $away_id])->orWhereIn('away_id', [$home_id, $away_id]);
}
}
})
->when($matches_played, function ($query) use ($matches_played, $player_on_field) {
if ($player_on_field == 'notplayed') {
return $query->whereNotIn('match_id', $matches_played);
} else {
return $query->whereIn('match_id', $matches_played);
}
})
->when($handicap_range, function ($query) use ($handicap_range) {
return $query->whereBetween('exp_handicap', $handicap_range);
})->when($total_range, function ($query) use ($total_range) {
return $query->whereBetween('exp_total', $total_range);
})
->when($start, function ($query) use ($start) {
return $query->whereDate('starttime', '>=', $start);
})->when($end, function ($query) use ($end) {
return $query->whereDate('starttime', '<=', $end);
})
->when($season, function ($query) use ($season, $season_or_date, $similar_past_matches) {
if ($similar_past_matches == 'none' && $season_or_date == 'season') {
return $query->whereIn('season', $season);
}
})
->orderBy('starttime', 'ASC')
->get();
}
}
@@ -0,0 +1,153 @@
<?php
namespace App\Filament\Widgets\Charts\LoadEvents;
use App\Models\StatistikoConfig;
class LoadExpectations
{
public static function load(array $data, object $match, string $statistic_type)
{
// dd($data, $match);
$config = StatistikoConfig::where('group', $statistic_type)->get();
$uba_home_made_total = 1;
$uba_home_made_home = 1;
$uba_home_got_total = 1;
$uba_home_got_home = 1;
$uba_away_made_total = 1;
$uba_away_made_home = 1;
$uba_away_got_total = 1;
$uba_away_got_home = 1;
foreach ($config as $value) {
$varname = str_replace($statistic_type.'_', '', $value->varname);
switch ($varname) {
case 'home_made_total':
$uba_home_made_total = (float) $value->value;
break;
case 'home_made_home':
$uba_home_made_home = (float) $value->value;
break;
case 'home_got_total':
$uba_home_got_total = (float) $value->value;
break;
case 'home_got_home':
$uba_home_got_home = (float) $value->value;
break;
case 'away_made_total':
$uba_away_made_total = (float) $value->value;
break;
case 'away_made_home':
$uba_away_made_home = (float) $value->value;
break;
case 'away_got_total':
$uba_away_got_total = (float) $value->value;
break;
case 'away_got_home':
$uba_away_got_home = (float) $value->value;
break;
}
}
$home_made_total = [];
$home_made_home = [];
$home_got_total = [];
$home_got_home = [];
$away_made_total = [];
$away_made_away = [];
$away_got_total = [];
$away_got_away = [];
$home_id = $match->home_id;
$away_id = $match->away_id;
foreach ($data as $value) {
// HOME
// if ($value['home_id'] == $home_id || $value['away_id'] == $home_id) {
// $home_made_total[] = $value['val_home'];
// $home_got_total[] = $value['val_away'];
// }
// if ($value['home_id'] == $home_id) {
// $home_made_home[] = $value['val_home'];
// $home_got_home[] = $value['val_away'];
// }
// AWAY
// if ($value['home_id'] == $away_id || $value['away_id'] == $away_id) {
// $away_made_total[] = $value['val_away'];
// $away_made_away[] = $value['val_home'];
// }
// if ($value['away_id'] == $away_id) {
// $away_made_away[] = $value['val_away'];
// $away_got_away[] = $value['val_home'];
// }
if ($value['home_id'] == $home_id) {
$home_made_total[] = $value['val_home'];
$home_made_home[] = $value['val_home'];
$home_got_total[] = $value['val_away'];
$home_got_home[] = $value['val_away'];
} elseif ($value['away_id'] == $home_id) {
$home_made_total[] = $value['val_away'];
$home_got_total[] = $value['val_away'];
} elseif ($value['home_id'] == $away_id) {
$home_made_total[] = $value['val_away'];
$home_got_total[] = $value['val_away'];
} elseif ($value['away_id'] == $away_id) {
$home_made_total[] = $value['val_home'];
$home_made_home[] = $value['val_home'];
$home_got_total[] = $value['val_away'];
$home_got_home[] = $value['val_home'];
}
if ($value['away_id'] == $away_id) {
$away_made_total[] = $value['val_away'];
$away_made_away[] = $value['val_away'];
$away_got_total[] = $value['val_home'];
$away_got_away[] = $value['val_home'];
} elseif ($value['home_id'] == $away_id) {
$away_made_total[] = $value['val_home'];
$away_got_total[] = $value['val_home'];
} elseif ($value['away_id'] == $home_id) {
$away_made_total[] = $value['val_home'];
$away_got_total[] = $value['val_home'];
} elseif ($value['home_id'] == $home_id) {
$away_made_total[] = $value['val_away'];
$away_made_away[] = $value['val_away'];
$away_got_total[] = $value['val_home'];
$away_got_away[] = $value['val_away'];
}
}
$summe_home = array_sum($home_made_total) * $uba_home_made_total;
$summe_home += array_sum($home_made_home) * $uba_home_made_home;
$summe_home += array_sum($home_got_total) * $uba_home_got_total;
$summe_home += array_sum($home_got_home) * $uba_home_got_home;
$count_home = \count($home_made_total);
$count_home += \count($home_made_home);
$count_home += \count($home_got_total);
$count_home += \count($home_got_home);
$count_home = ! $count_home ? 1 : $count_home;
$aspettativa_home = round($summe_home / $count_home, 1);
// dd($count_home, $summe_home, $aspettativa_home);
$summe_away = array_sum($away_made_total) * $uba_away_made_total;
$summe_away += array_sum($away_made_away) * $uba_away_made_home;
$summe_away += array_sum($away_got_total) * $uba_away_got_total;
$summe_away += array_sum($away_got_away) * $uba_away_got_home;
$count_away = \count($away_made_total);
$count_away += \count($away_made_away);
$count_away += \count($away_got_total);
$count_away += \count($away_got_away);
$count_away = ! $count_away ? 1 : $count_away;
$aspettativa_away = round($summe_away / $count_away, 1);
return ['home' => $aspettativa_home, 'away' => $aspettativa_away];
}
}
@@ -0,0 +1,605 @@
<?php
namespace App\Filament\Widgets\Charts;
use App\Models\SofaScoreRosa;
use App\Models\StatisticFixtures;
use App\Models\StatistikoEvent;
use App\Models\StatistikoPlayer;
use Illuminate\Support\Carbon;
class LoadPerformance
{
public static $last_query = [];
public static $events_data = [];
public static function load(array $filter, bool $hasdots)
{
$league_id = (int) $filter['league_id'] ?? 0;
$match_id = (int) $filter['match_id'] ?? 0;
$team_position = $filter['team_position'];
if (! $league_id) {
return [];
}
if (! $match_id) {
return [];
}
$team_map = SofaScoreRosa::pluck('ss_team_name', 'ss_team_id')->toArray();
$match = StatisticFixtures::where('id', $match_id)->first();
if (! $match) {
return [];
}
$home_id = $match->home_id ?? 0;
$away_id = $match->away_id ?? 0;
$res = StatistikoEvent::where('league_id', $league_id)->get();
$home_matches = [];
$away_matches = [];
$league_matches = [];
$date_home = [];
$date_away = [];
$events_home = [];
$events_away = [];
$results_home = [];
$results_away = [];
$labels = [];
foreach ($res as $val) {
$league_matches[] = $val->match_id;
switch ($team_position) {
case 'home':
if ($val->home_id == $home_id) {
$labels[] = round($val->starttime->diffInDays(Carbon::now()));
$date_home[] = $val['starttime']->format('Y-m-d H:i');
$results_home[] = $val['gls_h'].' : '.$val['gls_a'];
$events_home[] = $team_map[$val->home_id].' vs '.$team_map[$val->away_id];
$home_matches[] = $val->match_id;
}
if ($val->away_id == $away_id) {
$labels[] = round($val->starttime->diffInDays(Carbon::now()));
$date_away[] = $val['starttime']->format('Y-m-d H:i');
$results_away[] = $val['gls_h'].' : '.$val['gls_a'];
$events_home[] = $team_map[$val->home_id].' vs '.$team_map[$val->away_id];
$away_matches[] = $val->match_id;
}
break;
case 'away':
if ($val->away_id == $home_id) {
$labels[] = round($val->starttime->diffInDays(Carbon::now()));
$date_home[] = $val['starttime']->format('Y-m-d H:i');
$results_home[] = $val['gls_h'].' : '.$val['gls_a'];
$events_home[] = $team_map[$val->home_id].' vs '.$team_map[$val->away_id];
$home_matches[] = $val->match_id;
}
if ($val->home_id == $away_id) {
$labels[] = round($val->starttime->diffInDays(Carbon::now()));
$date_away[] = $val['starttime']->format('Y-m-d H:i');
$results_away[] = $val['gls_h'].' : '.$val['gls_a'];
$events_home[] = $team_map[$val->home_id].' vs '.$team_map[$val->away_id];
$away_matches[] = $val->match_id;
}
break;
default:
if ($val->home_id == $home_id or $val->away_id == $home_id) {
$labels[] = round($val->starttime->diffInDays(Carbon::now()));
$date_home[] = $val['starttime']->format('Y-m-d H:i');
$results_home[] = $val['gls_h'].' : '.$val['gls_a'];
$events_home[] = $team_map[$val->home_id].' vs '.$team_map[$val->away_id];
$home_matches[] = $val->match_id;
}
if ($val->home_id == $away_id or $val->away_id == $away_id) {
$labels[] = round($val->starttime->diffInDays(Carbon::now()));
$date_away[] = $val['starttime']->format('Y-m-d H:i');
$results_away[] = $val['gls_h'].' : '.$val['gls_a'];
$events_home[] = $team_map[$val->home_id].' vs '.$team_map[$val->away_id];
$away_matches[] = $val->match_id;
}
break;
}
}
$res = StatistikoPlayer::whereIn('match_id', $home_matches)->select('match_id', 'ss_player_id', 'activeteam_id', 'minutes_played', 'playerrating_value', 'player_position')->get();
$homes = self::filterMatches($res, $home_matches, $home_id);
// dd($homes['all']);
$res = StatistikoPlayer::whereIn('match_id', $away_matches)->select('match_id', 'ss_player_id', 'activeteam_id', 'minutes_played', 'playerrating_value', 'player_position')->get();
$aways = self::filterMatches($res, $away_matches, $away_id);
// dd($aways['all']);
$c_home = isset($homes['all']) ? count($homes['all']) : 0;
$c_away = isset($aways['all']) ? count($aways['all']) : 0;
$length = max($c_home, $c_away);
self::shortenEnding($labels, $homes, $aways);
$home_av = self::makeAv($homes, $length);
$away_av = self::makeAv($aways, $length);
$res = StatistikoPlayer::whereIn('match_id', $league_matches)->select('match_id', 'ss_player_id', 'activeteam_id', 'minutes_played', 'playerrating_value', 'player_position')->get();
$league = self::filterMatches($res, $league_matches);
$league_av = self::leagueAv($league, $length);
$data = [
'datasets' => [
[
'label' => $team_map[$match->home_id],
'playing_date' => $date_home,
'results_per_event' => $results_home,
'events' => $events_home,
'data' => $homes['all'] ?? [],
'spanGaps' => true,
'tension' => 0.5,
'borderColor' => '#fb2c36',
'backgroundColor' => '#fb2c36',
'pointStyle' => $hasdots,
],
[
'label' => 'Average Team',
'playing_date' => $date_home,
'results_per_event' => $results_home,
'events' => $events_home,
'data' => $home_av['all'],
'spanGaps' => true,
'tension' => 0.5,
'borderColor' => '#fb2c36',
'backgroundColor' => 'transparent',
'pointStyle' => false,
'borderDash' => [5, 5],
],
[
'label' => 'Defence',
'playing_date' => $date_home,
'results_per_event' => $results_home,
'events' => $events_home,
'data' => $homes['def'] ?? [],
'spanGaps' => true,
'tension' => 0.5,
'borderColor' => '#fe9a00',
'backgroundColor' => '#fe9a00',
'fill' => false,
'pointStyle' => $hasdots,
'hidden' => true,
],
[
'label' => 'Average Defence',
'playing_date' => $date_home,
'results_per_event' => $results_home,
'events' => $events_home,
'data' => $home_av['def'],
'spanGaps' => true,
'tension' => 0.5,
'borderColor' => '#fe9a00',
'backgroundColor' => 'transparent',
'pointStyle' => false,
'hidden' => true,
'borderDash' => [5, 5],
],
[
'label' => 'Attak',
'playing_date' => $date_home,
'results_per_event' => $results_home,
'events' => $events_home,
'data' => $homes['att'] ?? [],
'spanGaps' => true,
'tension' => 0.5,
'borderColor' => '#fe9a00',
'backgroundColor' => '#fe9a00',
'fill' => false,
'pointStyle' => $hasdots,
'hidden' => true,
],
[
'label' => 'Average Attak',
'playing_date' => $date_home,
'results_per_event' => $results_home,
'events' => $events_home,
'data' => $home_av['att'] ?? [],
'spanGaps' => true,
'tension' => 0.5,
'borderColor' => '#fe9a00',
'backgroundColor' => 'transparent',
'fill' => false,
'pointStyle' => false,
'hidden' => true,
'borderDash' => [5, 5],
],
[
'label' => 'Midfield',
'playing_date' => $date_home,
'results_per_event' => $results_home,
'events' => $events_home,
'data' => $homes['mid'] ?? [],
'spanGaps' => true,
'tension' => 0.5,
'borderColor' => '#fe9a00',
'backgroundColor' => '#fe9a00',
'fill' => false,
'pointStyle' => $hasdots,
'hidden' => true,
],
[
'label' => 'Average Midfield',
'playing_date' => $date_home,
'results_per_event' => $results_home,
'events' => $events_home,
'data' => $home_av['mid'] ?? [],
'spanGaps' => true,
'tension' => 0.5,
'borderColor' => '#fe9a00',
'backgroundColor' => 'transparent',
'fill' => false,
'pointStyle' => false,
'borderDash' => [5, 5],
'hidden' => true,
],
[
'label' => $team_map[$match->away_id],
'playing_date' => $date_away,
'results_per_event' => $results_away,
'events' => $events_away,
'data' => $aways['all'] ?? [],
'spanGaps' => true,
'tension' => 0.5,
'borderColor' => '#00bc7d',
'backgroundColor' => '#00bc7d',
'fill' => false,
'pointStyle' => $hasdots,
'hidden' => false,
],
[
'label' => 'Average Team',
'playing_date' => $date_away,
'results_per_event' => $results_away,
'events' => $events_away,
'data' => $away_av['all'] ?? [],
'spanGaps' => true,
'tension' => 0.5,
'borderColor' => '#00bc7d',
'backgroundColor' => 'transparent',
'fill' => false,
'pointStyle' => false,
'borderDash' => [5, 5],
'hidden' => false,
],
[
'label' => 'Defence',
'playing_date' => $date_away,
'results_per_event' => $results_away,
'events' => $events_away,
'data' => $aways['def'] ?? [],
'spanGaps' => true,
'tension' => 0.5,
'borderColor' => '#7ccf00',
'backgroundColor' => '#7ccf00',
'fill' => false,
'pointStyle' => $hasdots,
'hidden' => true,
],
[
'label' => 'Average Defence',
'playing_date' => $date_away,
'results_per_event' => $results_away,
'events' => $events_away,
'data' => $away_av['def'] ?? [],
'spanGaps' => true,
'tension' => 0.5,
'borderColor' => '#7ccf00',
'backgroundColor' => 'transparent',
'fill' => false,
'pointStyle' => false,
'borderDash' => [5, 5],
'hidden' => true,
],
[
'label' => 'Attak',
'playing_date' => $date_away,
'results_per_event' => $results_away,
'events' => $events_away,
'data' => $aways['att'] ?? [],
'spanGaps' => true,
'tension' => 0.5,
'borderColor' => '#7ccf00',
'backgroundColor' => '#7ccf00',
'fill' => false,
'pointStyle' => $hasdots,
'hidden' => true,
],
[
'label' => 'Average Attak',
'playing_date' => $date_away,
'results_per_event' => $results_away,
'events' => $events_away,
'data' => $away_av['att'] ?? [],
'spanGaps' => true,
'tension' => 0.5,
'borderColor' => '#7ccf00',
'backgroundColor' => 'transparent',
'fill' => false,
'pointStyle' => false,
'borderDash' => [5, 5],
'hidden' => true,
],
[
'label' => 'Midfield',
'playing_date' => $date_away,
'results_per_event' => $results_away,
'events' => $events_away,
'data' => $aways['mid'] ?? [],
'spanGaps' => true,
'tension' => 0.5,
'borderColor' => '#7ccf00',
'backgroundColor' => '#7ccf00',
'fill' => false,
'pointStyle' => $hasdots,
'hidden' => true,
],
[
'label' => 'Average Midfield',
'playing_date' => $date_away,
'results_per_event' => $results_away,
'events' => $events_away,
'data' => $away_av['mid'] ?? [],
'spanGaps' => true,
'tension' => 0.5,
'borderColor' => '#7ccf00',
'backgroundColor' => 'transparent',
'fill' => false,
'pointStyle' => false,
'borderDash' => [5, 5],
'hidden' => true,
],
[
'label' => 'Average League',
'playing_date' => $date_home,
'results_per_event' => $results_home,
'events' => $events_home,
'data' => $league_av['all'],
'spanGaps' => true,
'tension' => 0.5,
'borderColor' => '#00a6f4',
'backgroundColor' => '#00a6f4',
'pointStyle' => false,
'borderDash' => [5, 5],
'hidden' => true,
],
[
'label' => 'Average Defence',
'playing_date' => $date_home,
'results_per_event' => $results_home,
'events' => $events_home,
'data' => $league_av['def'],
'spanGaps' => true,
'tension' => 0.5,
'borderColor' => '#155dfc',
'backgroundColor' => 'transparent',
'pointStyle' => false,
'borderDash' => [5, 5],
'hidden' => true,
],
[
'label' => 'Average Attak',
'playing_date' => $date_home,
'results_per_event' => $results_home,
'events' => $events_home,
'data' => $league_av['att'],
'spanGaps' => true,
'tension' => 0.5,
'borderColor' => '#155dfc',
'backgroundColor' => '#155dfc',
'pointStyle' => false,
'borderDash' => [5, 5],
'hidden' => true,
],
[
'label' => 'Average Midfield',
'playing_date' => $date_home,
'results_per_event' => $results_home,
'events' => $events_home,
'data' => $league_av['mid'],
'spanGaps' => true,
'tension' => 0.5,
'borderColor' => '#155dfc',
'backgroundColor' => 'transparent',
'pointStyle' => false,
'borderDash' => [5, 5],
'hidden' => true,
],
],
'labels' => $labels,
];
return $data;
}
public static function filterMatches($res, array $matches, $team_id = 0)
{
if (! $res->count()) {
return ['all', 'def', 'att', 'mid'];
}
$result = [];
foreach ($res as $value) {
$match_id = $value->match_id;
if (! isset($result[$match_id])) {
$result[$match_id]['all']['ply'] = 0;
$result[$match_id]['all']['sum_min'] = 0;
$result[$match_id]['all']['rating'] = 0;
$result[$match_id]['att']['ply'] = 0;
$result[$match_id]['att']['sum_min'] = 0;
$result[$match_id]['att']['rating'] = 0;
$result[$match_id]['mid']['ply'] = 0;
$result[$match_id]['mid']['sum_min'] = 0;
$result[$match_id]['mid']['rating'] = 0;
$result[$match_id]['def']['ply'] = 0;
$result[$match_id]['def']['sum_min'] = 0;
$result[$match_id]['def']['rating'] = 0;
}
if ($team_id == 0 || $value->activeteam_id == $team_id) {
if ($value->minutes_played > 0) {
$result[$match_id]['all']['ply']++;
$result[$match_id]['all']['sum_min'] += (int) $value->minutes_played;
$result[$match_id]['all']['rating'] += (float) $value->playerrating_value;
if ($value->player_position == 'M') {
$result[$match_id]['mid']['ply']++;
$result[$match_id]['mid']['sum_min'] += (int) $value->minutes_played;
$result[$match_id]['mid']['rating'] += (float) $value->playerrating_value;
} elseif ($value->player_position == 'F') {
$result[$match_id]['att']['ply']++;
$result[$match_id]['att']['sum_min'] += (int) $value->minutes_played;
$result[$match_id]['att']['rating'] += (float) $value->playerrating_value;
} elseif ($value->player_position == 'D') {
$result[$match_id]['def']['ply']++;
$result[$match_id]['def']['sum_min'] += (int) $value->minutes_played;
$result[$match_id]['def']['rating'] += (float) $value->playerrating_value;
}
}
}
}
// dd($result);
$return = [];
foreach ($matches as $matchid) {
if (isset($result[$matchid])) {
$return['all'][] = round($result[$matchid]['all']['rating'] / $result[$matchid]['all']['ply'], 1);
if ($result[$matchid]['def']['sum_min']) {
$return['def'][] = round($result[$matchid]['def']['rating'] / $result[$matchid]['def']['ply'], 1);
} else {
$return['def'][] = null;
}
if ($result[$matchid]['att']['sum_min']) {
$return['att'][] = round($result[$matchid]['att']['rating'] / $result[$matchid]['att']['ply'], 1);
} else {
$return['att'][] = null;
}
if ($result[$matchid]['mid']['sum_min']) {
$return['mid'][] = round($result[$matchid]['mid']['rating'] / $result[$matchid]['mid']['ply'], 1);
} else {
$return['mid'][] = null;
}
} else {
$return['all'][] = null;
$return['def'][] = null;
$return['att'][] = null;
$return['mid'][] = null;
}
}
// dd($return);
// while (array_last($return['all']) == null) {
// }
return $return;
}
public static function shortenEnding(array &$labels, array &$homes, array &$aways)
{
// dd($labels, $homes, $aways);
if (! isset($homes['all'])) {
return;
}
$count_home = 0;
$count_away = 0;
if (isset($homes['all'])) {
for ($i = \count($homes['all']) - 1; $i > 0; $i--) {
if ($homes['all'][$i] == null) {
$count_home++;
} else {
break;
}
}
}
if (isset($aways['all'])) {
for ($i = \count($aways['all']) - 1; $i > 0; $i--) {
if ($aways['all'][$i] == null) {
$count_away++;
} else {
break;
}
}
}
$keeps = count($homes['all']) - min($count_home, $count_away) - 1;
if (isset($homes['all'])) {
$homes['all'] = array_slice($homes['all'], 0, $keeps);
$homes['def'] = array_slice($homes['def'], 0, $keeps);
$homes['att'] = array_slice($homes['att'], 0, $keeps);
$homes['mid'] = array_slice($homes['mid'], 0, $keeps);
}
if (isset($aways['all'])) {
$aways['all'] = array_slice($aways['all'], 0, $keeps);
$aways['def'] = array_slice($aways['def'], 0, $keeps);
$aways['att'] = array_slice($aways['att'], 0, $keeps);
$aways['mid'] = array_slice($aways['mid'], 0, $keeps);
}
$labels = array_slice($labels, 0, $keeps);
// $labels = range(1, $keeps);
}
public static function makeAv(array &$arr, int $length)
{
if (isset($arr['all']) && count($arr['all'])) {
$all = isset($arr['all']) ? array_sum($arr['all']) / count($arr['all']) : 1;
$def = isset($arr['def']) ? array_sum($arr['def']) / count($arr['def']) : 1;
$mid = isset($arr['mid']) ? array_sum($arr['mid']) / count($arr['mid']) : 1;
$att = isset($arr['att']) ? array_sum($arr['att']) / count($arr['att']) : 1;
$ret = [];
$ret['all'] = array_fill(0, $length, round($all, 2));
$ret['def'] = array_fill(0, $length, round($def, 2));
$ret['mid'] = array_fill(0, $length, round($mid, 2));
$ret['att'] = array_fill(0, $length, round($att, 2));
} else {
$ret = [];
$ret['all'] = [];
$ret['def'] = [];
$ret['mid'] = [];
$ret['att'] = [];
}
return $ret;
}
public static function leagueAv(array &$arr, int $len)
{
if (isset($arr['all'])) {
$all = array_sum($arr['all']) / count($arr['all']);
$def = array_sum($arr['def']) / count($arr['def']);
$mid = array_sum($arr['mid']) / count($arr['mid']);
$att = array_sum($arr['att']) / count($arr['att']);
} else {
$all = 0;
$def = 0;
$mid = 0;
$att = 0;
}
$ret = [];
$ret['all'] = array_fill(0, $len, round($all, 2));
$ret['def'] = array_fill(0, $len, round($def, 2));
$ret['mid'] = array_fill(0, $len, round($mid, 2));
$ret['att'] = array_fill(0, $len, round($att, 2));
return $ret;
}
}
@@ -0,0 +1,91 @@
<?php
namespace App\Filament\Widgets\Charts;
use App\Models\StatistikoDetail;
use App\Models\StatistikoPlayer;
use Illuminate\Support\Carbon;
class LoadPlayerPerformance
{
public static $last_query = [];
public static function load($filter, bool $hasdots)
{
// if (self::$last_query) {
// return self::$last_query;
// }
$league_id = (int) $filter['league_id'] ?? 0;
$team_id = (int) $filter['team_id'] ?? 0;
$ss_player_id = (int) $filter['ss_player_id'] ?? 0;
$statistic_type = $filter['statistic_type'] ?? 'gls';
$player_on_field = $filter['player_on_field'];
if (! $league_id) {
return [];
}
if (! $team_id) {
return [];
}
if (! $ss_player_id) {
return [];
}
$player_name = StatistikoDetail::where('ss_player_id', (int) $ss_player_id)->value('player_name');
if ($statistic_type == 'none') {
$statistic_type = 'gls';
}
$matches_played = StatistikoPlayer::with('event')
->where('ss_player_id', (int) $ss_player_id)
->when($player_on_field, function ($query) use ($player_on_field) {
switch ($player_on_field) {
case 'lineup':
return $query->where('lineup', 'T');
case 'substituted':
return $query->where('lineup', 'P');
}
})->get();
$tmp = [];
foreach ($matches_played as $value) {
$val = $value->playerrating_value;
$key = $value->event ? round($value->event->starttime->diffInDays(Carbon::now())) : 0;
$tmp["$key"] = $val;
}
krsort($tmp);
$dataset = [];
$labels = [];
foreach ($tmp as $key => $value) {
$labels[] = $key;
$dataset[] = $value;
}
// $labels = array_keys($dataset);
$data = [
'datasets' => [
[
'label' => 'Player Rating',
'data' => $dataset,
'tension' => 0.5,
'borderColor' => '#36A2EB',
'pointStyle' => $hasdots,
],
],
'labels' => $labels,
'player_name' => $player_name,
];
self::$last_query = $data;
return $data;
}
}
@@ -0,0 +1,183 @@
<?php
namespace App\Filament\Widgets\Charts;
use App\Filament\Pages\Selections\Helper\GetSeason;
use App\Models\StatistikoDetail;
use App\Models\StatistikoEvent;
use App\Models\StatistikoPlayer;
use Illuminate\Support\Carbon;
class LoadPlayerWidgets
{
public static $last_query = [];
public static function load(array $filter, bool $hasdots)
{
// dd($filter);
// if (self::$last_query) {
// return self::$last_query;
// }
$team_position = $filter['team_position'];
$league_id = (int) $filter['league_id'] ?? 0;
$team_id = (int) $filter['team_id'] ?? 0;
$ss_player_id = (int) $filter['ss_player_id'] ?? 0;
$player_on_field = $filter['player_on_field'] ?? 'all';
$season = $filter['season'];
$seasonmode = $filter['seasonmode'];
$season = GetSeason::load($season, $seasonmode);
// dd($player_on_field);
$statistic_type = $filter['statistic_type'] ?? 'gls';
$statistic_name = HelperStatisticType::get($filter);
if (! $league_id) {
return [];
}
if (! $team_id) {
return [];
}
if (! $ss_player_id) {
return [];
}
if ($statistic_type == 'none') {
$statistic_type = 'gls';
}
$player_name = StatistikoDetail::where('ss_player_id', (int) $ss_player_id)->value('player_name');
$matches_season = StatistikoEvent::whereIn('season', $season)
->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();
// dd($matches_season);
$matches_played = StatistikoPlayer::query()
->whereIn('match_id', $matches_season)
->where('ss_player_id', $ss_player_id)
->when($player_on_field, function ($query) use ($player_on_field) {
// 'all' => 'All',
// 'lineup' => 'Lineup',
// 'substituted' => 'Substituted',
// 'notplayed' => 'Not Played',
switch ($player_on_field) {
case 'all':
return $query->where('minutes_played', '>', 0);
case 'lineup':
return $query->where('lineup', 'T')->where('minutes_played', '>', 0);
case 'substituted':
return $query->where('lineup', 'P')->where('minutes_played', '>', 0);
default:
return $query->where('minutes_played', '>', 0);
}
})
->pluck('match_id')->toArray();
$res = StatistikoPlayer::with('event')
->where('ss_player_id', (int) $ss_player_id)
->when($matches_played, function ($query) use ($matches_played, $player_on_field) {
if ($player_on_field == 'notplayed') {
return $query->whereNotIn('match_id', $matches_played);
} else {
return $query->whereIn('match_id', $matches_played);
}
})->get();
$tmp = [];
foreach ($res as $value) {
$val = 0;
$key = 0;
if (isset($value->event->starttime)) {
$key = (int) round($value->event->starttime->diffInDays(Carbon::now()));
switch ($statistic_type) {
case 'gls':
$val = (int) $value->goals;
break;
case 'crn':
$val = (int) 0;
break;
case 'fls':
$val = (int) $value->fouls;
break;
case 'ofs':
$val = (int) $value->offsides;
break;
case 'crd':
$val = (int) $value->card_yellow + $value->card_red + $value->card_yellowred;
break;
case 'snt':
$val = (int) $value->shots_on_target;
break;
case 'tsh':
$val = (int) $value->shots_off_target;
break;
}
$tmp[$key] = $val;
}
}
krsort($tmp);
$dataset = [];
$labels = [];
foreach ($tmp as $key => $value) {
$labels[] = $key;
$dataset[] = $value;
}
$avverage = array_sum($dataset) / count($dataset);
$dataset2 = array_fill(0, count($dataset), $avverage);
$data = [
'datasets' => [
[
'label' => ucfirst($statistic_name),
'data' => $dataset,
'tension' => 0.5,
'borderColor' => '#36A2EB',
'pointStyle' => $hasdots,
],
],
'labels' => $labels,
'player_name' => $player_name,
];
$data['datasets'][] = [
'label' => 'Average',
'data' => $dataset2,
'tension' => 0.5,
'borderColor' => '#ad46ff',
'backgroundColor' => '#ad46ff',
'borderDash' => [5, 5],
'pointStyle' => false,
'hidden' => false,
'average_team_home' => [],
'average_team_away' => [],
];
self::$last_query = $data;
return $data;
}
}
@@ -0,0 +1,33 @@
<?php
namespace App\Filament\Widgets\PlayerProps;
class BoxNames
{
public static function load()
{
return [
2 => 'DL',
4 => 'MR',
6 => 'LW',
9 => 'DC',
10 => 'DM',
11 => 'MC',
12 => 'AM',
15 => 'SW',
16 => 'DC',
17 => 'DM',
18 => 'MC',
19 => 'AM',
20 => 'SS',
21 => 'ST',
23 => 'DC',
24 => 'DM',
25 => 'MC',
26 => 'AM',
30 => 'DR',
32 => 'ML',
34 => 'RW',
];
}
}
@@ -0,0 +1,247 @@
<?php
namespace App\Filament\Widgets\PlayerProps;
use App\Models\StatisticFixtures;
use App\Models\StatistikoEvent;
class Expectations
{
public static function load(StatisticFixtures $match)
{
$home_id = $match->home_id;
$away_id = $match->away_id;
$data = StatistikoEvent::where(function ($query) use ($home_id, $away_id) {
return $query->whereIn('home_id', [$home_id, $away_id])->orWhereIn('away_id', [$home_id, $away_id]);
})->get();
$work = [];
$bettypes = ['gls', 'fls', 'crn', 'ofs', 'crd', 'snt', 'tsh'];
foreach ($data as $value) {
foreach ($bettypes as $type) {
if ($value['home_id'] == $home_id) {
$work[$type]['home_made_total'][] = $value[$type.'_h'];
$work[$type]['home_made_home'][] = $value[$type.'_h'];
$work[$type]['home_got_total'][] = $value[$type.'_a'];
$work[$type]['home_got_home'][] = $value[$type.'_a'];
} elseif ($value['away_id'] == $home_id) {
$work[$type]['home_made_total'][] = $value[$type.'_a'];
$work[$type]['home_got_total'][] = $value[$type.'_a'];
} elseif ($value['home_id'] == $away_id) {
$work[$type]['home_made_total'][] = $value[$type.'_a'];
$work[$type]['home_got_total'][] = $value[$type.'_a'];
} elseif ($value['away_id'] == $away_id) {
$work[$type]['home_made_total'][] = $value[$type.'_h'];
$work[$type]['home_made_home'][] = $value[$type.'_h'];
$work[$type]['home_got_total'][] = $value[$type.'_a'];
$work[$type]['home_got_home'][] = $value[$type.'_h'];
}
if ($value['away_id'] == $away_id) {
$work[$type]['away_made_total'][] = $value[$type.'_a'];
$work[$type]['away_made_away'][] = $value[$type.'_a'];
$work[$type]['away_got_total'][] = $value[$type.'_h'];
$work[$type]['away_got_away'][] = $value[$type.'_a'];
} elseif ($value['away_id'] == $home_id) {
$work[$type]['away_made_total'][] = $value[$type.'_h'];
$work[$type]['away_got_total'][] = $value[$type.'_h'];
} elseif ($value['home_id'] == $away_id) {
$work[$type]['away_made_total'][] = $value[$type.'_h'];
$work[$type]['away_got_total'][] = $value[$type.'_h'];
} elseif ($value['away_id'] == $away_id) {
$work[$type]['away_made_total'][] = $value[$type.'_a'];
$work[$type]['away_made_away'][] = $value[$type.'_a'];
$work[$type]['away_got_total'][] = $value[$type.'_h'];
$work[$type]['away_got_away'][] = $value[$type.'_a'];
}
}
}
$num_home_crd = 0;
$num_away_crd = 0;
$num_home_gls = 0;
$num_away_gls = 0;
$num_home_fls = 0;
$num_away_fls = 0;
$num_home_ofs = 0;
$num_away_ofs = 0;
$num_home_snt = 0;
$num_away_snt = 0;
$num_home_tsh = 0;
$num_away_tsh = 0;
$bettypes = ['gls', 'crd', 'fls', 'ofs', 'snt', 'tsh'];
foreach ($work as $type => $value) {
switch ($type) {
case 'gls':
$sum_home_gls = array_sum($value['home_made_total']);
$num_home_gls = \count($value['home_made_total']);
$sum_home_gls += array_sum($value['home_made_home']);
$num_home_gls += \count($value['home_made_home']);
$sum_home_gls += array_sum($value['home_got_total']);
$num_home_gls += \count($value['home_got_total']);
$sum_home_gls += array_sum($value['home_got_home']);
$num_home_gls += \count($value['home_got_home']);
$sum_away_gls = array_sum($value['away_made_total']);
$num_away_gls = \count($value['away_made_total']);
$sum_away_gls += array_sum($value['away_made_away']);
$num_away_gls += \count($value['away_made_away']);
$sum_away_gls += array_sum($value['away_got_total']);
$num_away_gls += \count($value['away_got_total']);
$sum_away_gls += array_sum($value['away_got_away']);
$num_away_gls += \count($value['away_got_away']);
break;
case 'crd':
$sum_home_crd = array_sum($value['home_made_total']);
$num_home_crd = \count($value['home_made_total']);
$sum_home_crd += array_sum($value['home_made_home']);
$num_home_crd += \count($value['home_made_home']);
$sum_home_crd += array_sum($value['home_got_total']);
$num_home_crd += \count($value['home_got_total']);
$sum_home_crd += array_sum($value['home_got_home']);
$num_home_crd += \count($value['home_got_home']);
$sum_away_crd = array_sum($value['away_made_total']);
$num_away_crd = \count($value['away_made_total']);
$sum_away_crd += array_sum($value['away_made_away']);
$num_away_crd += \count($value['away_made_away']);
$sum_away_crd += array_sum($value['away_got_total']);
$num_away_crd += \count($value['away_got_total']);
$sum_away_crd += array_sum($value['away_got_away']);
$num_away_crd += \count($value['away_got_away']);
break;
case 'fls':
$sum_home_fls = array_sum($value['home_made_total']);
$num_home_fls = \count($value['home_made_total']);
$sum_home_fls += array_sum($value['home_made_home']);
$num_home_fls += \count($value['home_made_home']);
$sum_home_fls += array_sum($value['home_got_total']);
$num_home_fls += \count($value['home_got_total']);
$sum_home_fls += array_sum($value['home_got_home']);
$num_home_fls += \count($value['home_got_home']);
$sum_away_fls = array_sum($value['away_made_total']);
$num_away_fls = \count($value['away_made_total']);
$sum_away_fls += array_sum($value['away_made_away']);
$num_away_fls += \count($value['away_made_away']);
$sum_away_fls += array_sum($value['away_got_total']);
$num_away_fls += \count($value['away_got_total']);
$sum_away_fls += array_sum($value['away_got_away']);
$num_away_fls += \count($value['away_got_away']);
break;
case 'ofs':
$sum_home_ofs = array_sum($value['home_made_total']);
$num_home_ofs = \count($value['home_made_total']);
$sum_home_ofs += array_sum($value['home_made_home']);
$num_home_ofs += \count($value['home_made_home']);
$sum_home_ofs += array_sum($value['home_got_total']);
$num_home_ofs += \count($value['home_got_total']);
$sum_home_ofs += array_sum($value['home_got_home']);
$num_home_ofs += \count($value['home_got_home']);
$sum_away_ofs = array_sum($value['away_made_total']);
$num_away_ofs = \count($value['away_made_total']);
$sum_away_ofs += array_sum($value['away_made_away']);
$num_away_ofs += \count($value['away_made_away']);
$sum_away_ofs += array_sum($value['away_got_total']);
$num_away_ofs += \count($value['away_got_total']);
$sum_away_ofs += array_sum($value['away_got_away']);
$num_away_ofs += \count($value['away_got_away']);
break;
case 'snt':
$sum_home_snt = array_sum($value['home_made_total']);
$num_home_snt = \count($value['home_made_total']);
$sum_home_snt += array_sum($value['home_made_home']);
$num_home_snt += \count($value['home_made_home']);
$sum_home_snt += array_sum($value['home_got_total']);
$num_home_snt += \count($value['home_got_total']);
$sum_home_snt += array_sum($value['home_got_home']);
$num_home_snt += \count($value['home_got_home']);
$sum_away_snt = array_sum($value['away_made_total']);
$num_away_snt = \count($value['away_made_total']);
$sum_away_snt += array_sum($value['away_made_away']);
$num_away_snt += \count($value['away_made_away']);
$sum_away_snt += array_sum($value['away_got_total']);
$num_away_snt += \count($value['away_got_total']);
$sum_away_snt += array_sum($value['away_got_away']);
$num_away_snt += \count($value['away_got_away']);
break;
case 'tsh':
$sum_home_tsh = array_sum($value['home_made_total']);
$num_home_tsh = \count($value['home_made_total']);
$sum_home_tsh += array_sum($value['home_made_home']);
$num_home_tsh += \count($value['home_made_home']);
$sum_home_tsh += array_sum($value['home_got_total']);
$num_home_tsh += \count($value['home_got_total']);
$sum_home_tsh += array_sum($value['home_got_home']);
$num_home_tsh += \count($value['home_got_home']);
$sum_away_tsh = array_sum($value['away_made_total']);
$num_away_tsh = \count($value['away_made_total']);
$sum_away_tsh += array_sum($value['away_made_away']);
$num_away_tsh += \count($value['away_made_away']);
$sum_away_tsh += array_sum($value['away_got_total']);
$num_away_tsh += \count($value['away_got_total']);
$sum_away_tsh += array_sum($value['away_got_away']);
$num_away_tsh += \count($value['away_got_away']);
break;
}
}
$aspettativa = [];
$aspettativa['home']['gls'] = round($sum_home_gls / $num_home_gls, 1);
$aspettativa['home']['crd'] = round($sum_home_crd / $num_home_crd, 1);
$aspettativa['home']['fls'] = round($sum_home_fls / $num_home_fls, 1);
$aspettativa['home']['ofs'] = round($sum_home_ofs / $num_home_ofs, 1);
$aspettativa['home']['snt'] = round($sum_home_snt / $num_home_snt, 1);
$aspettativa['home']['tsh'] = round($sum_home_tsh / $num_home_tsh, 1);
$aspettativa['away']['gls'] = round($sum_away_gls / $sum_away_gls, 1);
$aspettativa['away']['crd'] = round($sum_away_crd / $num_away_crd, 1);
$aspettativa['away']['fls'] = round($sum_away_fls / $num_away_fls, 1);
$aspettativa['away']['ofs'] = round($sum_away_ofs / $num_away_ofs, 1);
$aspettativa['away']['snt'] = round($sum_away_snt / $num_away_snt, 1);
$aspettativa['away']['tsh'] = round($sum_away_tsh / $num_away_tsh, 1);
return $aspettativa;
}
}
@@ -0,0 +1,61 @@
<?php
namespace App\Filament\Widgets\PlayerProps;
class LineUpMap
{
public static function load()
{
return [
'3313' => [9, 16, 23, 11, 18, 25, 19, 6, 34, 21],
'3331' => [9, 16, 23, 17, 11, 25, 12, 19, 26, 21],
'3331-' => [9, 16, 23, 10, 18, 24, 12, 19, 26, 21],
'3331+' => [9, 16, 23, 11, 18, 25, 12, 19, 26, 21],
'3412-' => [9, 16, 23, 4, 10, 24, 32, 19, 20, 21],
'3412+' => [9, 16, 23, 4, 11, 25, 32, 19, 20, 21],
'3421-' => [9, 16, 23, 4, 10, 24, 32, 12, 26, 21],
'3421+' => [9, 16, 23, 4, 11, 25, 32, 12, 26, 21],
'343-' => [9, 16, 23, 4, 10, 24, 32, 6, 34, 21],
'343+' => [9, 16, 23, 4, 11, 25, 32, 6, 34, 21],
'3511' => [9, 16, 23, 4, 11, 17, 25, 32, 19, 21],
'3511-' => [9, 16, 23, 4, 10, 18, 24, 32, 19, 21],
'3511+' => [9, 16, 23, 4, 11, 18, 25, 32, 19, 21],
'352' => [9, 16, 23, 4, 11, 17, 25, 32, 20, 21],
'352-' => [9, 16, 23, 4, 10, 18, 24, 32, 20, 21],
'352+' => [9, 16, 23, 4, 11, 18, 25, 32, 20, 21],
'4132' => [2, 9, 23, 30, 17, 12, 19, 26, 20, 21],
'4213-' => [2, 9, 23, 30, 10, 24, 19, 6, 34, 21],
'4213+' => [2, 9, 23, 30, 11, 25, 19, 6, 34, 21],
'4222' => [2, 9, 23, 30, 10, 24, 12, 26, 20, 21],
'4231' => [2, 9, 23, 30, 10, 24, 12, 19, 26, 21],
'424' => [2, 9, 23, 30, 10, 24, 6, 34, 20, 21],
'4312' => [2, 9, 23, 30, 17, 11, 25, 19, 20, 21],
'4312-' => [2, 9, 23, 30, 10, 18, 24, 19, 20, 21],
'4312+' => [2, 9, 23, 30, 11, 18, 25, 19, 20, 21],
'4321' => [2, 9, 23, 30, 17, 11, 25, 12, 26, 21],
'4321-' => [2, 9, 23, 30, 10, 18, 24, 12, 26, 21],
'4321+' => [2, 9, 23, 30, 11, 18, 25, 12, 26, 21],
'433' => [2, 9, 23, 30, 17, 11, 25, 6, 34, 21],
'433-' => [2, 9, 23, 30, 10, 18, 24, 6, 34, 21],
'433+' => [2, 9, 23, 30, 11, 18, 25, 6, 34, 21],
'4411-' => [2, 9, 23, 30, 4, 10, 24, 32, 19, 21],
'4411+' => [2, 9, 23, 30, 4, 11, 25, 32, 19, 21],
'442' => [2, 9, 23, 30, 4, 17, 18, 32, 20, 21],
'442-' => [2, 9, 23, 30, 4, 10, 24, 32, 20, 21],
'442+' => [2, 9, 23, 30, 4, 11, 25, 32, 20, 21],
'451' => [2, 9, 23, 30, 4, 17, 11, 25, 32, 21],
'451-' => [2, 9, 23, 30, 4, 10, 18, 24, 32, 21],
'451+' => [2, 9, 23, 30, 4, 11, 18, 25, 32, 21],
'523-' => [2, 9, 16, 23, 30, 10, 24, 6, 34, 21],
'523+' => [2, 9, 16, 23, 30, 11, 25, 6, 34, 21],
'5311' => [2, 9, 16, 23, 30, 17, 11, 25, 19, 21],
'5311-' => [2, 9, 16, 23, 30, 10, 18, 24, 19, 21],
'5311+' => [2, 9, 16, 23, 30, 11, 18, 25, 19, 21],
'532' => [2, 9, 16, 23, 30, 17, 11, 25, 20, 21],
'532-' => [2, 9, 16, 23, 30, 10, 18, 24, 20, 21],
'532+' => [2, 9, 16, 23, 30, 11, 18, 25, 20, 21],
'541-' => [2, 9, 16, 23, 30, 4, 10, 24, 32, 21],
'541+' => [2, 9, 16, 23, 30, 4, 11, 25, 32, 21],
];
}
}
+675
View File
@@ -0,0 +1,675 @@
<?php
namespace App\Filament\Widgets;
use App\Filament\Widgets\PlayerProps\BoxNames;
use App\Filament\Widgets\PlayerProps\Expectations;
use App\Filament\Widgets\PlayerProps\LineUpMap;
use App\Livewire\PlayerCalculator;
use App\Models\ExpectedMinimumPosition;
use App\Models\SofaScorePlayerPerSeason;
use App\Models\SofaScorePlayerPosition;
use App\Models\SofaScoreRosa;
use App\Models\SsLineupMemory;
use App\Models\StatisticFixtures;
use Filament\Notifications\Notification;
use Filament\Widgets\Widget;
use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\On;
/**
* --- Aspettativa di Gioco (AdG) = Somma Goals fatti da Player nel DB / Somma Minuti Giocati da Player (SMG) nel DB * 90. Se la SMG è < Y per quel Player prenderemo in considerazione solo l'Aspettativa Statistica (AS). Il valore Y dovrebbe essere configurabile in una interfaccia. Il valore iniziale lo fissiamo a Y = 180
*/
class PlayerPropsDrop extends Widget
{
protected string $view = 'livewire.player-props-drop';
public float $x_value = 3;
public float $y_value = 180;
public array $activeBoxes;
public array $beschriftung;
public array $lineup;
public array $lineUpMap;
public string $activeLineUp;
public array $boxes;
public string $team_name = '';
public int $team_id = 0;
public int $match_id;
public int $player_on_field_counter;
public array $calculationVariables;
public array $players;
public function mount(): void
{
$this->activeBoxes = BoxNames::load();
$this->lineUpMap = LineUpMap::load();
$this->player_on_field_counter = 0;
for ($i = 1; $i <= 35; $i++) {
$this->boxes[$i] = [];
if (isset($this->activeBoxes[$i])) {
$this->beschriftung[$i] = $this->activeBoxes[$i];
} else {
$this->beschriftung[$i] = '';
}
}
$this->lineup = $this->lineUpMap[$this->activeLineUp];
}
#[On('clear-all')]
public function clearAll()
{
$this->team_name = '';
$this->match_id = 0;
for ($i = 1; $i <= 35; $i++) {
$this->boxes[$i] = [];
}
$this->players = [];
$this->dispatch('update-players', players: $this->players);
}
#[On('match-update')]
public function matchUpdate(?int $match_id)
{
$this->team_name = '';
$this->match_id = 0;
$this->players = [];
for ($i = 1; $i <= 35; $i++) {
$this->boxes[$i] = [];
}
if ($match_id) {
$this->match_id = $match_id;
}
$this->dispatch('update-players', players: $this->players);
}
#[On('team-update')]
public function syncData(?int $team_id)
{
if ($team_id) {
$this->players = PlayerCalculator::load($team_id);
$this->team_name = SofaScoreRosa::where('ss_team_id', $team_id)->value('ss_team_name');
$this->team_id = $team_id;
$this->loadPlacement();
} else {
$this->team_name = '';
$this->clearResultTable();
$this->players = [];
}
}
#[On('lineup-update')]
public function lineUpUpdate(int|string $activeLineUp)
{
$this->activeLineUp = $activeLineUp;
$this->lineup = $this->lineUpMap[$activeLineUp];
$this->loadPlacement();
}
#[On('element-dropped-in-box')]
public function handleElementDropped(mixed $elementData, mixed $boxNumber): void
{
$boxNumber = (int) $boxNumber;
$player = is_array($elementData) ? $elementData : json_decode($elementData, true);
if (! $player || ! isset($player['id'])) {
return;
}
// when drag from field to field remove from prviouse field to prevent doubles
foreach ($this->boxes as $k => $record) {
if (count($record) && $record['id'] == (int) $player['id']) {
$this->clearBox($k);
}
}
// when drag from source remove from proviuse field
foreach ($this->players as $k => $record) {
if ($record['id'] == (int) $player['id']) {
if ($this->boxes[$boxNumber]) {
$this->clearBox($boxNumber);
}
$this->boxes[$boxNumber] = $record;
$this->players[$k]['active'] = 1;
$this->players[$k]['pos'] = $this->activeBoxes[$boxNumber];
$this->player_on_field_counter++;
}
}
$this->storePlacement();
if ($this->player_on_field_counter >= 10) {
$this->calculateAspg();
} else {
$this->dispatch('update-players', players: $this->players);
}
}
public function loadPlacement()
{
$this->clearResultTable();
if ($this->team_id) {
$this->player_on_field_counter = 0;
$res = SsLineupMemory::where('client_id', Auth::user()->client_id)->where('team_id', $this->team_id)->where('lineup', $this->activeLineUp)->first();
if ($res) {
// Log::debug('SsLineupMemory', $res->toArray());
$placement = json_decode($res->placement, 1);
foreach ($this->players as $k => $record) {
// dd($this->lineup, $record, $stored_positions);
$id = $record['id'];
if (isset($placement[$id]) && in_array($placement[$id], $this->lineup)) {
$this->boxes[$placement[$id]] = $record;
$this->players[$k]['active'] = 1;
$this->players[$k]['pos'] = $record['pos_ori'];
$this->player_on_field_counter++;
}
}
}
}
$this->calculateAspg();
}
public function storePlacement()
{
$store = [];
foreach ($this->boxes as $pos => $value) {
if ($value) {
$store[$value['id']] = $pos;
}
}
SsLineupMemory::updateOrCreate([
'client_id' => Auth::user()->client_id,
'team_id' => $this->team_id,
'lineup' => $this->activeLineUp,
], [
'placement' => json_encode($store),
'team_name' => $this->team_name,
]);
}
public function updateLineup(?string $state)
{
$this->clearResultTable();
if (isset($this->lineupsMap[$state])) {
$this->lineup = $this->lineupsMap[$state];
} else {
$this->lineup = [];
}
}
public function clearBox(int $boxNumber): void
{
if (isset($this->boxes[$boxNumber])) {
$tmp = $this->boxes[$boxNumber];
$player_id = 0;
foreach ($tmp as $key => $value) {
if ($key == 'id') {
$player_id = $value;
}
}
foreach ($this->players as $k => $record) {
if ($record['id'] == (int) $player_id) {
$this->boxes[$boxNumber] = [];
$this->players[$k]['pos'] = '';
$this->players[$k]['active'] = 0;
$this->player_on_field_counter--;
}
}
foreach ($this->players as $k => $record) {
$this->players[$k]['gls'] = '';
$this->players[$k]['fls'] = '';
$this->players[$k]['ofs'] = '';
$this->players[$k]['crd'] = '';
$this->players[$k]['snt'] = '';
$this->players[$k]['tsh'] = '';
}
$this->storePlacement();
$this->loadPlacement();
}
}
public function clearResultTable(): void
{
for ($i = 1; $i <= 35; $i++) {
$this->boxes[$i] = [];
}
foreach ($this->players as $k => $record) {
// $this->players[$k] = [];
$this->players[$k]['active'] = 0;
$this->players[$k]['gls'] = '';
$this->players[$k]['fls'] = '';
$this->players[$k]['ofs'] = '';
$this->players[$k]['crd'] = '';
$this->players[$k]['snt'] = '';
$this->players[$k]['tsh'] = '';
}
$this->player_on_field_counter = 0;
$this->dispatch('update-players', players: $this->players);
}
public function copyDevelopment()
{
if ($this->player_on_field_counter < 10) {
Notification::make()->title('Needs a calculation first ')
->info()
->send();
return;
}
$copystring = '';
foreach ($this->calculationVariables as $row) {
if ($copystring == '') {
$keys = array_keys($row);
$copystring .= implode(';', $keys) . "\n";
}
$copystring .= implode(';', $row) . "\n";
}
$this->js("navigator.clipboard.writeText(`$copystring`)");
Notification::make()
->title('Calculation variables copied')
->success()
->send();
}
public function copyResult()
{
if ($this->player_on_field_counter < 10) {
Notification::make()->title('Needs a calculation first ')
->info()
->send();
return;
}
$header = ['name', 'foot', 'events', 'average min', 'position', 'on field', 'gls', 'fls', 'ofs', 'crd', 'snt', 'tsh'];
$copystring = implode(';', $header) . "\n";
foreach ($this->players as $row) {
$tmp = [];
$tmp[] = $row['name'];
$tmp[] = $row['foot'];
$tmp[] = $row['tot_evt'];
$tmp[] = $row['ave_min'];
if ($row['pos']) {
$tmp[] = $row['pos'];
} else {
$tmp[] = $row['pos_ori'];
}
$tmp[] = $row['active'];
$tmp[] = $row['gls'];
$tmp[] = $row['fls'];
$tmp[] = $row['ofs'];
$tmp[] = $row['crd'];
$tmp[] = $row['snt'];
$tmp[] = $row['tsh'];
$copystring .= implode(';', $tmp) . "\n";
}
$this->js("navigator.clipboard.writeText(`$copystring`)");
Notification::make()
->title('Results copied')
->success()
->send();
}
public function calculateAspg($manual = false): void
{
if ($this->player_on_field_counter < 10) {
foreach ($this->players as $k => $record) {
$this->players[$k]['gls'] = '';
$this->players[$k]['fls'] = '';
$this->players[$k]['ofs'] = '';
$this->players[$k]['crd'] = '';
$this->players[$k]['snt'] = '';
$this->players[$k]['tsh'] = '';
}
$this->dispatch('update-players', players: $this->players);
if ($manual) {
Notification::make()->title('Calculation needs 10 player on field')
->info()
->send();
}
return;
}
// Calcolare Aspettativa Team per GOALS
// (il valore che appare quando viene selezionato un Evento): nell' esempio,
// se scegliamo come Team il Remo (Home) il valore di riferimento sarà 1.2
$team_id = $this->team_id;
$match = StatisticFixtures::where('id', $this->match_id)->first();
$asp_team = 0;
$team_home_away = 'home';
if ((int) $match->home_id == (int) $team_id) {
$asp_team = (float) $match->exp_home;
$team_home_away = 'home';
} elseif ((int) $match->away_id == (int) $team_id) {
$asp_team = (float) $match->exp_away;
$team_home_away = 'away';
}
$player_totals = SofaScorePlayerPerSeason::with('details')->where('total_min', '>', 0)->where('season', 'total')->where('ss_team_id', $team_id)->get();
$count_player = 0;
foreach ($player_totals as $key => $value) {
if ($value->details != null && $value->details->position != 'GK' && (int) $value->details->is_active != 0) {
$count_player++;
}
}
$results = [];
foreach ($player_totals as $val) {
if ($val->details != null && $val->details->position != 'GK' && (int) $val->details->is_active != 0) {
/***
"goals" => 0
"fouls" => 13
"cards" => 3
"offsides" => 0
"shots_on_target" => 3
"shots_off_target" => 2
"total_shots" => 4
*/
$ss_player_id = $val->ss_player_id;
$position = $val->details->position;
$tmp = [];
$tmp['id'] = $ss_player_id;
$tmp['name'] = $val->details->player_name;
$tmp['id_team'] = $team_id;
$tmp['asp_team'] = $asp_team;
$tmp['player_count_without_gk'] = $count_player;
$position_field = $this->get_position($ss_player_id);
if ($position_field) {
$position = $position_field;
$tmp['active'] = 1;
} else {
$tmp['active'] = 0;
}
$tmp['pos'] = $position;
// Aspettativa di Gioco (AdG) = Somma Goals fatti da Player nel DB / Somma Minuti Giocati da Player (SMG) nel DB * 90.
// Se la SMG è < Y per quel Player prenderemo in considerazione solo l'Aspettativa Statistica (AS).
// Il valore Y dovrebbe essere configurabile in una interfaccia. Il valore iniziale lo fissiamo a Y = 180
// Somma Minuti Giocati da Player (SMG) nel DB
$tmp['somma_minuti'] = $val->total_min;
$tmp['shots_on_target'] = $val->shots_on_target;
$tmp['shots_off_target'] = $val->shots_off_target;
$tmp['shots_blocked'] = $val->shots_blocked;
// il valore corrispondente al ruolo del Player (esempio un giocatore in Details ha ruolo = RW
// quindi Aspettativa Statistica (AS) per RW = 0.219)
// exp_goals
// exp_assists
// exp_cards
// exp_fouls
// exp_was_fouled
// exp_offsides
// exp_total_shots
// exp_shots_on_target
$bettypes = ['goals', 'cards', 'fouls', 'offsides', 'total_shots', 'shots_on_target'];
foreach ($bettypes as $bettype) {
$asp_statistica = (float) SofaScorePlayerPosition::where('ss_code', $position)->value('exp_' . $bettype);
$tmp['asp_statistica_' . $bettype] = $asp_statistica;
// if ($val->ss_player_id == 243651)
// dd($val, $asp_statistica);
// if ($val->total_min < $this->y_value) {
// $asp_gioco = 0;
// } else {
// $asp_gioco = $val->shots_on_target / $val->total_min * 90;
// }
switch ($bettype) {
case 'goals':
$asp_gioco = $val->goals / $val->total_min * 90;
if ($asp_gioco == 0 || $val->total_min < $this->y_value) {
$tmp['asp_gioco_' . $bettype] = 0;
$tmp['asp_teorica_' . $bettype] = $asp_statistica;
} else {
$tmp['asp_gioco_' . $bettype] = $asp_gioco;
$tmp['asp_teorica_' . $bettype] = ($this->x_value * $asp_gioco + $asp_statistica) / (1 + $this->x_value);
}
break;
case 'cards':
$asp_gioco = $val->cards / $val->total_min * 90;
if ($asp_gioco == 0 || $val->total_min < $this->y_value) {
$tmp['asp_gioco_' . $bettype] = 0;
$tmp['asp_teorica_' . $bettype] = $asp_statistica;
} else {
$tmp['asp_gioco_' . $bettype] = $asp_gioco;
$tmp['asp_teorica_' . $bettype] = ($this->x_value * $asp_gioco + $asp_statistica) / (1 + $this->x_value);
}
break;
case 'fouls':
$asp_gioco = $val->fouls / $val->total_min * 90;
if ($asp_gioco == 0 || $val->total_min < $this->y_value) {
$tmp['asp_gioco_' . $bettype] = 0;
$tmp['asp_teorica_' . $bettype] = $asp_statistica;
} else {
$tmp['asp_gioco_' . $bettype] = $asp_gioco;
$tmp['asp_teorica_' . $bettype] = ($this->x_value * $asp_gioco + $asp_statistica) / (1 + $this->x_value);
}
break;
case 'offsides':
$asp_gioco = $val->offsides / $val->total_min * 90;
if ($asp_gioco == 0 || $val->total_min < $this->y_value) {
$tmp['asp_gioco_' . $bettype] = 0;
$tmp['asp_teorica_' . $bettype] = $asp_statistica;
} else {
$tmp['asp_gioco_' . $bettype] = $asp_gioco;
$tmp['asp_teorica_' . $bettype] = ($this->x_value * $asp_gioco + $asp_statistica) / (1 + $this->x_value);
}
break;
case 'total_shots':
$asp_gioco = $val->total_shots / $val->total_min * 90;
if ($asp_gioco == 0 || $val->total_min < $this->y_value) {
$tmp['asp_gioco_' . $bettype] = 0;
$tmp['asp_teorica_' . $bettype] = $asp_statistica;
} else {
$tmp['asp_gioco_' . $bettype] = $asp_gioco;
$tmp['asp_teorica_' . $bettype] = ($this->x_value * $asp_gioco + $asp_statistica) / (1 + $this->x_value);
}
break;
case 'shots_on_target':
$asp_gioco = $val->shots_on_target / $val->total_min * 90;
if ($asp_gioco == 0 || $val->total_min < $this->y_value) {
$tmp['asp_gioco_' . $bettype] = 0;
$tmp['asp_teorica_' . $bettype] = $asp_statistica;
} else {
$tmp['asp_gioco_' . $bettype] = $asp_gioco;
$tmp['asp_teorica_' . $bettype] = ($this->x_value * $asp_gioco + $asp_statistica) / (1 + $this->x_value);
}
break;
}
}
// Calcolare la Somma di tutte le AT (colonna G della Tabella)
// Considerare la ATR calcolata allo Step 1 (colonna I della Tabella)
// Aspettativa per Player: AP = AT * ATR / TOT AT
$results[] = $tmp;
}
}
$asp_team_all = Expectations::load($match);
// Aspettativa Team di Riferimento
// (ATR) = Aspettativa Team * Numero di Giocatori di Team in Rosters (esclusi i portieri) / 10.
// Ad esempio per Remo (supponiamo 24 giocatori nel Roster esclusi i portieri): ATR = 1.2 * 24 / 10 = 2.88
$bettypes = ['goals', 'cards', 'fouls', 'offsides', 'total_shots', 'shots_on_target'];
foreach ($bettypes as $bettype) {
$total_bettype = array_sum(array_column($results, 'asp_teorica_' . $bettype));
foreach ($results as $key => $value) {
switch ($bettype) {
case 'goals':
// Aspettativa per Player: AP = AT * ATR / TOT AT
// $results[$key]['asp_player_'.$bettype] = ((float) $value['asp_team'] * (float) $value['asp_teorica_'.$bettype]) / $total_bettype;
// $results[$key]['asp_player_'.$bettype] = ($asp_team * $asp_team_riferimento) / $total_bettype;
$asp_team_riferimento = (float) $asp_team * $count_player / 10;
$results[$key]['asp_riferimento_goals'] = $asp_team_riferimento;
$results[$key]['asp_player_' . $bettype] = $value['asp_teorica_' . $bettype] * $asp_team_riferimento / $total_bettype;
$results[$key]['asp_total_' . $bettype] = $total_bettype;
break;
case 'cards':
$asp_team_riferimento = (float) $asp_team_all[$team_home_away]['crd'] * $count_player / 10;
$results[$key]['asp_team_riferimento_card'] = $asp_team_riferimento;
$results[$key]['asp_total_' . $bettype] = $total_bettype;
$results[$key]['asp_player_' . $bettype] = $value['asp_teorica_' . $bettype] * $asp_team_riferimento / $total_bettype;
break;
case 'fouls':
$asp_team_riferimento = (float) $asp_team_all[$team_home_away]['fls'] * $count_player / 10;
$results[$key]['asp_team_riferimento_fouls'] = $asp_team_riferimento;
$results[$key]['asp_total_' . $bettype] = $total_bettype;
$results[$key]['asp_player_' . $bettype] = $value['asp_teorica_' . $bettype] * $asp_team_riferimento / $total_bettype;
break;
case 'offsides':
$asp_team_riferimento = (float) $asp_team_all[$team_home_away]['ofs'] * $count_player / 10;
$results[$key]['asp_team_riferimento_offside'] = $asp_team_riferimento;
$results[$key]['asp_total_' . $bettype] = $total_bettype;
$results[$key]['asp_player_' . $bettype] = $value['asp_teorica_' . $bettype] * $asp_team_riferimento / $total_bettype;
break;
case 'total_shots':
$asp_team_riferimento = (float) $asp_team_all[$team_home_away]['tsh'] * $count_player / 10;
$results[$key]['asp_team_riferimento_tsh'] = $asp_team_riferimento;
$results[$key]['asp_total_' . $bettype] = $total_bettype;
$results[$key]['asp_player_' . $bettype] = $value['asp_teorica_' . $bettype] * $asp_team_riferimento / $total_bettype;
break;
case 'shots_on_target':
$asp_team_riferimento = (float) $asp_team_all[$team_home_away]['snt'] * $count_player / 10;
$results[$key]['asp_team_riferimento_snt'] = $asp_team_riferimento;
$results[$key]['asp_total_' . $bettype] = $total_bettype;
$results[$key]['asp_player_' . $bettype] = $value['asp_teorica_' . $bettype] * $asp_team_riferimento / $total_bettype;
break;
}
}
}
$map = [];
$res = ExpectedMinimumPosition::all();
foreach ($res as $val) {
$map[$val->position]['gls'] = $val->gls;
$map[$val->position]['crd'] = $val->crd;
$map[$val->position]['fls'] = $val->fls;
$map[$val->position]['ofs'] = $val->ofs;
$map[$val->position]['tsh'] = $val->tsh;
$map[$val->position]['snt'] = $val->snt;
}
// stesso ordine di prima: GLS, CRD, FLS, OFS, TSH, SNT
foreach ($this->players as $k => $player) {
foreach ($results as $key => $result) {
if ((int) $player['id'] == (int) $result['id']) {
$this->players[$k]['active'] = $result['active'];
$pos = $this->players[$k]['pos'];
if (!$pos)
$pos = $this->players[$k]['pos_ori'];
$tamx = number_format($map[$pos]['gls'], 3);
$final = number_format($result['asp_player_goals'], 3);
$results[$key]['finale_tamx_gls'] = $tamx;
$results[$key]['finale_calc_gls'] = $final;
$this->players[$k]['gls'] = (float) $final > (float) $tamx ? $final : $tamx;
$tamx = number_format($map[$pos]['crd'], 3);
$final = number_format($result['asp_player_cards'], 3);
$results[$key]['finale_tamx_crd'] = $tamx;
$results[$key]['finale_calc_crd'] = $final;
$this->players[$k]['crd'] = (float) $final > (float) $tamx ? $final : $tamx;
$tamx = number_format($map[$pos]['fls'], 3);
$final = number_format($result['asp_player_fouls'], 3);
$results[$key]['finale_tamx_fls'] = $tamx;
$results[$key]['finale_calc_fls'] = $final;
$this->players[$k]['fls'] = (float) $final > (float) $tamx ? $final : $tamx;
$tamx = number_format($map[$pos]['ofs'], 3);
$final = number_format($result['asp_player_offsides'], 3);
$results[$key]['finale_tamx_ofs'] = $tamx;
$results[$key]['finale_calc_ofs'] = $final;
$this->players[$k]['ofs'] = (float) $final > (float) $tamx ? $final : $tamx;
$tamx = number_format($map[$pos]['tsh'], 3);
$final = number_format($result['asp_player_total_shots'], 3);
$results[$key]['finale_tamx_tsh'] = $tamx;
$results[$key]['finale_calc_tsh'] = $final;
$this->players[$k]['tsh'] = (float) $final > (float) $tamx ? $final : $tamx;
$tamx = number_format($map[$pos]['snt'], 3);
$final = number_format($result['asp_player_shots_on_target'], 3);
$results[$key]['finale_tamx_snt'] = $tamx;
$results[$key]['finale_calc_snt'] = $final;
$this->players[$k]['snt'] = (float) $final > (float) $tamx ? $final : $tamx;
}
}
}
$this->calculationVariables = $results;
$this->dispatch('update-players', players: $this->players);
}
public function get_position(int $ss_player_id)
{
// see if player is in field and if yes get new position
foreach ($this->players as $record) {
if ($record['id'] == $ss_player_id) {
return $record['pos'];
}
}
return false;
}
}
+99
View File
@@ -0,0 +1,99 @@
<?php
namespace App\Filament\Widgets;
use App\Models\User;
use Filament\Forms\Components\Select;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Tables\Columns\ViewColumn;
use Filament\Tables\Enums\FiltersLayout;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Table;
use Filament\Widgets\TableWidget;
use Illuminate\Support\HtmlString;
use Livewire\Attributes\On;
class PlayerPropsTable extends TableWidget
{
use InteractsWithForms;
protected int|string|array $columnSpan = 2;
public int $team_id;
public array $players;
#[On('update-players')]
public function updatePlayers(array $players)
{
$this->players = $players;
}
public function getHeadingTable(): HtmlString
{
return new HtmlString('
<div class="w-full grid grid-cols-15 text-[10px] items-center gap-1" style="position: relative; left: -10px; bottom: -13px;">
<div>Gls</div>
<div>Fls</div>
<div>Ofs</div>
<div>Crd</div>
<div>Snt</div>
<div>Tsh</div>
<div>Foot</div>
<div>Evt</div>
<div>Min</div>
</div>');
}
public function table(Table $table): Table
{
return $table
->heading(false)
->query(User::query()->whereRaw('1 = 0')) // Verhindert DB-Abfragen
->striped()
->defaultSort('name')
->emptyStateHeading('No team selected')
->columns([
ViewColumn::make('drag_card')
->label(fn() => $this->getHeadingTable())
->view('filament.tables.columns.drag-card'),
])->extraAttributes([
'id' => 'playerdragtable',
])
->filters([
Filter::make('positions')
->columnSpan(2)
->schema([
Select::make('area')
->hiddenLabel()
->placeholder('Filter Positions')
->native(false)
->allowHtml()
->options([
'attack' => '<span class="text-amber-500">Attack</span>',
'midfield' => '<span class="text-blue-500">Midfield</span>',
'defence' => '<span class="text-green-500">Defence</span>',
'goalkeeper' => '<span class="text-gray-500">Goalkeeper</span>',
]),
])
->query(function ($query) {
return $query;
})->indicateUsing(function (array $data): array {
// empty array disables indicator-badge
return [];
}),
], layout: FiltersLayout::AboveContent)
->deferFilters(false)
->records(function () {
$collection = collect($this->players)->sortBy('order')->sortBy('active', SORT_NUMERIC, 1);
$selectedPosition = $this->tableFilters['positions']['area'] ?? null;
if (! empty($selectedPosition)) {
$collection = $collection->where('area', $selectedPosition);
}
return $collection;
});
}
}