wip
This commit is contained in:
1 parent
86f507e996
commit
cd2763cada
1 file changed
+37
-58
@@ -25,6 +25,7 @@ use Filament\Tables\Contracts\HasTable;
|
||||
use Filament\Tables\Enums\FiltersLayout;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Livewire\Attributes\On;
|
||||
use Livewire\Component;
|
||||
@@ -37,6 +38,7 @@ class BoardDispatcher extends Component implements HasActions, HasSchemas, HasTa
|
||||
use RestrictsFileUploadsToSchemaComponents;
|
||||
|
||||
public array $sourceRecords = [];
|
||||
public array $calculationVariables = [];
|
||||
|
||||
public array $filters = [];
|
||||
|
||||
@@ -245,19 +247,27 @@ class BoardDispatcher extends Component implements HasActions, HasSchemas, HasTa
|
||||
->modalWidth(Width::ExtraLarge)
|
||||
->modalSubmitAction(false)
|
||||
->modalCancelAction(false)
|
||||
->modalContent(fn () => view('filament.modals.position-abbreviation')),
|
||||
->modalContent(fn() => view('filament.modals.position-abbreviation')),
|
||||
Action::make('reset')
|
||||
->hiddenLabel()
|
||||
->size(Size::Small)
|
||||
->tooltip('Remove all players from field')
|
||||
->icon('phosphor-arrows-clockwise')
|
||||
->action(fn () => $this->clearResultTable()),
|
||||
->action(fn() => $this->clearResultTable()),
|
||||
Action::make('copy')
|
||||
->tooltip('Copy results for pasting into a spread sheet')
|
||||
->hiddenLabel()
|
||||
->size(Size::Small)
|
||||
->icon('phosphor-copy')
|
||||
->action(fn () => $this->copyResult()),
|
||||
->action(fn() => $this->copyResult()),
|
||||
Action::make('copy')
|
||||
->tooltip('Copy calculation variables')
|
||||
->hiddenLabel()
|
||||
->size(Size::Small)
|
||||
->hidden(fn() => !in_array(Auth::user()->id, [1, 2]))
|
||||
->color('warning')
|
||||
->icon('phosphor-copy')
|
||||
->action(fn() => $this->copyDevelopment()),
|
||||
])
|
||||
/**
|
||||
* WICHTIG: Da Filament v5 zwingend eine Query braucht, nutzen wir ein
|
||||
@@ -270,7 +280,7 @@ class BoardDispatcher extends Component implements HasActions, HasSchemas, HasTa
|
||||
->columns([
|
||||
ViewColumn::make('drag_card')
|
||||
->columnSpanFull()
|
||||
->label(fn () => $this->getHeadingTable())
|
||||
->label(fn() => $this->getHeadingTable())
|
||||
->view('filament.tables.columns.drag-card'),
|
||||
])
|
||||
->filters([
|
||||
@@ -286,7 +296,7 @@ class BoardDispatcher extends Component implements HasActions, HasSchemas, HasTa
|
||||
'midfield' => '<span class="text-blue-500">Midfield</span>',
|
||||
'defence' => '<span class="text-green-500">Defence</span>',
|
||||
'goalkeeper' => '<span class="text-gray-500">Goalkeeper</span>',
|
||||
])->modifyFormFieldUsing(fn (Select $component) => $component->allowHtml())
|
||||
])->modifyFormFieldUsing(fn(Select $component) => $component->allowHtml())
|
||||
->query(function ($query) {
|
||||
return $query;
|
||||
})->indicateUsing(function (array $data): array {
|
||||
@@ -401,29 +411,22 @@ class BoardDispatcher extends Component implements HasActions, HasSchemas, HasTa
|
||||
$this->player_on_field_counter = 0;
|
||||
}
|
||||
|
||||
public function copyDevelopment()
|
||||
{
|
||||
$copystring = '';
|
||||
foreach ($this->calculationVariables as $row) {
|
||||
$copystring .= implode("\t", $row) . "\n";
|
||||
}
|
||||
$this->js("navigator.clipboard.writeText(`$copystring`)");
|
||||
}
|
||||
|
||||
public function copyResult()
|
||||
{
|
||||
if ($this->player_on_field_counter < 10) {
|
||||
return;
|
||||
}
|
||||
// "id" => 1218016
|
||||
// "name" => "Walter Nuñez"
|
||||
// "pos" => "LW"
|
||||
// "foot" => "Right"
|
||||
// "tot_evt" => 2
|
||||
// "tot_min" => 102
|
||||
// "ave_min" => 51
|
||||
// "gls" => 0
|
||||
// "fls" => 3
|
||||
// "ofs" => 0
|
||||
// "crd" => 0
|
||||
// "snt" => 0
|
||||
// "tsh" => 0
|
||||
// "color_evt" => "success"
|
||||
// "area" => "attack"
|
||||
// "color_pos" => "warning"
|
||||
$header = ['name', 'foot', 'events', 'average min', 'position', 'on field', 'gls', 'fls', 'ofs', 'snt', 'tsh', 'crd'];
|
||||
$copystring = implode("\t", $header)."\n";
|
||||
$copystring = implode("\t", $header) . "\n";
|
||||
foreach ($this->sourceRecords as $row) {
|
||||
$tmp = [];
|
||||
$tmp[] = $row['name'];
|
||||
@@ -443,7 +446,7 @@ class BoardDispatcher extends Component implements HasActions, HasSchemas, HasTa
|
||||
$tmp[] = $row['tsh'];
|
||||
$tmp[] = $row['crd'];
|
||||
|
||||
$copystring .= implode("\t", $tmp)."\n";
|
||||
$copystring .= implode("\t", $tmp) . "\n";
|
||||
}
|
||||
$this->js("navigator.clipboard.writeText(`$copystring`)");
|
||||
}
|
||||
@@ -504,6 +507,7 @@ class BoardDispatcher extends Component implements HasActions, HasSchemas, HasTa
|
||||
"shots_off_target" => 0
|
||||
*/
|
||||
$results = [];
|
||||
$this->calculationVariables = [];
|
||||
foreach ($player_totals as $val) {
|
||||
if ($val->details && $val->details->is_active) {
|
||||
|
||||
@@ -557,36 +561,38 @@ class BoardDispatcher extends Component implements HasActions, HasSchemas, HasTa
|
||||
$bettypes = ['goals', 'cards', 'fouls', 'offsides', 'total_shots', 'shots_on_target'];
|
||||
foreach ($bettypes as $bettype) {
|
||||
|
||||
$asp_statistica = (float) SofaScorePlayerPosition::where('ss_code', $position)->value('exp_'.$bettype);
|
||||
$asp_statistica = (float) SofaScorePlayerPosition::where('ss_code', $position)->value('exp_' . $bettype);
|
||||
|
||||
$tmp['asp_statistica_'.$bettype] = $asp_statistica;
|
||||
$tmp['asp_statistica_' . $bettype] = $asp_statistica;
|
||||
|
||||
if ($val->total_min < $this->y_value) {
|
||||
// Se la SMG è < Y per quel Player prenderemo in considerazione solo l'Aspettativa Statistica (AS).
|
||||
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
|
||||
$tmp['asp_teorica_' . $bettype] = $asp_statistica;
|
||||
} else {
|
||||
// Aspettativa Teorica (AT) Goals = (X * AdG + AS) / (1 + X)
|
||||
// dove X è un valore che dovrebbe essere parametrizzabile da una interfaccia.
|
||||
// Il valore iniziale lo fissiamo a X = 3
|
||||
// (AT)
|
||||
$tmp['asp_teorica_'.$bettype] = ($this->x_value * $asp_gioco + $asp_statistica) / (1 + $this->x_value);
|
||||
$tmp['asp_teorica_' . $bettype] = ($this->x_value * $asp_gioco + $asp_statistica) / (1 + $this->x_value);
|
||||
}
|
||||
}
|
||||
// Calcolare la Somma di tutte le AT (colonna G della Tabella)
|
||||
// Considerare la ATR calcolata allo Step 1 (colonna I della Tabella)
|
||||
// Aspettativa per Player: AP = AT * ATR / TOT AT
|
||||
|
||||
$results[] = $tmp;
|
||||
|
||||
// for dev copy
|
||||
$this->calculationVariables = $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
$bettypes = ['goals', 'cards', 'fouls', 'offsides', 'total_shots', 'shots_on_target'];
|
||||
foreach ($bettypes as $bettype) {
|
||||
$total_bettype = array_sum(array_column($results, 'asp_teorica_'.$bettype));
|
||||
$total_bettype = array_sum(array_column($results, 'asp_teorica_' . $bettype));
|
||||
foreach ($results as $key => $value) {
|
||||
// Aspettativa per Player: AP = AT * ATR / TOT AT
|
||||
$results[$key]['asp_total_'.$bettype] = $total_bettype;
|
||||
$results[$key]['asp_player_'.$bettype] = ((float) $value['asp_team'] * (float) $value['asp_teorica_'.$bettype]) / $total_bettype;
|
||||
$results[$key]['asp_total_' . $bettype] = $total_bettype;
|
||||
$results[$key]['asp_player_' . $bettype] = ((float) $value['asp_team'] * (float) $value['asp_teorica_' . $bettype]) / $total_bettype;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -596,33 +602,6 @@ class BoardDispatcher extends Component implements HasActions, HasSchemas, HasTa
|
||||
foreach ($this->sourceRecords as $k => $record) {
|
||||
|
||||
foreach ($results as $key => $result) {
|
||||
// "id" => 44691
|
||||
// "name" => "Maicon"
|
||||
// "asp_team" => "1.11030870045550"
|
||||
// "asp_team_riferimento" => 2.8868026211843
|
||||
// "active" => 0
|
||||
// "position" => "DC"
|
||||
// "somma_goals" => 1044
|
||||
// "somma_minuti" => 1044
|
||||
// "asp_gioco" => 90
|
||||
// "asp_statistica_goals" => 0.044
|
||||
// "asp_teorica_goals" => 67.511
|
||||
// "asp_statistica_cards" => 0.195
|
||||
// "asp_teorica_cards" => 67.54875
|
||||
// "asp_statistica_fouls" => 0.959
|
||||
// "asp_teorica_fouls" => 67.73975
|
||||
// "asp_statistica_offsides" => 0.036
|
||||
// "asp_teorica_offsides" => 67.509
|
||||
// "asp_statistica_total_shots" => 0.525
|
||||
// "asp_teorica_total_shots" => 67.63125
|
||||
// "asp_statistica_shots_on_target" => 0.263
|
||||
// "asp_teorica_shots_on_target" => 67.56575
|
||||
// "asp_player_goals" => 0.041110675617421
|
||||
// "asp_player_cards" => 0.041126169295623
|
||||
// "asp_player_fouls" => 0.041104958293849
|
||||
// "asp_player_offsides" => 0.041105354678332
|
||||
// "asp_player_total_shots" => 0.041028401589513
|
||||
// "asp_player_shots_on_target" => 0.041094150075013
|
||||
if ($record['id'] == $result['id']) {
|
||||
// dd($result);
|
||||
$this->sourceRecords[$k]['active'] = $result['active'];
|
||||
|
||||
Reference in new issue
Block a user