wip Expectations
This commit is contained in:
1 parent
3db428899c
commit
1dbdbcf586
26 files changed
+704
-268
No files matched your search
@@ -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'][] = [
|
||||
|
||||
Reference in new issue
Block a user