File tree Expand file tree Collapse file tree 3 files changed +37
-1
lines changed
Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Phperf \Pipeline \Vector ;
4+
5+
6+ class Custom implements VectorProcessor
7+ {
8+ /** @var callable */
9+ private $ callable ;
10+
11+ public function __construct (callable $ callable )
12+ {
13+ $ this ->callable = $ callable ;
14+ }
15+
16+ public function value ($ value )
17+ {
18+ $ c = $ this ->callable ;
19+ return $ c ($ value );
20+ }
21+
22+
23+ }
Original file line number Diff line number Diff line change @@ -6,10 +6,13 @@ class DropAnomaly implements VectorProcessor
66{
77 private $ deviation ;
88 private $ prevValue ;
9+ /** @var VectorProcessor */
10+ private $ processor ;
911
1012 public function __construct ($ deviation = 0.5 )
1113 {
1214 $ this ->deviation = $ deviation ;
15+ $ this ->processor = new MovingAverage (6 );
1316 }
1417
1518 public function value ($ value )
@@ -20,10 +23,11 @@ public function value($value)
2023 if ($ delta > $ allowedDelta ) {
2124 return null ;
2225 } else {
26+ $ this ->prevValue = $ this ->processor ->value ($ value );
2327 return $ value ;
2428 }
2529 } else {
26- $ this ->prevValue = $ value ;
30+ $ this ->prevValue = $ this -> processor -> value ( $ value ) ;
2731 return $ value ;
2832 }
2933 }
Original file line number Diff line number Diff line change @@ -13,9 +13,17 @@ public function addProcessor(VectorProcessor $processor)
1313 return $ this ;
1414 }
1515
16+ private $ lastValue ;
17+
18+ public function getLastValue ()
19+ {
20+ return $ this ->lastValue ;
21+ }
22+
1623 public function value ($ value )
1724 {
1825 if ($ value === null ) {
26+ $ this ->lastValue = null ;
1927 return null ;
2028 }
2129 foreach ($ this ->processors as $ processor ) {
@@ -24,6 +32,7 @@ public function value($value)
2432 break ;
2533 }
2634 }
35+ $ this ->lastValue = $ value ;
2736 return $ value ;
2837 }
2938}
You can’t perform that action at this time.
0 commit comments