wip Expectations

This commit is contained in:
salam committed 2026-08-14 19:02:58 +02:00
1 parent 3db428899c
commit 1dbdbcf586
26 files changed
+704 -268

No files matched your search

@@ -26,7 +26,7 @@ class SofaScoreRosaResource extends Resource
protected static ?string $modelLabel = 'Teams';
protected static string|UnitEnum|null $navigationGroup = 'SofaScore';
protected static string|UnitEnum|null $navigationGroup = 'Statistiko';
public static function form(Schema $schema): Schema
{
@@ -26,7 +26,7 @@ class SofaScoreTaskResource extends Resource
protected static ?int $navigationSort = 2;
protected static string|UnitEnum|null $navigationGroup = 'SofaScore';
protected static string|UnitEnum|null $navigationGroup = 'Statistiko';
protected function isReadOnly(): bool
{
@@ -17,7 +17,7 @@ class SofaScoreTournamentResource extends Resource
{
protected static ?string $model = SofaScoreTournament::class;
protected static string|UnitEnum|null $navigationGroup = 'SofaScore';
protected static string|UnitEnum|null $navigationGroup = 'Statistiko';
protected static ?string $cluster = StaticDataCluster::class;
@@ -20,7 +20,7 @@ class StatisticFixturesResource extends Resource
protected static ?string $modelLabel = 'Fixtures';
protected static string|UnitEnum|null $navigationGroup = 'SofaScore';
protected static string|UnitEnum|null $navigationGroup = 'Statistiko';
protected static ?int $navigationSort = 5;
@@ -0,0 +1,11 @@
<?php
namespace App\Filament\Clusters\StaticData\Resources\StatistikoConfigs\Pages;
use App\Filament\Clusters\StaticData\Resources\StatistikoConfigs\StatistikoConfigResource;
use Filament\Resources\Pages\CreateRecord;
class CreateStatistikoConfig extends CreateRecord
{
protected static string $resource = StatistikoConfigResource::class;
}
@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Clusters\StaticData\Resources\StatistikoConfigs\Pages;
use App\Filament\Clusters\StaticData\Resources\StatistikoConfigs\StatistikoConfigResource;
use Filament\Actions\DeleteAction;
use Filament\Resources\Pages\EditRecord;
class EditStatistikoConfig extends EditRecord
{
protected static string $resource = StatistikoConfigResource::class;
protected function getHeaderActions(): array
{
return [
DeleteAction::make(),
];
}
}
@@ -0,0 +1,12 @@
<?php
namespace App\Filament\Clusters\StaticData\Resources\StatistikoConfigs\Pages;
use App\Filament\Clusters\StaticData\Resources\StatistikoConfigs\StatistikoConfigResource;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
class ListStatistikoConfigs extends ListRecords
{
protected static string $resource = StatistikoConfigResource::class;
}
@@ -0,0 +1,26 @@
<?php
namespace App\Filament\Clusters\StaticData\Resources\StatistikoConfigs\Schemas;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Schema;
class StatistikoConfigForm
{
public static function configure(Schema $schema): Schema
{
return $schema
->components([
TextInput::make('group')
->required(),
TextInput::make('varname')
->required(),
TextInput::make('team')
->required(),
TextInput::make('name')
->required(),
TextInput::make('value')
->required(),
]);
}
}
@@ -0,0 +1,49 @@
<?php
namespace App\Filament\Clusters\StaticData\Resources\StatistikoConfigs;
use App\Filament\Clusters\StaticData\Resources\StatistikoConfigs\Pages\ListStatistikoConfigs;
use App\Filament\Clusters\StaticData\Resources\StatistikoConfigs\Schemas\StatistikoConfigForm;
use App\Filament\Clusters\StaticData\Resources\StatistikoConfigs\Tables\StatistikoConfigsTable;
use App\Filament\Clusters\StaticData\StaticDataCluster;
use App\Models\StatistikoConfig;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Tables\Table;
use UnitEnum;
class StatistikoConfigResource extends Resource
{
protected static ?string $model = StatistikoConfig::class;
protected static string|UnitEnum|null $navigationGroup = 'Statistiko';
protected static ?string $cluster = StaticDataCluster::class;
protected static ?string $navigationLabel = 'Configurations';
protected static ?string $modelLabel = 'Configurations';
protected static ?int $navigationSort = 15;
public static function form(Schema $schema): Schema
{
return StatistikoConfigForm::configure($schema);
}
public static function table(Table $table): Table
{
return StatistikoConfigsTable::configure($table);
}
public static function getPages(): array
{
return [
'index' => ListStatistikoConfigs::route('/'),
];
}
public static function getNavigationBadge(): ?string
{
return parent::getEloquentQuery()->count();
}
}
@@ -0,0 +1,57 @@
<?php
namespace App\Filament\Clusters\StaticData\Resources\StatistikoConfigs\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\TextInputColumn;
use Filament\Tables\Enums\FiltersLayout;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
class StatistikoConfigsTable
{
public static function configure(Table $table): Table
{
return $table
->columns([
TextColumn::make('group')->formatStateUsing(fn(string $state): string => match ($state) {
'gls' => 'Goals',
'crn' => 'Corner',
'fls' => 'Fouls',
'ofs' => 'Offside',
'crd' => 'Cards',
'snt' => 'Shots On Target',
'tsh' => 'Total Shots',
}),
TextColumn::make('team')->badge()
->color(fn(string $state): string => match ($state) {
'home' => 'info',
'away' => 'warning',
}),
TextColumn::make('varname')
->formatStateUsing(fn(string $state): string => strtoupper($state)),
TextInputColumn::make('value')
->prefix('xx.x')
->type('number')
->rules(['required', 'decimal:0.1,10']),
])
->filters([
SelectFilter::make('group')
->options([
'gls' => 'Goals',
'crn' => 'Corner',
'fls' => 'Fouls Commited',
'ofs' => 'Offside',
'crd' => 'Cards',
'snt' => 'Shots On Target',
'tsh' => 'Total Shots',
]),
SelectFilter::make('team')
->options([
'home' => 'Home',
'away' => 'Away',
])
], layout: FiltersLayout::AboveContent)
->deferFilters(false);
}
}
@@ -20,7 +20,7 @@ class StatistikoDetailResource extends Resource
protected static ?string $modelLabel = 'Details';
protected static string|UnitEnum|null $navigationGroup = 'SofaScore';
protected static string|UnitEnum|null $navigationGroup = 'Statistiko';
protected static ?string $cluster = StaticDataCluster::class;
@@ -20,7 +20,7 @@ class StatistikoEventsResource extends Resource
protected static ?string $modelLabel = 'Events';
protected static string|UnitEnum|null $navigationGroup = 'SofaScore';
protected static string|UnitEnum|null $navigationGroup = 'Statistiko';
protected static ?int $navigationSort = 6;
@@ -20,7 +20,7 @@ class StatistikaImportResource extends Resource
protected static ?string $modelLabel = 'File Uploads';
protected static string|UnitEnum|null $navigationGroup = 'SofaScore';
protected static string|UnitEnum|null $navigationGroup = 'Statistiko';
protected static ?int $navigationSort = 1;
@@ -20,7 +20,7 @@ class StatistikoPlayerResource extends Resource
protected static ?string $modelLabel = 'Player';
protected static string|UnitEnum|null $navigationGroup = 'SofaScore';
protected static string|UnitEnum|null $navigationGroup = 'Statistiko';
protected static ?string $cluster = StaticDataCluster::class;
+50 -243
View File
@@ -2,42 +2,27 @@
namespace App\Filament\Widgets\Data;
use Illuminate\Support\Carbon;
use App\Models\StatistikoEvent;
use App\Models\StatistikoDetail;
use App\Models\StatistikoPlayer;
use App\Models\StatisticFixtures;
use Illuminate\Support\Facades\Log;
use App\Filament\Widgets\Data\LoadEvents\LoadEventsAverages;
use App\Filament\Widgets\Data\LoadEvents\LoadEventsQuery;
use App\Filament\Widgets\Data\LoadEvents\LoadExpectations;
use App\Models\StatisticFixtures;
use App\Models\StatistikoEvent;
use App\Models\StatistikoPlayer;
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;
$season_or_date = $filter['season_or_date'] ?? 'season';
$season = $filter['season'] ?? 0;
$ss_player_id = (int) $filter['ss_player_id'] ?? 0;
$start = $filter['start_date'] ?? 0;
$end = $filter['end_date'] ?? 0;
$statistic_type = $filter['statistic_type'] ?? 'gls';
$team_position = $filter['team_position'];
$player_on_field = $filter['player_on_field'] ?? 'all';
$accuracy = (float) $filter['accuracy'] ?? 0.5;
$similar_past_matches = $filter['similar_past_matches'];
if (! $league_id) {
@@ -68,8 +53,8 @@ class LoadEvents
* 'league' => 'League',
* 'all' => 'All Database',
*/
$handicap_range = 0;
$total_range = 0;
$handicap_range = [];
$total_range = [];
if ($similar_past_matches != 'none') {
$team_position = '';
@@ -98,7 +83,6 @@ class LoadEvents
$description = '';
if ($ss_player_id) {
$matches_season = StatistikoEvent::where(function ($query) use ($team_id, $team_position) {
switch ($team_position) {
case 'home':
@@ -132,8 +116,6 @@ class LoadEvents
})
->pluck('match_id')->toArray();
// $description = ' with ' . StatistikoDetail::where('ss_player_id', (int) $ss_player_id)->value('name') . ' (' . \count($matches_played) . ')';
if (! $matches_played) {
$matches_played[] = -1;
}
@@ -142,52 +124,7 @@ class LoadEvents
/**
* STATTISTIC DATA
*/
$res = 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, $team_position, $similar_past_matches) {
if ($similar_past_matches == 'none') {
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);
}
}
})->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->where('starttime', '>=', $start);
})->when($end, function ($query) use ($end) {
return $query->where('starttime', '<=', $end);
})->when($season, function ($query) use ($season) {
return $query->whereIn('season', $season);
})
->orderBy('starttime', 'ASC')
->get();
if ($res == null) {
return [];
}
// Log::debug($res->toArray());
$res = LoadEventsQuery::load($filter, $matches_played, $handicap_range, $total_range);
$dataset_home = [];
$dataset_away = [];
@@ -199,17 +136,22 @@ class LoadEvents
$events = [];
$results = ['w' => 0, 'd' => 0, 'l' => 0, 'w2' => 0, 'l2' => 0];
// dd($res);
if (!\in_array($team_position, ['home', 'away']))
$team_position = 'all';
foreach ($res as $value) {
if (!isset($res[$team_position])) {
return [];
}
$labels[] = round($value['starttime']->diffInDays(Carbon::now()));
$expectations = LoadExpectations::load($res['all'], $match_id, $statistic_type);
// $labels[] = $value['starttime']->format('Y-m-d H:i');
foreach ($res[$team_position] as $value) {
$playing_date[] = $value['starttime']->format('d. F Y H:i');
$start = Carbon::createFromTimestamp($value['starttime']);
$labels[] = round($start->diffInDays(Carbon::now()));
$playing_date[] = $start->format('Y-m-d H:i');
$results_per_event[] = $value['gls_h'] . ' : ' . $value['gls_a'];
$results_per_event[] = $value['val_home'] . ' : ' . $value['val_away'];
if ($similar_past_matches != 'none') {
switch ($value['result_code']) {
@@ -225,38 +167,12 @@ class LoadEvents
$results['w2']++;
break;
}
switch ($statistic_type) {
case 'gls':
$val_home = (int) $value['gls_h'];
$val_away = (int) $value['gls_a'];
$dataset_exp_home[] = (float) round($value['exp_home'], 1);
$dataset_exp_away[] = (float) round($value['exp_away'], 1);
break;
case 'crn':
$val_home = (int) $value['crn_h'];
$val_away = (int) $value['crn_a'];
break;
case 'fls':
$val_home = (int) $value['fls_h'];
$val_away = (int) $value['fls_a'];
break;
case 'ofs':
$val_home = (int) $value['ofs_h'];
$val_away = (int) $value['ofs_a'];
break;
case 'crd':
$val_home = (int) $value['crd_h'];
$val_away = (int) $value['crd_a'];
break;
case 'snt':
$val_home = (int) $value['snt_h'];
$val_away = (int) $value['snt_a'];
break;
case 'tsh':
$val_home = (int) $value['tsh_h'];
$val_away = (int) $value['tsh_a'];
break;
}
$val_home = (int) $value['val_home'];
$val_away = (int) $value['val_away'];
$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']) {
@@ -273,38 +189,11 @@ class LoadEvents
break;
}
switch ($statistic_type) {
case 'gls':
$val_home = (int) $value['gls_h'];
$val_away = (int) $value['gls_a'];
$dataset_exp_home[] = (float) round($value['exp_home'], 1);
$dataset_exp_away[] = (float) round($value['exp_away'], 1);
break;
case 'crn':
$val_home = (int) $value['crn_h'];
$val_away = (int) $value['crn_a'];
break;
case 'fls':
$val_home = (int) $value['fls_h'];
$val_away = (int) $value['fls_a'];
break;
case 'ofs':
$val_home = (int) $value['ofs_h'];
$val_away = (int) $value['ofs_a'];
break;
case 'crd':
$val_home = (int) $value['crd_h'];
$val_away = (int) $value['crd_a'];
break;
case 'snt':
$val_home = (int) $value['snt_h'];
$val_away = (int) $value['snt_a'];
break;
case 'tsh':
$val_home = (int) $value['tsh_h'];
$val_away = (int) $value['tsh_a'];
break;
}
$val_home = (int) $value['val_home'];
$val_away = (int) $value['val_away'];
$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']) {
@@ -321,38 +210,11 @@ class LoadEvents
break;
}
switch ($statistic_type) {
case 'gls':
$val_home = (int) $value['gls_a'];
$val_away = (int) $value['gls_h'];
$dataset_exp_home[] = (float) round($value['exp_away'], 1);
$dataset_exp_away[] = (float) round($value['exp_home'], 1);
break;
case 'crn':
$val_home = (int) $value['crn_a'];
$val_away = (int) $value['crn_h'];
break;
case 'fls':
$val_home = (int) $value['fls_a'];
$val_away = (int) $value['fls_h'];
break;
case 'ofs':
$val_home = (int) $value['ofs_a'];
$val_away = (int) $value['ofs_h'];
break;
case 'crd':
$val_home = (int) $value['crd_a'];
$val_away = (int) $value['crd_h'];
break;
case 'snt':
$val_home = (int) $value['snt_a'];
$val_away = (int) $value['snt_h'];
break;
case 'tsh':
$val_home = (int) $value['tsh_a'];
$val_away = (int) $value['tsh_h'];
break;
}
$val_home = (int) $value['val_away'];
$val_away = (int) $value['val_home'];
$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']);
@@ -381,79 +243,21 @@ class LoadEvents
break;
}
switch ($statistic_type) {
case 'gls':
if ($team_id == $value['home_id']) {
$val_home = (int) $value['gls_h'];
$val_away = (int) $value['gls_a'];
$dataset_exp_home[] = (float) round($value['exp_home'], 1);
$dataset_exp_away[] = (float) round($value['exp_away'], 1);
} else {
$val_home = (int) $value['gls_a'];
$val_away = (int) $value['gls_h'];
$dataset_exp_home[] = (float) round($value['exp_away'], 1);
$dataset_exp_away[] = (float) round($value['exp_home'], 1);
}
break;
case 'crn':
if ($team_id == $value['home_id']) {
$val_home = (int) $value['crn_h'];
$val_away = (int) $value['crn_a'];
} else {
$val_home = (int) $value['crn_a'];
$val_away = (int) $value['crn_h'];
}
break;
case 'fls':
if ($team_id == $value['home_id']) {
$val_home = (int) $value['fls_h'];
$val_away = (int) $value['fls_a'];
} else {
$val_home = (int) $value['fls_a'];
$val_away = (int) $value['fls_h'];
}
break;
case 'ofs':
if ($team_id == $value['home_id']) {
$val_home = (int) $value['ofs_h'];
$val_away = (int) $value['ofs_a'];
} else {
$val_home = (int) $value['ofs_a'];
$val_away = (int) $value['ofs_h'];
}
break;
case 'crd':
if ($team_id == $value['home_id']) {
$val_home = (int) $value['crd_h'];
$val_away = (int) $value['crd_a'];
} else {
$val_home = (int) $value['crd_a'];
$val_away = (int) $value['crd_h'];
}
break;
case 'snt':
if ($team_id == $value['home_id']) {
$val_home = (int) $value['snt_h'];
$val_away = (int) $value['snt_a'];
} else {
$val_home = (int) $value['snt_a'];
$val_away = (int) $value['snt_h'];
}
break;
case 'tsh':
if ($team_id == $value['home_id']) {
$val_home = (int) $value['tsh_h'];
$val_away = (int) $value['tsh_a'];
} else {
$val_home = (int) $value['tsh_a'];
$val_away = (int) $value['tsh_h'];
}
break;
if ($team_id == $value['home_id']) {
$val_home = (int) $value['val_home'];
$val_away = (int) $value['val_away'];
$dataset_exp_home[] = (float) round($value['exp_home'], 1);
$dataset_exp_away[] = (float) round($value['exp_away'], 1);
} else {
$val_home = (int) $value['val_away'];
$val_away = (int) $value['val_home'];
$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->ss_team_name . ' vs ' . $value->away->ss_team_name;
$events[] = $value['home'] . ' vs ' . $value['away'];
$dataset_home[] = $val_home;
$dataset_away[] = $val_away;
}
@@ -467,6 +271,7 @@ class LoadEvents
$label2 = 'Against';
}
self::shortenEnding($labels, $dataset_home, $dataset_away);
$data = [
@@ -507,6 +312,8 @@ class LoadEvents
'home_team' => $home_team,
'away_team' => $away_team,
'similar_past_matches' => $similar_past_matches,
'expectations_home' => $expectations['home'],
'expectations_away' => $expectations['away'],
];
if ($statistic_type == 'gls') {
$data['datasets'][] = [
@@ -0,0 +1,118 @@
<?php
namespace App\Filament\Widgets\Data\LoadEvents;
use App\Models\StatistikoEvent;
class LoadEventsQuery
{
public static function load(array $filter, array $matches_played, array $handicap_range, array $total_range)
{
$league_id = (int) $filter['league_id'] ?? 0;
$team_id = (int) $filter['team_id'] ?? 0;
$season = $filter['season'] ?? 0;
$start = $filter['start_date'] ?? 0;
$end = $filter['end_date'] ?? 0;
$player_on_field = $filter['player_on_field'] ?? 'all';
$similar_past_matches = $filter['similar_past_matches'];
$statistic_type = $filter['statistic_type'] ?? 'gls';
if ($statistic_type == 'none') {
$statistic_type = 'gls';
}
/**
* STATTISTIC DATA
*/
$res = 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, $similar_past_matches) {
if ($similar_past_matches == 'none') {
return $query->where('home_id', '=', $team_id)
->orWhere('away_id', '=', $team_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->where('starttime', '>=', $start);
})->when($end, function ($query) use ($end) {
return $query->where('starttime', '<=', $end);
})->when($season, function ($query) use ($season) {
return $query->whereIn('season', $season);
})
->orderBy('starttime', 'ASC')
->get();
$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'] = $value->home->ss_team_name;
$tmp['away'] = $value->away->ss_team_name;
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,117 @@
<?php
namespace App\Filament\Widgets\Data\LoadEvents;
use App\Models\StatisticFixtures;
use App\Models\StatistikoConfig;
class LoadExpectations
{
public static function load(array $data, int $match_id, string $statistic_type)
{
$match = StatisticFixtures::where('id', $match_id)->first();
$home_id = $match->home_id;
$away_id = $match->away_id;
$config = StatistikoConfig::where('group', $statistic_type)->get();
$home_made_total = 1;
$home_made_home = 1;
$home_got_total = 1;
$home_got_home = 1;
$away_made_total = 1;
$away_made_home = 1;
$away_got_total = 1;
$away_got_home = 1;
foreach ($config as $value) {
$varname = str_replace($statistic_type . '_', '', $value->varname);
switch ($varname) {
case 'home_made_total':
$home_made_total = (float) $value->value;
break;
case 'home_made_home':
$home_made_home = (float) $value->value;
break;
case 'home_got_total':
$home_got_total = (float) $value->value;
break;
case 'home_got_home':
$home_got_home = (float) $value->value;
break;
case 'away_made_total':
$away_made_total = (float) $value->value;
break;
case 'away_made_home':
$away_made_home = (float) $value->value;
break;
case 'away_got_total':
$away_got_total = (float) $value->value;
break;
case 'away_got_home':
$away_got_home = (float) $value->value;
break;
}
}
$h_made_t = [];
$h_made_h = [];
$h_got_t = [];
$h_got_h = [];
$a_made_t = [];
$a_made_a = [];
$a_got_t = [];
$a_got_a = [];
foreach ($data as $value) {
// HOME
if ($value['home_id'] == $home_id || $value['away_id'] == $home_id) {
$h_made_t[] = $value['val_home'];
$h_got_t[] = $value['val_away'];
}
if ($value['home_id'] == $home_id) {
$h_made_h[] = $value['val_home'];
$h_got_h[] = $value['val_away'];
}
// AWAY
if ($value['home_id'] == $away_id || $value['away_id'] == $away_id) {
$a_made_t[] = $value['val_away'];
$a_made_a[] = $value['val_home'];
}
if ($value['away_id'] == $away_id) {
$a_made_a[] = $value['val_away'];
$a_got_a[] = $value['val_home'];
}
}
$summe_home = array_sum($h_made_t) * $home_made_total;
$summe_home += array_sum($h_made_h) * $home_made_home;
$summe_home += array_sum($h_got_t) * $home_got_total;
$summe_home += array_sum($h_got_h) * $home_got_home;
$count_home = \count($h_made_t);
$count_home += \count($h_made_h);
$count_home += \count($h_got_t);
$count_home += \count($h_got_h);
$count_home = !$count_home ? 1 : $count_home;
$aspettativa_home = round($summe_home / $count_home, 2);
$summe_away = array_sum($a_made_t) * $away_made_total;
$summe_away += array_sum($a_made_a) * $away_made_home;
$summe_away += array_sum($a_got_t) * $away_got_total;
$summe_away += array_sum($a_got_a) * $away_got_home;
$count_away = \count($a_made_t);
$count_away += \count($a_made_a);
$count_away += \count($a_got_t);
$count_away += \count($a_got_a);
$count_away = !$count_away ? 1 : $count_away;
$aspettativa_away = round($summe_away / $count_away, 2);
return ['home' => $aspettativa_home, 'away' => $aspettativa_away];
}
}
+33 -10
View File
@@ -9,7 +9,6 @@ use App\Utilities\Round;
use Filament\Widgets\Concerns\InteractsWithPageFilters;
use Filament\Widgets\StatsOverviewWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\HtmlString;
use Livewire\Attributes\Reactive;
@@ -101,8 +100,11 @@ class StatsMedianAverage extends StatsOverviewWidget
$average_team_away = 0;
$average_league_home = 0;
$average_league_away = 0;
$expectations_home = 0;
$expectations_away = 0;
// Log::debug($data);
$expectations_home = $data['expectations_home'] ?? 0;
$expectations_away = $data['expectations_away'] ?? 0;
foreach ($data['datasets'] as $value) {
if ($value['label'] == 'Average Team') {
@@ -119,37 +121,58 @@ class StatsMedianAverage extends StatsOverviewWidget
$boxes = [];
// BOX 1
$boxes[] = Stat::make('Number', new HtmlString('<div id="number-of-events">' . $total_home . '</div>'))
->description('Events');
$boxes[] = Stat::make('Total', new HtmlString('<div id="number-of-events">' . $total_home . '</div>'))
->description('Events')
->extraAttributes([
'class' => 'box-info',
]);
// ->extraAttributes(['x-init' => "animate('number-of-events', $total_home, 0)"]);
// BOX 2
$boxes[] = Stat::make('Average ' . $statistic_type, self::template('avhome', 'avaway', $home_team, $away_team, $value_home, $value_away))
->description('Team ' . $team_position);
->description('Team ' . $team_position)
->extraAttributes([
'class' => 'box-success',
]);
// ->extraAttributes(['x-init' => "animate('avhome', $value_home); animate('avaway', $value_away)"]);
// BOX 3
// Log::debug([$average_team_home, $average_team_away]);
$boxes[] = Stat::make('Average ' . $statistic_type, self::template('av_team_home', 'av_team_away', $home_team, $away_team, $average_team_home, $average_team_away))
->description('Team Season');
->description('Team Season')
->extraAttributes([
'class' => 'box-success',
]);
// ->extraAttributes(['x-init' => "animate('av_team_home', $average_team_home); animate('av_team_away', $average_team_away)"]);
// BOX 4
$boxes[] = Stat::make('Average ' . $statistic_type, self::template('av_league_home', 'av_league_away', 'Home', 'Away', $average_league_home, $average_league_away))
->description('League Season');
->description('League Season')
->extraAttributes([
'class' => 'box-success',
]);
// ->extraAttributes(['x-init' => "animate('av_league_home', $average_league_home); animate('av_league_away', $average_league_away)"]);
// BOX 5
$boxes[] = Stat::make('Odds', self::templateOdds($data, $win, $draw, $lost))
->description($team_position);
->description($team_position)
->extraAttributes([
'class' => 'box-purple',
]);
// ->extraAttributes(['x-init' => "animate('mehome', $median_home); animate('meaway', $median_away, 0)"]);
// BOX 6
$boxes[] = Stat::make($statistic_type, self::template('expectations_home', 'expectations_away', 'Home', 'Away', $expectations_home, $expectations_away))
->description('Expectations')
->extraAttributes([
'class' => 'box-yellow',
]);
$this->columns = [
'default' => 1,
'sm' => 2,
'md' => 3,
'lg' => 4,
'xl' => 5,
'xl' => 6,
];
return $boxes;