min max for asp

This commit is contained in:
salam committed 2026-10-09 18:16:10 +02:00
1 parent 274d653f95
commit 01b62be635
4 files changed
+102 -9

No files matched your search

@@ -5,6 +5,7 @@ namespace App\Filament\Widgets\Boxes;
use App\Filament\Widgets\Boxes\Helper\ExpectationCalculationMethodA;
use App\Filament\Widgets\Boxes\Helper\ExpectationCalculationMethodB;
use App\Filament\Widgets\Boxes\Helper\ExpectationCollecting;
use App\Filament\Widgets\Boxes\Helper\ExpectationsMinMax;
use App\Filament\Widgets\Charts\LoadEvents\LoadEventsQueryAll;
use App\Filament\Widgets\Charts\LoadEvents\LoadEventsQueryTP;
use App\Utilities\Round;
@@ -19,6 +20,7 @@ class ExpectationsTeam
* STATTISTIC DATA
*/
$team_id = (int) $filter['team_id'] ?? 0;
$league_id = (int) $filter['league_id'] ?? 0;
$team_position = $filter['team_position'];
$similar_past_matches = $filter['similar_past_matches'];
@@ -34,20 +36,13 @@ class ExpectationsTeam
$res = LoadEventsQueryAll::load($filter, $match);
$res_tp = LoadEventsQueryTP::load($filter, $match);
$count_tp = $res_tp->count();
// $count_events = ExpectationCounting::count($team_position, $team_id, $res);
// Log::debug('count_events ' . $count_events);
if (! $res) {
return [];
}
$tmp = [];
foreach ($res as $value) {
// dd($match->home_id, $match->away_id, $value);
ExpectationCollecting::sort($similar_past_matches, $tmp, 'gls', $value->home_id, $value->away_id, $value->gls_h, $value->gls_a, $match);
ExpectationCollecting::sort($similar_past_matches, $tmp, 'fls', $value->home_id, $value->away_id, $value->fls_h, $value->fls_a, $match);
ExpectationCollecting::sort($similar_past_matches, $tmp, 'ofs', $value->home_id, $value->away_id, $value->ofs_h, $value->ofs_a, $match);
@@ -63,6 +58,10 @@ class ExpectationsTeam
$expectations = ExpectationCalculationMethodB::calc($tmp);
}
// dd($expectations);
ExpectationsMinMax::calc($expectations, $league_id);
$expectations['gls']['name'] = 'Goals';
$expectations['crn']['name'] = 'Corner';
$expectations['fls']['name'] = 'Fouls';
@@ -72,6 +71,10 @@ class ExpectationsTeam
$expectations['tsh']['name'] = 'Total Shots';
$expectations['home'] = $home_team;
$expectations['away'] = $away_team;
$res_tp = LoadEventsQueryTP::load($filter, $match);
$count_tp = $res_tp->count();
$expectations['count_events'] = $count_tp;
$expectations += ['win_count' => 0, 'draw_count' => 0, 'lost_count' => 0];
@@ -0,0 +1,79 @@
<?php
namespace App\Filament\Widgets\Boxes\Helper;
use App\Models\StatistikoEvent;
class ExpectationsMinMax
{
public static function calc(array &$expectations, int $league_id)
{
/**
* 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', $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 ($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'];
}
}
}
}