This commit is contained in:
salam committed 2026-08-24 17:45:32 +02:00
1 parent ea1acb50a9
commit 877f884095
1 file changed
+207 -96
+207 -96
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\LoadExpectations;
use App\Models\StatisticFixtures;
use App\Models\StatistikoEvent;
use Illuminate\Support\Carbon;
class LoadEvents
@@ -41,11 +40,12 @@ class LoadEvents
*/
$handicap_range = [];
$total_range = [];
$match = StatisticFixtures::with('home')->with('away')->where('id', (int) $match_id)->first();
if ($similar_past_matches != 'none') {
$team_position = '';
$match = StatisticFixtures::with('home')->with('away')->where('id', (int) $match_id)->first();
$exp_handicap = $match->exp_away - $match->exp_home;
@@ -62,7 +62,6 @@ class LoadEvents
$away_team = 'Against';
}
$match = StatisticFixtures::where('id', $match_id)->first();
/**
* STATTISTIC DATA
*/
@@ -87,37 +86,21 @@ class LoadEvents
return [];
}
$expectations = LoadExpectations::load($res['all'], $match, $statistic_type);
foreach ($res[$team_position] as $value) {
if ($team_id) {
$labels[] = round($value['starttime']->diffInDays(Carbon::now()));
$playing_date[] = $value['starttime']->format('Y-m-d H:i');
foreach ($res[$team_position] as $value) {
$results_per_event[] = $value['val_home'] . ' : ' . $value['val_away'];
$labels[] = round($value['starttime']->diffInDays(Carbon::now()));
if ($similar_past_matches != 'none') {
switch ($value['result_code']) {
case '1':
$results['w']++;
$results['l2']++;
break;
case 'X':
$results['d']++;
break;
case '2':
$results['l']++;
$results['w2']++;
break;
}
$playing_date[] = $value['starttime']->format('Y-m-d H:i');
$val_home = (int) $value['val_home'];
$val_away = (int) $value['val_away'];
$results_per_event[] = $value['val_home'] . ' : ' . $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') {
if ($similar_past_matches != 'none') {
switch ($value['result_code']) {
case '1':
$results['w']++;
@@ -135,84 +118,185 @@ class LoadEvents
$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']) {
case '1':
$results['l']++;
$results['w2']++;
break;
case 'X':
$results['d']++;
break;
case '2':
$results['w']++;
$results['l2']++;
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']);
switch ($value['result_code']) {
case '1':
if ($team_id == $value['home_id']) {
$results['l2']++;
$results['w']++;
} else {
$results['w2']++;
$results['l']++;
}
break;
case 'X':
$results['d']++;
break;
case '2':
if ($team_id == $value['home_id']) {
$results['l']++;
$results['w2']++;
} else {
$results['l2']++;
$results['w']++;
}
break;
}
if ($team_id == $value['home_id']) {
$val_home = (int) $value['val_home'];
$val_away = (int) $value['val_away'];
if ($statistic_type == 'gls') {
$dataset_exp_home[] = (float) round($value['exp_home'], 1);
$dataset_exp_away[] = (float) round($value['exp_away'], 1);
} else {
}
} else {
if ($team_position == 'home') {
switch ($value['result_code']) {
case '1':
$results['w']++;
$results['l2']++;
break;
case 'X':
$results['d']++;
break;
case '2':
$results['l']++;
$results['w2']++;
break;
}
$val_home = (int) $value['val_home'];
$val_away = (int) $value['val_away'];
if ($statistic_type == 'gls') {
$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']) {
case '1':
$results['l']++;
$results['w2']++;
break;
case 'X':
$results['d']++;
break;
case '2':
$results['w']++;
$results['l2']++;
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);
if ($statistic_type == 'gls') {
$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']);
// switch ($value['result_code']) {
// case '1':
// if ($team_id == $value['home_id']) {
// $results['l2']++;
// $results['w']++;
// } else {
// $results['w2']++;
// $results['l']++;
// }
// break;
// case 'X':
// $results['d']++;
// break;
// case '2':
// if ($team_id == $value['home_id']) {
// $results['l']++;
// $results['w2']++;
// } else {
// $results['l2']++;
// $results['w']++;
// }
// break;
// }
// "match_id" => 14059455
// "sport_id" => 1
// "league_id" => 18
// "home_id" => 9
// "away_id" => 32
// "starttime" => Illuminate\Support\Carbon @1754672400 {#4400 ▶}
// "season" => "25/26"
// "exp_home" => 1.2259626288952
// "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)) {
$events[] = $value['home'] . ' vs ' . $value['away'];
$dataset_home[] = $val_home;
$dataset_away[] = $val_away;
}
}
if (isset($val_home) && isset($val_away)) {
if ($similar_past_matches != 'none') {
$label1 = 'Home';
$label2 = 'Away';
} else {
$label1 = 'In Favour';
$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'];
$dataset_home[] = $val_home;
$dataset_away[] = $val_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'];
}
}
}
if ($similar_past_matches != 'none') {
$label1 = 'Home';
$label2 = 'Away';
} else {
$label1 = 'In Favour';
$label2 = 'Against';
}
// dd($events, $dataset_home, $dataset_home2);
self::shortenEnding($labels, $dataset_home, $dataset_away);
@@ -258,7 +342,7 @@ class LoadEvents
'expectations_home' => $expectations['home'],
'expectations_away' => $expectations['away'],
];
if ($statistic_type == 'gls') {
if ($team_id && $statistic_type == 'gls') {
$data['datasets'][] = [
'label' => 'Goals ' . $label1,
'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);
/**
* LEAGUE AVERAGES
*/
if ($similar_past_matches == 'none') {
if ($team_id && $similar_past_matches == 'none') {
LoadEventsAverages::load($data, $filter, $labels, $events);
}