103 lines
3.5 KiB
PHP
103 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Widgets\Boxes\Helper;
|
|
|
|
use App\Models\StatistikoEvent;
|
|
|
|
class ExpectationsMinMax
|
|
{
|
|
public static function calc(array &$expectations, object $match)
|
|
{
|
|
/**
|
|
* get min and max for each bettype from all DB for liga
|
|
* make average
|
|
*/
|
|
$bets = ['crn', 'fls', 'ofs', 'crd', 'snt', 'tsh'];
|
|
$Y = 0.25;
|
|
|
|
$res = StatistikoEvent::where('league_id', $match->league_id)->get();
|
|
$count = $res->count();
|
|
|
|
$data = [];
|
|
foreach ($bets as $bet) {
|
|
$data[$bet]['home'] = 0;
|
|
$data[$bet]['away'] = 0;
|
|
}
|
|
|
|
foreach ($res as $val) {
|
|
|
|
$data['crn']['home'] += $val->crn_h;
|
|
$data['crn']['away'] += $val->crn_a;
|
|
|
|
$data['fls']['home'] += $val->fls_h;
|
|
$data['fls']['away'] += $val->fls_a;
|
|
|
|
$data['ofs']['home'] += $val->ofs_h;
|
|
$data['ofs']['away'] += $val->ofs_a;
|
|
|
|
$data['snt']['home'] += $val->snt_h;
|
|
$data['snt']['away'] += $val->snt_a;
|
|
|
|
$data['tsh']['home'] += $val->tsh_h;
|
|
$data['tsh']['away'] += $val->tsh_a;
|
|
|
|
$data['crd']['home'] += $val->crd_h;
|
|
$data['crd']['away'] += $val->crd_a;
|
|
}
|
|
|
|
foreach ($data as $key => $value) {
|
|
$data[$key]['home'] = $value['home'] / $count;
|
|
$data[$key]['away'] = $value['away'] / $count;
|
|
}
|
|
|
|
$final = [];
|
|
foreach ($data as $key => $value) {
|
|
if ($value['home'] > $value['away']) {
|
|
$final[$key]['max'] = round($value['home'] * (1 + $Y), 2);
|
|
$final[$key]['min'] = round($value['away'] * (1 - $Y), 2);
|
|
} else {
|
|
$final[$key]['min'] = round($value['home'] * (1 - $Y), 2);
|
|
$final[$key]['max'] = round($value['away'] * (1 + $Y), 2);
|
|
}
|
|
}
|
|
|
|
foreach ($bets as $key) {
|
|
if (isset($expectations[$key])) {
|
|
if ($expectations[$key]['home'] > $final[$key]['max']) {
|
|
$expectations[$key]['home'] = $final[$key]['max'];
|
|
}
|
|
if ($expectations[$key]['away'] > $final[$key]['max']) {
|
|
$expectations[$key]['away'] = $final[$key]['max'];
|
|
}
|
|
if ($expectations[$key]['home'] < $final[$key]['min']) {
|
|
$expectations[$key]['home'] = $final[$key]['min'];
|
|
}
|
|
if ($expectations[$key]['away'] < $final[$key]['min']) {
|
|
$expectations[$key]['away'] = $final[$key]['min'];
|
|
}
|
|
}
|
|
}
|
|
|
|
// GOALS with asp from fixtures
|
|
$gls_home_max = $match->exp_home * (1 + ($Y / 2));
|
|
$gls_home_min = $match->exp_home * (1 - ($Y / 2));
|
|
$gls_away_max = $match->exp_away * (1 + ($Y / 2));
|
|
$gls_away_min = $match->exp_away * (1 - ($Y / 2));
|
|
|
|
if (isset($expectations['gls'])) {
|
|
if ($expectations['gls']['home'] > $gls_home_max) {
|
|
$expectations['gls']['home'] = $gls_home_max;
|
|
}
|
|
if ($expectations['gls']['away'] > $gls_away_max) {
|
|
$expectations['gls']['away'] = $gls_away_max;
|
|
}
|
|
if ($expectations['gls']['home'] < $gls_home_min) {
|
|
$expectations['gls']['home'] = $gls_home_min;
|
|
}
|
|
if ($expectations['gls']['away'] < $gls_away_min) {
|
|
$expectations['gls']['away'] = $gls_away_min;
|
|
}
|
|
}
|
|
}
|
|
}
|