Files
nuhodds_fi4/app/Filament/Widgets/Boxes/Expectation1X2.php
T

66 lines
2.3 KiB
PHP

<?php
namespace App\Filament\Widgets\Boxes;
use App\Filament\Widgets\Charts\LoadEvents\LoadEventsQueryTP;
use App\Utilities\Round;
class Expectation1X2
{
public static function load(array &$expectations, array $filter, object $match)
{
$team_id = (int) $filter['team_id'] ?? 0;
$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];
foreach ($res_tp as $value) {
if ($value->home_id == $team_id) {
switch ($value['result_code']) {
case '1':
$expectations['win_count']++;
break;
case 'X':
$expectations['draw_count']++;
break;
case '2':
$expectations['lost_count']++;
break;
}
} elseif ($value->away_id == $team_id) {
switch ($value['result_code']) {
case '2':
$expectations['win_count']++;
break;
case 'X':
$expectations['draw_count']++;
break;
case '1':
$expectations['lost_count']++;
break;
}
} else {
switch ($value['result_code']) {
case '1':
$expectations['win_count']++;
break;
case 'X':
$expectations['draw_count']++;
break;
case '2':
$expectations['lost_count']++;
break;
}
}
}
$expectations['win_odd'] = $expectations['win_count'] ? number_format(Round::odd($count_tp / $expectations['win_count']), 2) : 0;
$expectations['draw_odd'] = $expectations['draw_count'] ? number_format(Round::odd($count_tp / $expectations['draw_count']), 2) : 0;
$expectations['lost_odd'] = $expectations['lost_count'] ? number_format(Round::odd($count_tp / $expectations['lost_count']), 2) : 0;
}
}