This commit is contained in:
salam committed 2026-06-16 17:08:51 +02:00
1 parent 640328c1ca
commit 3376eb6d2e
3 files changed
+85 -33

No files matched your search

+75 -27
View File
@@ -21,6 +21,10 @@ class LoadPerformance
$match_id = (int) $filter['match_id'] ?? 0;
$team_position = $filter['team_position'];
$team_id = (int) $filter['team_id'] ?? 0;
if (! $league_id) {
return [];
}
@@ -33,6 +37,8 @@ class LoadPerformance
$home_id = $match->home_id;
$away_id = $match->away_id;
$res = StatistikoEvent::where('league_id', $league_id)->get();
$home_matches = [];
@@ -47,37 +53,78 @@ class LoadPerformance
$labels = [];
foreach ($res as $val) {
$league_matches[] = $val->match_id;
if ($val->home_id == $home_id or $val->away_id == $home_id) {
$labels[] = round($val->starttime->diffInDays(Carbon::now()));
$date_home[] = $val['starttime']->format('d. F Y H:i');
$results_home[] = $val['gls_h'] . ' : ' . $val['gls_a'];
$events_home[] = $val->home->name . ' vs ' . $val->away->name;
$home_matches[] = $val->match_id;
}
if ($val->home_id == $away_id or $val->away_id == $away_id) {
$labels[] = round($val->starttime->diffInDays(Carbon::now()));
$date_away[] = $val['starttime']->format('d. F Y H:i');
$results_away[] = $val['gls_h'] . ' : ' . $val['gls_a'];
$events_away[] = $val->home->name . ' vs ' . $val->away->name;
$away_matches[] = $val->match_id;
switch ($team_position) {
case 'home':
if ($val->home_id == $home_id) {
$labels[] = round($val->starttime->diffInDays(Carbon::now()));
$date_home[] = $val['starttime']->format('d. F Y H:i');
$results_home[] = $val['gls_h'] . ' : ' . $val['gls_a'];
$events_home[] = $val->home->name . ' vs ' . $val->away->name;
$home_matches[] = $val->match_id;
}
if ($val->away_id == $away_id) {
$labels[] = round($val->starttime->diffInDays(Carbon::now()));
$date_away[] = $val['starttime']->format('d. F Y H:i');
$results_away[] = $val['gls_h'] . ' : ' . $val['gls_a'];
$events_away[] = $val->home->name . ' vs ' . $val->away->name;
$away_matches[] = $val->match_id;
}
break;
case 'away':
if ($val->away_id == $home_id) {
$labels[] = round($val->starttime->diffInDays(Carbon::now()));
$date_home[] = $val['starttime']->format('d. F Y H:i');
$results_home[] = $val['gls_h'] . ' : ' . $val['gls_a'];
$events_home[] = $val->home->name . ' vs ' . $val->away->name;
$home_matches[] = $val->match_id;
}
if ($val->home_id == $away_id) {
$labels[] = round($val->starttime->diffInDays(Carbon::now()));
$date_away[] = $val['starttime']->format('d. F Y H:i');
$results_away[] = $val['gls_h'] . ' : ' . $val['gls_a'];
$events_away[] = $val->home->name . ' vs ' . $val->away->name;
$away_matches[] = $val->match_id;
}
break;
default:
if ($val->home_id == $home_id or $val->away_id == $home_id) {
$labels[] = round($val->starttime->diffInDays(Carbon::now()));
$date_home[] = $val['starttime']->format('d. F Y H:i');
$results_home[] = $val['gls_h'] . ' : ' . $val['gls_a'];
$events_home[] = $val->home->name . ' vs ' . $val->away->name;
$home_matches[] = $val->match_id;
}
if ($val->home_id == $away_id or $val->away_id == $away_id) {
$labels[] = round($val->starttime->diffInDays(Carbon::now()));
$date_away[] = $val['starttime']->format('d. F Y H:i');
$results_away[] = $val['gls_h'] . ' : ' . $val['gls_a'];
$events_away[] = $val->home->name . ' vs ' . $val->away->name;
$away_matches[] = $val->match_id;
}
break;
}
}
// dd($home_matches);
$res = StatistikoPlayer::whereIn('match_id', $home_matches)->select('match_id', 'minutes_played', 'playerrating_value', 'player_position')->get();
$homes = self::filterMatches($res, $home_matches);
// dd($homes);
$res = StatistikoPlayer::whereIn('match_id', $away_matches)->select('match_id', 'minutes_played', 'playerrating_value', 'player_position')->get();
$aways = self::filterMatches($res, $away_matches);
$length = max(count($homes['all']), count($aways['all']));
self::shortenEnding($labels, $homes, $aways);
$home_av = self::makeAv($homes);
$away_av = self::makeAv($aways);
$home_av = self::makeAv($homes, $length);
$away_av = self::makeAv($aways, $length);
$res = StatistikoPlayer::whereIn('match_id', $league_matches)->select('match_id', 'minutes_played', 'playerrating_value', 'player_position')->get();
$league = self::filterMatches($res, $league_matches);
$league_av = self::leagueAv($league, count($homes['all']));
$league_av = self::leagueAv($league, $length);
$data = [
'datasets' => [
@@ -374,8 +421,9 @@ class LoadPerformance
public static function filterMatches($res, array $matches)
{
if (!$res->count()) {
return [];
return ['all', 'def', 'att', 'mid'];
}
$result = [];
foreach ($res as $value) {
@@ -480,17 +528,17 @@ class LoadPerformance
$labels = range(1, $keeps);
}
public static function makeAv(array &$arr)
public static function makeAv(array &$arr, $length)
{
$all = array_sum($arr['all']) / count($arr['all']);
$def = array_sum($arr['def']) / count($arr['def']);
$mid = array_sum($arr['mid']) / count($arr['mid']);
$att = array_sum($arr['att']) / count($arr['att']);
$all = isset($arr['all']) ? array_sum($arr['all']) / count($arr['all']) : 1;
$def = isset($arr['def']) ? array_sum($arr['def']) / count($arr['def']) : 1;
$mid = isset($arr['mid']) ? array_sum($arr['mid']) / count($arr['mid']) : 1;
$att = isset($arr['att']) ? array_sum($arr['att']) / count($arr['att']) : 1;
$ret = [];
$ret['all'] = array_fill(0, count($arr['all']), round($all, 2));
$ret['def'] = array_fill(0, count($arr['def']), round($def, 2));
$ret['mid'] = array_fill(0, count($arr['mid']), round($mid, 2));
$ret['att'] = array_fill(0, count($arr['att']), round($att, 2));
$ret['all'] = array_fill(0, $length, round($all, 2));
$ret['def'] = array_fill(0, $length, round($def, 2));
$ret['mid'] = array_fill(0, $length, round($mid, 2));
$ret['att'] = array_fill(0, $length, round($att, 2));
return $ret;
}
+5 -5
View File
@@ -112,15 +112,15 @@ class StatsMedianAverage extends StatsOverviewWidget
$value_away = 0;
$boxes = [];
$boxes[] = Stat::make('Events', new HtmlString('<div id="number-of-events">' . $total_home . '</div>'))->extraAttributes(['x-init' => "animate('number-of-events', $total_home, 0)"]);
$boxes[] = Stat::make('Avg ' . $statistic_type, self::template('avhome', 'avaway', $home_team, $away_team))->extraAttributes(['x-init' => "animate('avhome', $value_home); animate('avaway', $value_away, 0)"]);
$boxes[] = Stat::make('Events', new HtmlString('<div id="number-of-events">' . $total_home . '</div>'))->description('Number')->extraAttributes(['x-init' => "animate('number-of-events', $total_home, 0)"]);
$boxes[] = Stat::make($statistic_type, self::template('avhome', 'avaway', $home_team, $away_team))->description('Average Team')->extraAttributes(['x-init' => "animate('avhome', $value_home); animate('avaway', $value_away, 0)"]);
foreach ($data['datasets'] as $value) {
if ($value['label'] == "Average League") {
$str = $value['data'][0] ?? 0;
$boxes[] = Stat::make('Avg League', new HtmlString('<div id="number-of-events">' . $str . '</div>'))->extraAttributes(['x-init' => "animate('number-of-events', $total_home, 0)"]);
$boxes[] = Stat::make($statistic_type, new HtmlString('<div id="number-of-events">' . $str . '</div>'))->description('Average League')->extraAttributes(['x-init' => "animate('number-of-events', $total_home, 0)"]);
}
}
$boxes[] = Stat::make('Med ' . $statistic_type, self::template('mehome', 'meaway', $home_team, $away_team))->extraAttributes(['x-init' => "animate('mehome', $median_home); animate('meaway', $median_away, 0)"]);
$boxes[] = Stat::make($statistic_type, self::template('mehome', 'meaway', $home_team, $away_team))->description('Median')->extraAttributes(['x-init' => "animate('mehome', $median_home); animate('meaway', $median_away, 0)"]);
$boxes[] = Stat::make($data['similar_past_matches'] != 'none' ? '1' : 'Win: ' . $data['results']['w'], new HtmlString('<div id="number-of-win">' . $win . '</div>'))->extraAttributes(['x-init' => "animate('number-of-win', $win, 1)"]);
$boxes[] = Stat::make($data['similar_past_matches'] != 'none' ? 'X' : 'Draw: ' . $data['results']['d'], new HtmlString('<div id="number-of-draw">' . $draw . '</div>'))->extraAttributes(['x-init' => "animate('number-of-draw', $draw, 1)"]);
$boxes[] = Stat::make($data['similar_past_matches'] != 'none' ? '2' : 'Lost: ' . $data['results']['l'], new HtmlString('<div id="number-of-lost">' . $lost . '</div>'))->extraAttributes(['x-init' => "animate('number-of-lost', $lost, 1)"]);
@@ -130,7 +130,7 @@ class StatsMedianAverage extends StatsOverviewWidget
protected function template(string $home_id, string $away_id, string $home_name, string $away_name): HtmlString
{
return new HtmlString('<div class="grid grid-cols-2 justify-center font-bold text-4xl">
return new HtmlString('<div class="grid grid-cols-2 justify-center font-bold text-3xl">
<span class="text-center" id="' . $home_id . '">0</span>
<span class="text-center" id="' . $away_id . '">0</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">' . $home_name . '</span>
+5 -1
View File
@@ -118,7 +118,11 @@ widget space to filter
}
.fi-wi-stats-overview-stat-label {
@apply text-lg font-bold mx-auto
@apply text-sm font-bold mx-auto text-amber-500
}
.fi-wi-stats-overview-stat-description span {
@apply mx-auto text-blue-500;
}
.fi-wi-stats-overview-stat-value {