filters = $filters;
}
protected function getStats(): array
{
$data = LoadEvents::load($this->filters, false);
$team_id = (int) $this->filters['team_id'] ?? 0;
$season = $this->filters['season'] ?? 0;
$season_or_date = $this->filters['season_or_date'];
$similar_past_matches = $this->filters['similar_past_matches'];
$date_events = '';
switch ($season_or_date) {
case 'season':
if ($season)
$date_events = implode(', ', $season);
else
$date_events = 'Current Season';
break;
default:
$start = $this->filters['start_date'] ?? 0;
$end = $this->filters['end_date'] ?? 0;
$tmp = [];
if ($start) {
$tmp[] = 'From: ' . Carbon::createFromDate($start)->format('Y-m-d');
}
if ($end)
$tmp[] = 'To: ' . Carbon::createFromDate($end)->format('Y-m-d');
if ($tmp)
$date_events = implode('
', $tmp);
else
$date_events = 'All Dates';
break;
}
$team_position = HelperTeamPosition::get($this->filters);
if (! $data) {
return [];
}
$statistic_type = HelperStatisticType::get($this->filters);
if (! isset($data['datasets'][0])) {
$data['datasets'][0]['data'] = [];
$data['datasets'][1]['data'] = [];
$total_home = 0;
$total_away = 0;
$summe_home = 0;
$summe_away = 0;
$home_team = '';
$away_team = '';
} else {
$arr_home = $data['datasets'][0]['data'];
$arr_away = $data['datasets'][1]['data'];
$total_home = count($arr_home);
$total_away = count($arr_away);
$summe_home = array_sum($arr_home);
$summe_away = array_sum($arr_away);
$home_team = $data['home_team'];
$away_team = $data['away_team'];
}
if (isset($data['results'])) {
$win = $data['results']['w'] ? number_format(Round::odd($total_home / $data['results']['w']), 2) : 0;
$draw = $data['results']['d'] ? number_format(Round::odd($total_home / $data['results']['d']), 2) : 0;
$lost = $data['results']['l'] ? number_format(Round::odd($total_home / $data['results']['l']), 2) : 0;
} else {
$win = 0;
$draw = 0;
$lost = 0;
}
if ($total_home) {
$value_home = number_format($summe_home / $total_home, 1);
} else {
$value_home = 0;
}
if ($total_away) {
$value_away = number_format($summe_away / $total_away, 1);
} else {
$value_away = 0;
}
$max_boxes = 3;
$average_team_home = 0;
$average_team_away = 0;
$average_league_home = 0;
$average_league_away = 0;
$expectations_home = 0;
$expectations_away = 0;
$expectations_home = $data['expectations_home'] ?? 0;
$expectations_away = $data['expectations_away'] ?? 0;
foreach ($data['datasets'] as $value) {
if ($value['label'] == 'Average Team') {
$average_team_home = $value['average_team_home'] ?? 0;
$average_team_away = $value['average_team_away'] ?? 0;
$max_boxes++;
}
if ($value['label'] == 'Average League') {
$average_league_home = $value['average_league_home'] ?? 0;
$average_league_away = $value['average_league_away'] ?? 0;
$max_boxes++;
}
}
$boxes = [];
if ($similar_past_matches != 'none') {
// BOX 2
$boxes[] = Stat::make('Total', self::template_box2($total_home))
->description(fn() => new HtmlString($date_events))
->extraAttributes([
'x-init' => "animate('number-of-events', $total_home);",
'class' => 'box-info',
]);
// BOX 3
$boxes[] = Stat::make('Average ' . $statistic_type, self::template_box3('Home', 'Away', $value_home, $value_away))
->description('Team ' . $team_position)
->extraAttributes([
'x-init' => "animate('average_home', $value_home); animate('average_away', $value_away)",
'class' => 'box-success',
]);
// BOX 6
$boxes[] = Stat::make('Odds', self::templateOdds($data, $win, $draw, $lost))
->description($team_position)
->extraAttributes([
'x-init' => "animate('win', $win); animate('draw', $draw); animate('lost', $lost)",
'class' => 'box-purple',
]);
} else {
// BOX 1
$boxes[] = Stat::make($statistic_type, self::template_box1($expectations_home, $expectations_away))
->description('Expected Values')
->extraAttributes([
'x-init' => "animate('expectations_home', $expectations_home); animate('expectations_away', $expectations_away)",
'class' => 'box-yellow',
]);
if ($team_id) {
// BOX 2
$boxes[] = Stat::make('Total', self::template_box2($total_home))
->description(fn() => new HtmlString($date_events))
->extraAttributes([
'x-init' => "animate('number-of-events', $total_home);",
'class' => 'box-info',
]);
// BOX 3
$boxes[] = Stat::make('Average ' . $statistic_type, self::template_box3($home_team, $away_team, $value_home, $value_away))
->description('Team ' . $team_position)
->extraAttributes([
'x-init' => "animate('average_home', $value_home); animate('average_away', $value_away)",
'class' => 'box-success',
]);
// BOX 4
$boxes[] = Stat::make('Average ' . $statistic_type, self::template_box4($home_team, $away_team, $average_team_home, $average_team_away))
->description('Team Season')
->extraAttributes([
'x-init' => "animate('av_team_home', $average_team_home); animate('av_team_away', $average_team_away)",
'class' => 'box-success',
]);
// BOX 5
$boxes[] = Stat::make('Average ' . $statistic_type, self::template_box5('Home', 'Away', $average_league_home, $average_league_away))
->description('League Season')
->extraAttributes([
'x-init' => "animate('av_league_home', $average_league_home); animate('av_league_away', $average_league_away)",
'class' => 'box-success',
]);
// BOX 6
$boxes[] = Stat::make('Odds', self::templateOdds($data, $win, $draw, $lost))
->description($team_position)
->extraAttributes([
'x-init' => "animate('win', $win); animate('draw', $draw); animate('lost', $lost)",
'class' => 'box-purple',
]);
}
}
$this->columns = [
'default' => 1,
'sm' => 2,
'md' => 3,
'xl' => 6,
];
return $boxes;
}
// TEAMPLATE BOX 1
protected function template_box1(float $expectations_home, float $expectations_away): HtmlString
{
return new HtmlString('