wip
This commit is contained in:
1 parent
6d5b05e561
commit
7cb30a256c
5 files changed
+156
-2
No files matched your search
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Filament\Widgets\Data\HelperMoveingAveragePerformens;
|
||||
use App\Filament\Widgets\Data\LoadPerformance;
|
||||
use Filament\Support\RawJs;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Filament\Widgets\Concerns\InteractsWithPageFilters;
|
||||
|
||||
class ChartEventPerfMoAv extends ChartWidget
|
||||
{
|
||||
use InteractsWithPageFilters;
|
||||
|
||||
protected ?string $heading = 'Events';
|
||||
|
||||
protected ?string $description = 'Performance Moving Average';
|
||||
|
||||
protected ?string $pollingInterval = null;
|
||||
|
||||
protected bool $isCollapsible = true;
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$data = LoadPerformance::load($this->filters);
|
||||
|
||||
if ($data) {
|
||||
|
||||
HelperMoveingAveragePerformens::get($data);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'line';
|
||||
}
|
||||
|
||||
protected function getOptions(): RawJs
|
||||
{
|
||||
return RawJs::make(<<<'JS'
|
||||
{
|
||||
interaction: {
|
||||
intersect: false,
|
||||
},
|
||||
// plugins: {
|
||||
// tooltip: {
|
||||
// callbacks: {
|
||||
// label: (context) => {
|
||||
// return [' '+context.parsed.y, ' '+context.dataset.playing_date[context.dataIndex], ' '+context.dataset.events[context.dataIndex], ' '+context.dataset.results_per_event[context.dataIndex]];
|
||||
// },
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
scales: {
|
||||
x: {
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Days since today'
|
||||
}
|
||||
},
|
||||
y: {
|
||||
beginAtZero:false,
|
||||
ticks: {
|
||||
callback: function(value, index, ticks) {
|
||||
return value % 1 === 0 ? value : '';
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
JS);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Filament\Widgets\Concerns\InteractsWithPageFilters;
|
||||
|
||||
class ChartPlayerPerfMoAv extends ChartWidget
|
||||
{
|
||||
use InteractsWithPageFilters;
|
||||
|
||||
protected ?string $heading = 'Player';
|
||||
|
||||
protected ?string $description = 'Performance Moving Average';
|
||||
|
||||
protected ?string $pollingInterval = null;
|
||||
|
||||
protected bool $isCollapsible = true;
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'line';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets\Data;
|
||||
|
||||
class HelperMoveingAveragePerformens
|
||||
{
|
||||
public static function get(&$data)
|
||||
{
|
||||
$data['labels'] = array_slice($data['labels'], 2);
|
||||
|
||||
$datasets = $data['datasets'];
|
||||
foreach ($datasets as $k => $dataset) {
|
||||
$arr = $dataset['data'];
|
||||
|
||||
self::fillHoles($arr);
|
||||
|
||||
$new = [];
|
||||
$last = count($arr);
|
||||
foreach ($arr as $key => $value) {
|
||||
if ($key == 1 && $last > 2) {
|
||||
$new[] = round(($arr[0] + $value + $arr[2]) / 3, 1);
|
||||
} elseif ($key > 1 && $key < $last - 1) {
|
||||
$new[] = round(($arr[$key - 1] + $value + $arr[$key + 1]) / 3, 1);
|
||||
}
|
||||
}
|
||||
$data['datasets'][$k]['data'] = $new;
|
||||
}
|
||||
}
|
||||
|
||||
public static function fillHoles(array &$arr)
|
||||
{
|
||||
if (! $arr[0]) {
|
||||
// get first value in array and copy it to start if start is null
|
||||
$arr[0] = current(array_filter($arr));
|
||||
}
|
||||
foreach ($arr as $key => $value) {
|
||||
if ($value) {
|
||||
$priv = $value;
|
||||
} else {
|
||||
$arr[$key] = $priv;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,7 +188,7 @@ class LoadPerformance
|
||||
if ($value->player_position == 'M') {
|
||||
$result[$match_id]['mid']['sum_min'] += $value->minutes_played;
|
||||
$result[$match_id]['mid']['rating'] += $value->playerrating_value * $value->minutes_played;
|
||||
} elseif ($value->player_position == 'A') {
|
||||
} elseif ($value->player_position == 'F') {
|
||||
$result[$match_id]['att']['sum_min'] += $value->minutes_played;
|
||||
$result[$match_id]['att']['rating'] += $value->playerrating_value * $value->minutes_played;
|
||||
} elseif ($value->player_position == 'D') {
|
||||
|
||||
Reference in new issue
Block a user