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

@@ -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];
}
}