'None', * 'league' => 'League', * 'all' => 'All Database', */ $handicap_range = []; $total_range = []; $match = StatisticFixtures::with('home')->with('away')->where('id', (int) $match_id)->first(); if ($similar_past_matches != 'none') { $team_position = ''; $exp_handicap = $match->exp_away - $match->exp_home; $exp_total = $match->exp_away + $match->exp_home; $handicap_range = [$exp_handicap - $accuracy, $exp_handicap + $accuracy]; $total_range = [$exp_total - $accuracy, $exp_total + $accuracy]; $home_team = $match->home->ss_team_name; $away_team = $match->away->ss_team_name; } else { $home_team = 'In Favour'; $away_team = 'Against'; } /** * STATTISTIC DATA */ $res = LoadEventsQuery::load($filter, $handicap_range, $total_range, $match); $dataset_home = []; $dataset_away = []; $dataset_exp_home = []; $dataset_exp_away = []; $results_per_event = []; $playing_date = []; $labels = []; $events = []; $results = ['w' => 0, 'd' => 0, 'l' => 0, 'w2' => 0, 'l2' => 0]; if (!$team_id || !\in_array($team_position, ['home', 'away'])) { $team_position = 'all'; } if (!isset($res['all'])) { return []; } $expectations = LoadExpectations::load($res['all'], $match, $statistic_type); if ($team_id) { foreach ($res[$team_position] as $value) { $labels[] = round($value['starttime']->diffInDays(Carbon::now())); $playing_date[] = $value['starttime']->format('Y-m-d H:i'); $results_per_event[] = $value['val_home'] . ' : ' . $value['val_away']; 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; } $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 { 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']; 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 ($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']; // $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']; } else if ($match->home_id == $value['away_id']) { $dataset_home[] = (int) $value['val_away']; $dataset_away[] = (int) $value['val_home']; } // Home playing AWAY done and commited else if ($match->away_id == $value['home_id']) { $dataset_home2[] = (int) $value['val_home']; $dataset_away2[] = (int) $value['val_away']; } else if ($match->away_id == $value['away_id']) { $dataset_home2[] = (int) $value['val_away']; $dataset_away2[] = (int) $value['val_home']; } } $n = max(count($dataset_home), count($dataset_home2)); $f = array_first($labels); $step = round($f / $n); $labels = []; for ($i = $f; $i >= 0; $i -= $step) { $labels[] = $i; } } // dd($events, count($dataset_home), count($dataset_away), count($dataset_home2), count($dataset_away2)); self::shortenEnding($labels, $dataset_home, $dataset_away); $data = [ 'datasets' => [ [ 'label' => $label1, 'events' => $events, 'playing_date' => $playing_date, 'results_per_event' => $results_per_event, 'data' => $dataset_home, 'tension' => 0.5, 'borderColor' => '#fb2c36', 'backgroundColor' => '#fb2c36', 'pointStyle' => $hasdots, 'fill' => [ 'target' => 1, 'above' => '#fb2c3680', 'below' => '#fdc70080', ], ], [ 'label' => $label2, 'events' => $events, 'playing_date' => $playing_date, 'results_per_event' => $results_per_event, 'data' => $dataset_away, 'tension' => 0.5, 'borderColor' => '#fdc700', 'backgroundColor' => '#fdc700', 'pointStyle' => $hasdots, 'fill' => false, 'hidden' => true, ], ], 'labels' => $labels, 'description' => $description ?? '', 'results' => $results, 'home_team' => $home_team, 'away_team' => $away_team, 'similar_past_matches' => $similar_past_matches, 'expectations_home' => $expectations['home'], 'expectations_away' => $expectations['away'], ]; if ($team_id && $statistic_type == 'gls') { $data['datasets'][] = [ 'label' => 'Goals ' . $label1, 'events' => $events, 'playing_date' => $playing_date, 'results_per_event' => $results_per_event, 'data' => $dataset_exp_home, 'tension' => 0.5, 'borderColor' => '#00c950', 'backgroundColor' => '#00c950', 'pointStyle' => $hasdots, 'hidden' => true, ]; $data['datasets'][] = [ 'label' => 'Goals ' . $label2, 'events' => $events, 'playing_date' => $playing_date, 'results_per_event' => $results_per_event, 'data' => $dataset_exp_away, 'tension' => 0.5, 'borderColor' => '#2b7fff', 'backgroundColor' => '#2b7fff', 'pointStyle' => $hasdots, 'hidden' => true, ]; } 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 ($team_id && $similar_past_matches == 'none') { LoadEventsAverages::load($data, $filter, $labels, $events); } return $data; } public static function shortenEnding(array &$labels, array &$homes, array &$aways) { if (! isset($homes['all'])) { return; } $count_home = 0; $count_away = 0; for ($i = \count($homes) - 1; $i > 0; $i--) { if ($homes[$i] == null) { $count_home++; } else { break; } } for ($i = \count($aways) - 1; $i > 0; $i--) { if ($aways[$i] == null) { $count_away++; } else { break; } } $keeps = count($homes['all']) - min($count_home, $count_away) - 1; $homes = array_slice($homes, 0, $keeps); $aways = array_slice($aways, 0, $keeps); $labels = array_slice($labels, 0, $keeps); } }