Files
nuhodds_fi4/app/Filament/Widgets/Data/LoadEvents/LoadExpectations.php
T
2026-09-23 11:50:01 +02:00

154 lines
6.0 KiB
PHP

<?php
namespace App\Filament\Widgets\Data\LoadEvents;
use App\Models\StatistikoConfig;
class LoadExpectations
{
public static function load(array $data, object $match, string $statistic_type)
{
// dd($data, $match);
$config = StatistikoConfig::where('group', $statistic_type)->get();
$uba_home_made_total = 1;
$uba_home_made_home = 1;
$uba_home_got_total = 1;
$uba_home_got_home = 1;
$uba_away_made_total = 1;
$uba_away_made_home = 1;
$uba_away_got_total = 1;
$uba_away_got_home = 1;
foreach ($config as $value) {
$varname = str_replace($statistic_type.'_', '', $value->varname);
switch ($varname) {
case 'home_made_total':
$uba_home_made_total = (float) $value->value;
break;
case 'home_made_home':
$uba_home_made_home = (float) $value->value;
break;
case 'home_got_total':
$uba_home_got_total = (float) $value->value;
break;
case 'home_got_home':
$uba_home_got_home = (float) $value->value;
break;
case 'away_made_total':
$uba_away_made_total = (float) $value->value;
break;
case 'away_made_home':
$uba_away_made_home = (float) $value->value;
break;
case 'away_got_total':
$uba_away_got_total = (float) $value->value;
break;
case 'away_got_home':
$uba_away_got_home = (float) $value->value;
break;
}
}
$home_made_total = [];
$home_made_home = [];
$home_got_total = [];
$home_got_home = [];
$away_made_total = [];
$away_made_away = [];
$away_got_total = [];
$away_got_away = [];
$home_id = $match->home_id;
$away_id = $match->away_id;
foreach ($data as $value) {
// HOME
// if ($value['home_id'] == $home_id || $value['away_id'] == $home_id) {
// $home_made_total[] = $value['val_home'];
// $home_got_total[] = $value['val_away'];
// }
// if ($value['home_id'] == $home_id) {
// $home_made_home[] = $value['val_home'];
// $home_got_home[] = $value['val_away'];
// }
// AWAY
// if ($value['home_id'] == $away_id || $value['away_id'] == $away_id) {
// $away_made_total[] = $value['val_away'];
// $away_made_away[] = $value['val_home'];
// }
// if ($value['away_id'] == $away_id) {
// $away_made_away[] = $value['val_away'];
// $away_got_away[] = $value['val_home'];
// }
if ($value['home_id'] == $home_id) {
$home_made_total[] = $value['val_home'];
$home_made_home[] = $value['val_home'];
$home_got_total[] = $value['val_away'];
$home_got_home[] = $value['val_away'];
} elseif ($value['away_id'] == $home_id) {
$home_made_total[] = $value['val_away'];
$home_got_total[] = $value['val_away'];
} elseif ($value['home_id'] == $away_id) {
$home_made_total[] = $value['val_away'];
$home_got_total[] = $value['val_away'];
} elseif ($value['away_id'] == $away_id) {
$home_made_total[] = $value['val_home'];
$home_made_home[] = $value['val_home'];
$home_got_total[] = $value['val_away'];
$home_got_home[] = $value['val_home'];
}
if ($value['away_id'] == $away_id) {
$away_made_total[] = $value['val_away'];
$away_made_away[] = $value['val_away'];
$away_got_total[] = $value['val_home'];
$away_got_away[] = $value['val_home'];
} elseif ($value['home_id'] == $away_id) {
$away_made_total[] = $value['val_home'];
$away_got_total[] = $value['val_home'];
} elseif ($value['away_id'] == $home_id) {
$away_made_total[] = $value['val_home'];
$away_got_total[] = $value['val_home'];
} elseif ($value['home_id'] == $home_id) {
$away_made_total[] = $value['val_away'];
$away_made_away[] = $value['val_away'];
$away_got_total[] = $value['val_home'];
$away_got_away[] = $value['val_away'];
}
}
$summe_home = array_sum($home_made_total) * $uba_home_made_total;
$summe_home += array_sum($home_made_home) * $uba_home_made_home;
$summe_home += array_sum($home_got_total) * $uba_home_got_total;
$summe_home += array_sum($home_got_home) * $uba_home_got_home;
$count_home = \count($home_made_total);
$count_home += \count($home_made_home);
$count_home += \count($home_got_total);
$count_home += \count($home_got_home);
$count_home = ! $count_home ? 1 : $count_home;
$aspettativa_home = round($summe_home / $count_home, 1);
// dd($count_home, $summe_home, $aspettativa_home);
$summe_away = array_sum($away_made_total) * $uba_away_made_total;
$summe_away += array_sum($away_made_away) * $uba_away_made_home;
$summe_away += array_sum($away_got_total) * $uba_away_got_total;
$summe_away += array_sum($away_got_away) * $uba_away_got_home;
$count_away = \count($away_made_total);
$count_away += \count($away_made_away);
$count_away += \count($away_got_total);
$count_away += \count($away_got_away);
$count_away = ! $count_away ? 1 : $count_away;
$aspettativa_away = round($summe_away / $count_away, 1);
return ['home' => $aspettativa_home, 'away' => $aspettativa_away];
}
}