wip fix
This commit is contained in:
1 parent
9bcd4432c6
commit
6f92f9e1d5
1209 files changed
+220940
No files matched your search
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets\Charts;
|
||||
|
||||
class HelperMoveingAveragePerformens
|
||||
{
|
||||
public static function get(&$data)
|
||||
{
|
||||
if (! $data) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data['labels'] = array_slice($data['labels'], 2);
|
||||
|
||||
$datasets = $data['datasets'];
|
||||
foreach ($datasets as $k => $dataset) {
|
||||
$arr = $dataset['data'];
|
||||
|
||||
// dd($arr);
|
||||
|
||||
$new = [];
|
||||
$last = count($arr);
|
||||
foreach ($arr as $key => $value) {
|
||||
if ($key == 1 && $last > 2) {
|
||||
$new[] = round(($arr[0] + $value + $arr[2]) / 3, 2);
|
||||
} elseif ($key > 1 && $key < $last - 1) {
|
||||
$new[] = round(($arr[$key - 1] + $value + $arr[$key + 1]) / 3, 2);
|
||||
}
|
||||
}
|
||||
$data['datasets'][$k]['data'] = $new;
|
||||
}
|
||||
}
|
||||
|
||||
public static function fillHoles(array &$arr)
|
||||
{
|
||||
if (! $arr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $arr[0]) {
|
||||
// get first value in array and copy it to start if start is null
|
||||
$arr[0] = current(array_filter($arr));
|
||||
}
|
||||
$priv = 0;
|
||||
foreach ($arr as $key => $value) {
|
||||
if ($value) {
|
||||
$priv = $value;
|
||||
} else {
|
||||
if ($priv) {
|
||||
$arr[$key] = $priv;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user