115 lines
3.8 KiB
PHP
115 lines
3.8 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)
|
|
{
|
|
$home_id = $match->home_id;
|
|
$away_id = $match->away_id;
|
|
|
|
$config = StatistikoConfig::where('group', $statistic_type)->get();
|
|
|
|
$home_made_total = 1;
|
|
$home_made_home = 1;
|
|
$home_got_total = 1;
|
|
$home_got_home = 1;
|
|
$away_made_total = 1;
|
|
$away_made_home = 1;
|
|
$away_got_total = 1;
|
|
$away_got_home = 1;
|
|
|
|
foreach ($config as $value) {
|
|
$varname = str_replace($statistic_type . '_', '', $value->varname);
|
|
switch ($varname) {
|
|
case 'home_made_total':
|
|
$home_made_total = (float) $value->value;
|
|
break;
|
|
case 'home_made_home':
|
|
$home_made_home = (float) $value->value;
|
|
break;
|
|
case 'home_got_total':
|
|
$home_got_total = (float) $value->value;
|
|
break;
|
|
case 'home_got_home':
|
|
$home_got_home = (float) $value->value;
|
|
break;
|
|
case 'away_made_total':
|
|
$away_made_total = (float) $value->value;
|
|
break;
|
|
case 'away_made_home':
|
|
$away_made_home = (float) $value->value;
|
|
break;
|
|
case 'away_got_total':
|
|
$away_got_total = (float) $value->value;
|
|
break;
|
|
case 'away_got_home':
|
|
$away_got_home = (float) $value->value;
|
|
break;
|
|
}
|
|
}
|
|
|
|
$h_made_t = [];
|
|
$h_made_h = [];
|
|
$h_got_t = [];
|
|
$h_got_h = [];
|
|
|
|
$a_made_t = [];
|
|
$a_made_a = [];
|
|
$a_got_t = [];
|
|
$a_got_a = [];
|
|
|
|
foreach ($data as $value) {
|
|
// HOME
|
|
if ($value['home_id'] == $home_id || $value['away_id'] == $home_id) {
|
|
$h_made_t[] = $value['val_home'];
|
|
$h_got_t[] = $value['val_away'];
|
|
}
|
|
if ($value['home_id'] == $home_id) {
|
|
$h_made_h[] = $value['val_home'];
|
|
$h_got_h[] = $value['val_away'];
|
|
}
|
|
|
|
// AWAY
|
|
if ($value['home_id'] == $away_id || $value['away_id'] == $away_id) {
|
|
$a_made_t[] = $value['val_away'];
|
|
$a_made_a[] = $value['val_home'];
|
|
}
|
|
|
|
if ($value['away_id'] == $away_id) {
|
|
$a_made_a[] = $value['val_away'];
|
|
$a_got_a[] = $value['val_home'];
|
|
}
|
|
}
|
|
|
|
$summe_home = array_sum($h_made_t) * $home_made_total;
|
|
$summe_home += array_sum($h_made_h) * $home_made_home;
|
|
$summe_home += array_sum($h_got_t) * $home_got_total;
|
|
$summe_home += array_sum($h_got_h) * $home_got_home;
|
|
$count_home = \count($h_made_t);
|
|
$count_home += \count($h_made_h);
|
|
$count_home += \count($h_got_t);
|
|
$count_home += \count($h_got_h);
|
|
|
|
$count_home = !$count_home ? 1 : $count_home;
|
|
$aspettativa_home = round($summe_home / $count_home, 1);
|
|
|
|
$summe_away = array_sum($a_made_t) * $away_made_total;
|
|
$summe_away += array_sum($a_made_a) * $away_made_home;
|
|
$summe_away += array_sum($a_got_t) * $away_got_total;
|
|
$summe_away += array_sum($a_got_a) * $away_got_home;
|
|
$count_away = \count($a_made_t);
|
|
$count_away += \count($a_made_a);
|
|
$count_away += \count($a_got_t);
|
|
$count_away += \count($a_got_a);
|
|
|
|
$count_away = !$count_away ? 1 : $count_away;
|
|
$aspettativa_away = round($summe_away / $count_away, 1);
|
|
|
|
return ['home' => $aspettativa_home, 'away' => $aspettativa_away];
|
|
}
|
|
}
|