This commit is contained in:
salam committed 2026-08-24 17:45:32 +02:00
1 parent ea1acb50a9
commit 877f884095
1 file changed
+150 -39
+150 -39
View File
@@ -6,7 +6,6 @@ use App\Filament\Widgets\Data\LoadEvents\LoadEventsAverages;
use App\Filament\Widgets\Data\LoadEvents\LoadEventsQuery; use App\Filament\Widgets\Data\LoadEvents\LoadEventsQuery;
use App\Filament\Widgets\Data\LoadEvents\LoadExpectations; use App\Filament\Widgets\Data\LoadEvents\LoadExpectations;
use App\Models\StatisticFixtures; use App\Models\StatisticFixtures;
use App\Models\StatistikoEvent;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
class LoadEvents class LoadEvents
@@ -41,11 +40,12 @@ class LoadEvents
*/ */
$handicap_range = []; $handicap_range = [];
$total_range = []; $total_range = [];
$match = StatisticFixtures::with('home')->with('away')->where('id', (int) $match_id)->first();
if ($similar_past_matches != 'none') { if ($similar_past_matches != 'none') {
$team_position = ''; $team_position = '';
$match = StatisticFixtures::with('home')->with('away')->where('id', (int) $match_id)->first();
$exp_handicap = $match->exp_away - $match->exp_home; $exp_handicap = $match->exp_away - $match->exp_home;
@@ -62,7 +62,6 @@ class LoadEvents
$away_team = 'Against'; $away_team = 'Against';
} }
$match = StatisticFixtures::where('id', $match_id)->first();
/** /**
* STATTISTIC DATA * STATTISTIC DATA
*/ */
@@ -87,11 +86,16 @@ class LoadEvents
return []; return [];
} }
$expectations = LoadExpectations::load($res['all'], $match, $statistic_type); $expectations = LoadExpectations::load($res['all'], $match, $statistic_type);
if ($team_id) {
foreach ($res[$team_position] as $value) { foreach ($res[$team_position] as $value) {
$labels[] = round($value['starttime']->diffInDays(Carbon::now())); $labels[] = round($value['starttime']->diffInDays(Carbon::now()));
$playing_date[] = $value['starttime']->format('Y-m-d H:i'); $playing_date[] = $value['starttime']->format('Y-m-d H:i');
$results_per_event[] = $value['val_home'] . ' : ' . $value['val_away']; $results_per_event[] = $value['val_home'] . ' : ' . $value['val_away'];
@@ -114,8 +118,10 @@ class LoadEvents
$val_home = (int) $value['val_home']; $val_home = (int) $value['val_home'];
$val_away = (int) $value['val_away']; $val_away = (int) $value['val_away'];
if ($statistic_type == 'gls') {
$dataset_exp_home[] = (float) round($value['exp_home'], 1); $dataset_exp_home[] = (float) round($value['exp_home'], 1);
$dataset_exp_away[] = (float) round($value['exp_away'], 1); $dataset_exp_away[] = (float) round($value['exp_away'], 1);
}
} else { } else {
if ($team_position == 'home') { if ($team_position == 'home') {
switch ($value['result_code']) { switch ($value['result_code']) {
@@ -135,8 +141,10 @@ class LoadEvents
$val_home = (int) $value['val_home']; $val_home = (int) $value['val_home'];
$val_away = (int) $value['val_away']; $val_away = (int) $value['val_away'];
if ($statistic_type == 'gls') {
$dataset_exp_home[] = (float) round($value['exp_home'], 1); $dataset_exp_home[] = (float) round($value['exp_home'], 1);
$dataset_exp_away[] = (float) round($value['exp_away'], 1); $dataset_exp_away[] = (float) round($value['exp_away'], 1);
}
} elseif ($team_position == 'away') { } elseif ($team_position == 'away') {
switch ($value['result_code']) { switch ($value['result_code']) {
@@ -156,47 +164,79 @@ class LoadEvents
$val_home = (int) $value['val_away']; $val_home = (int) $value['val_away'];
$val_away = (int) $value['val_home']; $val_away = (int) $value['val_home'];
if ($statistic_type == 'gls') {
$dataset_exp_home[] = (float) round($value['exp_away'], 1); $dataset_exp_home[] = (float) round($value['exp_away'], 1);
$dataset_exp_away[] = (float) round($value['exp_home'], 1); $dataset_exp_away[] = (float) round($value['exp_home'], 1);
}
} else { } else {
// dd($team_id, $value['home_id'], $value['away_id']); // dd($team_id, $value['home_id'], $value['away_id']);
switch ($value['result_code']) { // switch ($value['result_code']) {
case '1': // case '1':
if ($team_id == $value['home_id']) { // if ($team_id == $value['home_id']) {
$results['l2']++; // $results['l2']++;
$results['w']++; // $results['w']++;
} else { // } else {
$results['w2']++; // $results['w2']++;
$results['l']++; // $results['l']++;
} // }
break; // break;
case 'X': // case 'X':
$results['d']++; // $results['d']++;
break; // break;
case '2': // case '2':
if ($team_id == $value['home_id']) { // if ($team_id == $value['home_id']) {
$results['l']++; // $results['l']++;
$results['w2']++; // $results['w2']++;
} else { // } else {
$results['l2']++; // $results['l2']++;
$results['w']++; // $results['w']++;
} // }
break; // break;
} // }
if ($team_id == $value['home_id']) {
$val_home = (int) $value['val_home']; // "match_id" => 14059455
$val_away = (int) $value['val_away']; // "sport_id" => 1
$dataset_exp_home[] = (float) round($value['exp_home'], 1); // "league_id" => 18
$dataset_exp_away[] = (float) round($value['exp_away'], 1); // "home_id" => 9
} else { // "away_id" => 32
$val_home = (int) $value['val_away']; // "starttime" => Illuminate\Support\Carbon @1754672400 {#4400 ▶}
$val_away = (int) $value['val_home']; // "season" => "25/26"
$dataset_exp_home[] = (float) round($value['exp_away'], 1); // "exp_home" => 1.2259626288952
$dataset_exp_away[] = (float) round($value['exp_home'], 1); // "exp_away" => 1.1765083700232
} // "exp_handicap" => -0.049454258871964
// "exp_total" => 2.4024709989184
// "result_code" => "X"
// "home" => "Birmingham City"
// "away" => "Ipswich Town"
// "val_home" => 1
// "val_away" => 4
// if ($match->home_id == $value['home_id']) {
// $dataset_home[] = (int) $value['val_home'];
// $dataset_away[] = (int) $value['val_away'];
// }
// if ($match->home_id == $value['home_id']) {
// $val_home = (int) $value['val_home'];
// }
// if ($match->away_id == $value['away_id']) {
// $val_away = (int) $value['val_away'];
// }
// if ($team_id == $value['home_id']) {
// $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_id == $value['away_id']) {
// $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)) { if (isset($val_home) && isset($val_away)) {
@@ -213,6 +253,50 @@ class LoadEvents
$label1 = 'In Favour'; $label1 = 'In Favour';
$label2 = 'Against'; $label2 = 'Against';
} }
} 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 = [];
foreach ($res[$team_position] as $value) {
// dd($value);
$events[] = $value['home'] . ' vs ' . $value['away'];
$playing_date[] = $value['starttime']->format('Y-m-d H:i');
$results_per_event[] = $value['val_home'] . ' : ' . $value['val_away'];
$labels[] = round($value['starttime']->diffInDays(Carbon::now()));
// Home playing HOME done and commited
if ($match->home_id == $value['home_id']) {
$dataset_home[] = (int) $value['val_home'];
$dataset_away[] = (int) $value['val_away'];
$dataset_home2[] = end($dataset_home2);
$dataset_away2[] = end($dataset_away2);
} else if ($match->home_id == $value['away_id']) {
$dataset_home[] = (int) $value['val_away'];
$dataset_away[] = (int) $value['val_home'];
$dataset_home2[] = end($dataset_home2);
$dataset_away2[] = end($dataset_away2);
}
// Home playing AWAY done and commited
else if ($match->away_id == $value['home_id']) {
$dataset_home[] = end($dataset_home);
$dataset_away[] = end($dataset_away);
$dataset_home2[] = (int) $value['val_home'];
$dataset_away2[] = (int) $value['val_away'];
} else if ($match->away_id == $value['away_id']) {
$dataset_home[] = end($dataset_home);
$dataset_away[] = end($dataset_away);
$dataset_home2[] = (int) $value['val_away'];
$dataset_away2[] = (int) $value['val_home'];
}
}
}
// dd($events, $dataset_home, $dataset_home2);
self::shortenEnding($labels, $dataset_home, $dataset_away); self::shortenEnding($labels, $dataset_home, $dataset_away);
@@ -258,7 +342,7 @@ class LoadEvents
'expectations_home' => $expectations['home'], 'expectations_home' => $expectations['home'],
'expectations_away' => $expectations['away'], 'expectations_away' => $expectations['away'],
]; ];
if ($statistic_type == 'gls') { if ($team_id && $statistic_type == 'gls') {
$data['datasets'][] = [ $data['datasets'][] = [
'label' => 'Goals ' . $label1, 'label' => 'Goals ' . $label1,
'events' => $events, 'events' => $events,
@@ -285,13 +369,40 @@ class LoadEvents
]; ];
} }
if (!$team_id && 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,
];
}
// Log::debug($results); // Log::debug($results);
/** /**
* LEAGUE AVERAGES * LEAGUE AVERAGES
*/ */
if ($similar_past_matches == 'none') { if ($team_id && $similar_past_matches == 'none') {
LoadEventsAverages::load($data, $filter, $labels, $events); LoadEventsAverages::load($data, $filter, $labels, $events);
} }