wip
This commit is contained in:
1 parent
49e883e49e
commit
41d91a7124
5 files changed
+231
-127
No files matched your search
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets\PlayerProps;
|
||||
|
||||
use App\Models\StatistikoConfig;
|
||||
use App\Models\StatistikoEvent;
|
||||
|
||||
class Expectations
|
||||
{
|
||||
public static function load(int $team_id)
|
||||
{
|
||||
$bettypes = ['gls', 'fls', 'ofs', 'crd', 'snt', 'tsh'];
|
||||
$data = StatistikoEvent::where(function ($query) use ($team_id) {
|
||||
return $query->orWhere('home_id', $team_id)
|
||||
->orWhere('away_id', '=', $team_id);
|
||||
})->get();
|
||||
|
||||
$count_events = $data->count();
|
||||
$count_events = ! $count_events ? 1 : $count_events;
|
||||
|
||||
$config = StatistikoConfig::pluck('value', 'varname')->toArray();
|
||||
$work = [];
|
||||
foreach ($config as $key => $value) {
|
||||
$work[$key] = 0;
|
||||
}
|
||||
|
||||
foreach ($data as $value) {
|
||||
foreach ($bettypes as $type) {
|
||||
if ($value['home_id'] == $team_id) {
|
||||
$work[$type.'_home_made_total'] += $value[$type.'_h'];
|
||||
// $work[$type.'_home_made_home'] += $value[$type.'_h'];
|
||||
$work[$type.'_home_got_total'] += $value[$type.'_a'];
|
||||
// $work[$type.'_home_got_home'] += $value[$type.'_a'];
|
||||
} elseif ($value['away_id'] == $team_id) {
|
||||
$work[$type.'_away_made_total'] += $value[$type.'_a'];
|
||||
// $work[$type.'_away_made_home'] += $value[$type.'_a'];
|
||||
$work[$type.'_away_got_total'] += $value[$type.'_h'];
|
||||
// $work[$type.'_away_got_home'] += $value[$type.'_h'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$config = StatistikoConfig::pluck('value', 'varname')->toArray();
|
||||
foreach ($config as $key => $value) {
|
||||
$work[$key] = $work[$key] * $value;
|
||||
}
|
||||
|
||||
$aspettativa = [];
|
||||
foreach ($work as $key => $value) {
|
||||
if ($value) {
|
||||
$aspettativa[$key] = round($value /= $count_events, 1);
|
||||
}
|
||||
}
|
||||
|
||||
$finals = [];
|
||||
foreach ($bettypes as $type) {
|
||||
$finals[$type]['home'] = 0;
|
||||
$finals[$type]['away'] = 0;
|
||||
}
|
||||
foreach ($aspettativa as $key => $value) {
|
||||
foreach ($bettypes as $type) {
|
||||
if (strpos($key, $type) !== false) {
|
||||
if (strpos($key, 'home') !== false) {
|
||||
$finals[$type]['home'] += $value;
|
||||
}
|
||||
if (strpos($key, 'away') !== false) {
|
||||
$finals[$type]['away'] += $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $finals;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user