wip
This commit is contained in:
1 parent
6d5b05e561
commit
7cb30a256c
5 files changed
+156
-2
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user