wip
This commit is contained in:
1 parent
fb8518597f
commit
90c3ad32cb
6 files changed
+399
-264
No files matched your search
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Statistics;
|
||||
|
||||
class MoveingAverage
|
||||
{
|
||||
public static function get(&$data)
|
||||
{
|
||||
|
||||
// dd($data);
|
||||
|
||||
$arr = $data['datasets'][0]['data'];
|
||||
|
||||
$new = [];
|
||||
$last = count($arr);
|
||||
$second_last = $last--;
|
||||
foreach ($arr as $key => $value) {
|
||||
switch ($key) {
|
||||
case 0:
|
||||
$new[] = $value;
|
||||
break;
|
||||
case 1:
|
||||
$new[] = ($arr[0] + $value) / 2;
|
||||
break;
|
||||
case $second_last:
|
||||
$new[] = ($arr[$second_last] + $arr[$last]) / 2;
|
||||
break;
|
||||
case $last:
|
||||
$new[] = $arr[$last];
|
||||
break;
|
||||
default:
|
||||
$before = $key--;
|
||||
$after = $key++;
|
||||
$new[] = ($arr[$before] + $value + $arr[$after]) / 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// $data['datasets'][0]['backgroundColor'] = '#00a63e';
|
||||
$data['datasets'][0]['borderColor'] = '#00a63e';
|
||||
// $data['datasets'][0]['fill'] = true;
|
||||
$data['datasets'][0]['tension'] = 0.5;
|
||||
// $data['datasets'][0]['borderRadius'] = 30;
|
||||
$data['datasets'][0]['data'] = $new;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user