wip
This commit is contained in:
1 parent
40ddc2e61a
commit
08bd5a848a
1 file changed
+34
-35
@@ -64,37 +64,16 @@ class StatsMedianAverage extends StatsOverviewWidget
|
|||||||
if (! $total_home) {
|
if (! $total_home) {
|
||||||
return [
|
return [
|
||||||
Stat::make('Number of events', 0),
|
Stat::make('Number of events', 0),
|
||||||
Stat::make('Average '.$statistic_type, self::template(0, 0, $home_team, $away_team)),
|
Stat::make('Average ' . $statistic_type, self::template(0, 0, $home_team, $away_team)),
|
||||||
Stat::make('Median '.$statistic_type, self::template(0, 0, $home_team, $away_team)),
|
Stat::make('Median ' . $statistic_type, self::template(0, 0, $home_team, $away_team)),
|
||||||
Stat::make('Win', 0),
|
Stat::make('Win', 0),
|
||||||
Stat::make('Draw', 0),
|
Stat::make('Draw', 0),
|
||||||
Stat::make('Lost', 0),
|
Stat::make('Lost', 0),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
sort($arr_home);
|
$median_home = self::getMedian($arr_home);
|
||||||
sort($arr_away);
|
$median_away = self::getMedian($arr_away);
|
||||||
|
|
||||||
if ($total_home % 2 == 0) {
|
|
||||||
// even
|
|
||||||
$m = $total_home / 2;
|
|
||||||
$m1 = floor($m);
|
|
||||||
$m2 = ceil($m);
|
|
||||||
$median_home = round(($arr_home[$m1] + $arr_home[$m2]) / 2, 2);
|
|
||||||
|
|
||||||
$m = $total_away / 2;
|
|
||||||
$m1 = floor($m);
|
|
||||||
$m2 = ceil($m);
|
|
||||||
$median_away = round(($arr_away[$m1] + $arr_away[$m2]) / 2, 2);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// odd
|
|
||||||
$m = $total_home / 2;
|
|
||||||
$median_home = $arr_home[$m];
|
|
||||||
|
|
||||||
$m = floor($total_away / 2);
|
|
||||||
$median_away = $arr_away[$m];
|
|
||||||
}
|
|
||||||
|
|
||||||
$win = $data['results']['w'] ? number_format(Round::odd($total_home / $data['results']['w']), 2) : 0;
|
$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;
|
$draw = $data['results']['d'] ? number_format(Round::odd($total_home / $data['results']['d']), 2) : 0;
|
||||||
@@ -104,22 +83,42 @@ class StatsMedianAverage extends StatsOverviewWidget
|
|||||||
$value_away = number_format($summe_away / $total_away, 1);
|
$value_away = number_format($summe_away / $total_away, 1);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Stat::make('Number of events', new HtmlString('<div id="number-of-events">'.$total_home.'</div>'))->extraAttributes(['x-init' => "animate('number-of-events', $total_home)"]),
|
Stat::make('Number of events', new HtmlString('<div id="number-of-events">' . $total_home . '</div>'))->extraAttributes(['x-init' => "animate('number-of-events', $total_home)"]),
|
||||||
Stat::make('Average '.$statistic_type, self::template('avhome', 'avaway', $home_team, $away_team))->extraAttributes(['x-init' => "animate('avhome', $value_home); animate('avaway', $value_away)"]),
|
Stat::make('Average ' . $statistic_type, self::template('avhome', 'avaway', $home_team, $away_team))->extraAttributes(['x-init' => "animate('avhome', $value_home); animate('avaway', $value_away)"]),
|
||||||
Stat::make('Median '.$statistic_type, self::template('mehome', 'meaway', $home_team, $away_team))->extraAttributes(['x-init' => "animate('mehome', $median_home); animate('meaway', $median_away)"]),
|
Stat::make('Median ' . $statistic_type, self::template('mehome', 'meaway', $home_team, $away_team))->extraAttributes(['x-init' => "animate('mehome', $median_home); animate('meaway', $median_away)"]),
|
||||||
Stat::make($data['similar_past_matches'] != 'none' ? 'Win' : 'Win: '.$data['results']['w'], new HtmlString('<div id="number-of-win">'.$win.'</div>'))->extraAttributes(['x-init' => "animate('number-of-win', $win)"]),
|
Stat::make($data['similar_past_matches'] != 'none' ? 'Win' : 'Win: ' . $data['results']['w'], new HtmlString('<div id="number-of-win">' . $win . '</div>'))->extraAttributes(['x-init' => "animate('number-of-win', $win)"]),
|
||||||
Stat::make($data['similar_past_matches'] != 'none' ? 'Draw' : 'Draw: '.$data['results']['d'], new HtmlString('<div id="number-of-draw">'.$draw.'</div>'))->extraAttributes(['x-init' => "animate('number-of-draw', $draw)"]),
|
Stat::make($data['similar_past_matches'] != 'none' ? 'Draw' : 'Draw: ' . $data['results']['d'], new HtmlString('<div id="number-of-draw">' . $draw . '</div>'))->extraAttributes(['x-init' => "animate('number-of-draw', $draw)"]),
|
||||||
Stat::make($data['similar_past_matches'] != 'none' ? 'Lost' : 'Lost: '.$data['results']['l'], new HtmlString('<div id="number-of-lost">'.$lost.'</div>'))->extraAttributes(['x-init' => "animate('number-of-lost', $lost)"]),
|
Stat::make($data['similar_past_matches'] != 'none' ? 'Lost' : 'Lost: ' . $data['results']['l'], new HtmlString('<div id="number-of-lost">' . $lost . '</div>'))->extraAttributes(['x-init' => "animate('number-of-lost', $lost)"]),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function template(string $home_id, string $away_id, string $home_name, string $away_name): HtmlString
|
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-4xl">
|
||||||
<span class="text-center" id="'.$home_id.'">0</span>
|
<span class="text-center" id="' . $home_id . '">0</span>
|
||||||
<span class="text-center" id="'.$away_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>
|
<span class="text-center text-xs text-gray-500 dark:text-gray-400">' . $home_name . '</span>
|
||||||
<span class="text-center text-xs text-gray-500 dark:text-gray-400">'.$away_name.'</span>
|
<span class="text-center text-xs text-gray-500 dark:text-gray-400">' . $away_name . '</span>
|
||||||
</div>');
|
</div>');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getMedian(array $arr)
|
||||||
|
{
|
||||||
|
sort($arr);
|
||||||
|
$size = count($arr);
|
||||||
|
|
||||||
|
if ($size % 2 == 0) {
|
||||||
|
// even
|
||||||
|
$m = ($size) / 2;
|
||||||
|
$m1 = $m - 1;
|
||||||
|
$m2 = $m;
|
||||||
|
// dd('GERADE', $arr, $size, $m, $m1, $m2);
|
||||||
|
return round(($arr[$m1] + $arr[$m2]) / 2, 2);
|
||||||
|
} else {
|
||||||
|
// odd (add 1 because array starts with 0)
|
||||||
|
$m = ($size - 1) / 2;
|
||||||
|
// dd('UNGERADE', $m, $arr, $arr[$m]);
|
||||||
|
return $arr[$m];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user