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
+691 -255

No files matched your search

+2
View File
@@ -28,3 +28,5 @@ https://www.chartjs.org/docs/latest/configuration/interactions.html
https://www.sofascore.com/api/v1/unique-tournament/17/season/96668/standings/total
/** @var \App\Models\User */
@@ -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;
+38 -231
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'];
$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);
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;
}
} 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'];
$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);
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;
}
} 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'];
$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);
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;
}
} 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'];
$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['gls_a'];
$val_away = (int) $value['gls_h'];
$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);
}
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 (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;
+12
View File
@@ -0,0 +1,12 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class StatistikoConfig extends Model
{
protected $fillable = [
'value',
];
}
+1
View File
@@ -82,6 +82,7 @@ class AppServiceProvider extends ServiceProvider
'sky' => Color::Sky,
'yellow' => Color::Yellow,
'teal' => Color::Teal,
'purple' => Color::Purple,
]);
}
}
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('statistiko_configs', function (Blueprint $table) {
$table->id();
$table->string('group');
$table->string('team');
$table->string('varname');
$table->decimal('value', 3, 2)->default(1);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('statistiko_configs');
}
};
+1
View File
@@ -27,6 +27,7 @@ class DatabaseSeeder extends Seeder
AlarmLevelSeeder::class,
OddsNameSeeder::class,
AddByMethodSeeder::class,
StatistikoConfigSeeder::class
]);
}
}
@@ -0,0 +1,74 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class StatistikoConfigSeeder extends Seeder
{
public function run(): void
{
$sql = "INSERT INTO `statistiko_configs` (`id`, `group`, `team`, `varname`, `value`, `created_at`, `updated_at`)
VALUES
(1, 'gls', 'home', 'gls_home_made_total', '1', NULL, NULL),
(2, 'gls', 'home', 'gls_home_made_home', '1', NULL, NULL),
(3, 'gls', 'home', 'gls_home_got_total', '1', NULL, NULL),
(4, 'gls', 'home', 'gls_home_got_home', '1', NULL, NULL),
(5, 'gls', 'away', 'gls_away_made_total', '1', NULL, NULL),
(6, 'gls', 'away', 'gls_away_made_home', '1', NULL, NULL),
(7, 'gls', 'away', 'gls_away_got_total', '1', NULL, NULL),
(8, 'gls', 'away', 'gls_away_got_home', '1', NULL, NULL),
(9, 'crn', 'home', 'crn_home_made_total', '1', NULL, NULL),
(10, 'crn', 'home', 'crn_home_made_home', '1', NULL, NULL),
(11, 'crn', 'home', 'crn_home_got_total', '1', NULL, NULL),
(12, 'crn', 'home', 'crn_home_got_home', '1', NULL, NULL),
(13, 'crn', 'away', 'crn_away_made_total', '1', NULL, NULL),
(14, 'crn', 'away', 'crn_away_made_home', '1', NULL, NULL),
(15, 'crn', 'away', 'crn_away_got_total', '1', NULL, NULL),
(16, 'crn', 'away', 'crn_away_got_home', '1', NULL, NULL),
(17, 'fls', 'home', 'fls_home_made_total', '1', NULL, NULL),
(18, 'fls', 'home', 'fls_home_made_home', '1', NULL, NULL),
(19, 'fls', 'home', 'fls_home_got_total', '1', NULL, NULL),
(20, 'fls', 'home', 'fls_home_got_home', '1', NULL, NULL),
(21, 'fls', 'away', 'fls_away_made_total', '1', NULL, NULL),
(22, 'fls', 'away', 'fls_away_made_home', '1', NULL, NULL),
(23, 'fls', 'away', 'fls_away_got_total', '1', NULL, NULL),
(24, 'fls', 'away', 'fls_away_got_home', '1', NULL, NULL),
(25, 'ofs', 'home', 'ofs_home_made_total', '1', NULL, NULL),
(26, 'ofs', 'home', 'ofs_home_made_home', '1', NULL, NULL),
(27, 'ofs', 'home', 'ofs_home_got_total', '1', NULL, NULL),
(28, 'ofs', 'home', 'ofs_home_got_home', '1', NULL, NULL),
(29, 'ofs', 'away', 'ofs_away_made_total', '1', NULL, NULL),
(30, 'ofs', 'away', 'ofs_away_made_home', '1', NULL, NULL),
(31, 'ofs', 'away', 'ofs_away_got_total', '1', NULL, NULL),
(32, 'ofs', 'away', 'ofs_away_got_home', '1', NULL, NULL),
(33, 'crd', 'home', 'crd_home_made_total', '1', NULL, NULL),
(34, 'crd', 'home', 'crd_home_made_home', '1', NULL, NULL),
(35, 'crd', 'home', 'crd_home_got_total', '1', NULL, NULL),
(36, 'crd', 'home', 'crd_home_got_home', '1', NULL, NULL),
(37, 'crd', 'away', 'crd_away_made_total', '1', NULL, NULL),
(38, 'crd', 'away', 'crd_away_made_home', '1', NULL, NULL),
(39, 'crd', 'away', 'crd_away_got_total', '1', NULL, NULL),
(40, 'crd', 'away', 'crd_away_got_home', '1', NULL, NULL),
(41, 'snt', 'home', 'snt_home_made_total', '1', NULL, NULL),
(42, 'snt', 'home', 'snt_home_made_home', '1', NULL, NULL),
(43, 'snt', 'home', 'snt_home_got_total', '1', NULL, NULL),
(44, 'snt', 'home', 'snt_home_got_home', '1', NULL, NULL),
(45, 'snt', 'away', 'snt_away_made_total', '1', NULL, NULL),
(46, 'snt', 'away', 'snt_away_made_home', '1', NULL, NULL),
(47, 'snt', 'away', 'snt_away_got_total', '1', NULL, NULL),
(48, 'snt', 'away', 'snt_away_got_home', '1', NULL, NULL),
(49, 'tsh', 'home', 'tsh_home_made_total', '1', NULL, NULL),
(50, 'tsh', 'home', 'tsh_home_made_home', '1', NULL, NULL),
(51, 'tsh', 'home', 'tsh_home_got_total', '1', NULL, NULL),
(52, 'tsh', 'home', 'tsh_home_got_home', '1', NULL, NULL),
(53, 'tsh', 'away', 'tsh_away_made_total', '1', NULL, NULL),
(54, 'tsh', 'away', 'tsh_away_made_home', '1', NULL, NULL),
(55, 'tsh', 'away', 'tsh_away_got_total', '1', NULL, NULL),
(56, 'tsh', 'away', 'tsh_away_got_home', '1', NULL, NULL);
";
DB::unprepared($sql);
}
}
+26 -6
View File
@@ -103,10 +103,22 @@ input[type="radio"].fi-radio-input {
}
/*
Green Stat Widgets
Statistiko BOX Widgets
*/
.fi-sc-component .fi-wi-stats-overview-stat {
@apply bg-green-50 dark:bg-green-500/10 border border-green-500/30 dark:border-green-700/30 p-3
.box-info {
@apply bg-info-50 dark:bg-info-500/20 border border-info-500/30 dark:border-info-900 drop-shadow-xl p-2
}
.box-success {
@apply bg-success-50 dark:bg-success-500/20 border border-success-500/30 dark:border-success-900 drop-shadow-xl p-2
}
.box-purple {
@apply bg-purple-50 dark:bg-purple-500/20 border border-purple-500/30 dark:border-purple-900 drop-shadow-xl p-2
}
.box-yellow {
@apply bg-yellow-50 dark:bg-yellow-500/20 border border-yellow-500/30 dark:border-yellow-900 drop-shadow-xl p-2
}
/*
@@ -120,7 +132,7 @@ widget space to top menu
widget space to filter
*/
.fi-page-content {
row-gap: 1rem;
row-gap: 2rem;
}
/*
@@ -131,11 +143,11 @@ widget space to filter
}
.fi-wi-stats-overview-stat-label {
@apply text-sm font-bold mx-auto text-blue-600 dark:text-blue-500
@apply text-sm font-bold mx-auto
}
.fi-wi-stats-overview-stat-description span {
@apply mx-auto text-blue-600 dark:text-blue-500;
@apply mx-auto;
}
.fi-wi-stats-overview-stat-value {
@@ -214,3 +226,11 @@ less padding in table
#player_selector .fi-dropdown-header {
@apply px-2 text-lg font-black dark:bg-black border-y border-gray-300 dark:text-gray-300 dark:border-gray-600
}
@layer components {
.fi-tabs-item {
&.fi-active {
@apply bg-gray-100 dark:bg-gray-600/30 drop-shadow
}
}
}
+56
View File
@@ -0,0 +1,56 @@
gls, home, gls_home_made_total, 1
gls, home, gls_home_made_home, 1
gls, home, gls_home_got_total, 1
gls, home, gls_home_got_home, 1
gls, away, gls_away_made_total, 1
gls, away, gls_away_made_home, 1
gls, away, gls_away_got_total, 1
gls, away, gls_away_got_home, 1
crn, home, crn_home_made_total, 1
crn, home, crn_home_made_home, 1
crn, home, crn_home_got_total, 1
crn, home, crn_home_got_home, 1
crn, away, crn_away_made_total, 1
crn, away, crn_away_made_home, 1
crn, away, crn_away_got_total, 1
crn, away, crn_away_got_home, 1
fls, home, fls_home_made_total, 1
fls, home, fls_home_made_home, 1
fls, home, fls_home_got_total, 1
fls, home, fls_home_got_home, 1
fls, away, fls_away_made_total, 1
fls, away, fls_away_made_home, 1
fls, away, fls_away_got_total, 1
fls, away, fls_away_got_home, 1
ofs, home, ofs_home_made_total, 1
ofs, home, ofs_home_made_home, 1
ofs, home, ofs_home_got_total, 1
ofs, home, ofs_home_got_home, 1
ofs, away, ofs_away_made_total, 1
ofs, away, ofs_away_made_home, 1
ofs, away, ofs_away_got_total, 1
ofs, away, ofs_away_got_home, 1
crd, home, crd_home_made_total, 1
crd, home, crd_home_made_home, 1
crd, home, crd_home_got_total, 1
crd, home, crd_home_got_home, 1
crd, away, crd_away_made_total, 1
crd, away, crd_away_made_home, 1
crd, away, crd_away_got_total, 1
crd, away, crd_away_got_home, 1
snt, home, snt_home_made_total, 1
snt, home, snt_home_made_home, 1
snt, home, snt_home_got_total, 1
snt, home, snt_home_got_home, 1
snt, away, snt_away_made_total, 1
snt, away, snt_away_made_home, 1
snt, away, snt_away_got_total, 1
snt, away, snt_away_got_home, 1
tsh, home, tsh_home_made_total, 1
tsh, home, tsh_home_made_home, 1
tsh, home, tsh_home_got_total, 1
tsh, home, tsh_home_got_home, 1
tsh, away, tsh_away_made_total, 1
tsh, away, tsh_away_made_home, 1
tsh, away, tsh_away_got_total, 1
tsh, away, tsh_away_got_home, 1
1 gls home gls_home_made_total 1
2 gls home gls_home_made_home 1
3 gls home gls_home_got_total 1
4 gls home gls_home_got_home 1
5 gls away gls_away_made_total 1
6 gls away gls_away_made_home 1
7 gls away gls_away_got_total 1
8 gls away gls_away_got_home 1
9 crn home crn_home_made_total 1
10 crn home crn_home_made_home 1
11 crn home crn_home_got_total 1
12 crn home crn_home_got_home 1
13 crn away crn_away_made_total 1
14 crn away crn_away_made_home 1
15 crn away crn_away_got_total 1
16 crn away crn_away_got_home 1
17 fls home fls_home_made_total 1
18 fls home fls_home_made_home 1
19 fls home fls_home_got_total 1
20 fls home fls_home_got_home 1
21 fls away fls_away_made_total 1
22 fls away fls_away_made_home 1
23 fls away fls_away_got_total 1
24 fls away fls_away_got_home 1
25 ofs home ofs_home_made_total 1
26 ofs home ofs_home_made_home 1
27 ofs home ofs_home_got_total 1
28 ofs home ofs_home_got_home 1
29 ofs away ofs_away_made_total 1
30 ofs away ofs_away_made_home 1
31 ofs away ofs_away_got_total 1
32 ofs away ofs_away_got_home 1
33 crd home crd_home_made_total 1
34 crd home crd_home_made_home 1
35 crd home crd_home_got_total 1
36 crd home crd_home_got_home 1
37 crd away crd_away_made_total 1
38 crd away crd_away_made_home 1
39 crd away crd_away_got_total 1
40 crd away crd_away_got_home 1
41 snt home snt_home_made_total 1
42 snt home snt_home_made_home 1
43 snt home snt_home_got_total 1
44 snt home snt_home_got_home 1
45 snt away snt_away_made_total 1
46 snt away snt_away_made_home 1
47 snt away snt_away_got_total 1
48 snt away snt_away_got_home 1
49 tsh home tsh_home_made_total 1
50 tsh home tsh_home_made_home 1
51 tsh home tsh_home_got_total 1
52 tsh home tsh_home_got_home 1
53 tsh away tsh_away_made_total 1
54 tsh away tsh_away_made_home 1
55 tsh away tsh_away_got_total 1
56 tsh away tsh_away_got_home 1