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
6
6
{
7
7
private $ deviation ;
8
8
private $ prevValue ;
9
+ /** @var VectorProcessor */
10
+ private $ processor ;
9
11
10
12
public function __construct ($ deviation = 0.5 )
11
13
{
12
14
$ this ->deviation = $ deviation ;
15
+ $ this ->processor = new MovingAverage (6 );
13
16
}
14
17
15
18
public function value ($ value )
@@ -20,10 +23,11 @@ public function value($value)
20
23
if ($ delta > $ allowedDelta ) {
21
24
return null ;
22
25
} else {
26
+ $ this ->prevValue = $ this ->processor ->value ($ value );
23
27
return $ value ;
24
28
}
25
29
} else {
26
- $ this ->prevValue = $ value ;
30
+ $ this ->prevValue = $ this -> processor -> value ( $ value ) ;
27
31
return $ value ;
28
32
}
29
33
}
Original file line number Diff line number Diff line change @@ -13,9 +13,17 @@ public function addProcessor(VectorProcessor $processor)
13
13
return $ this ;
14
14
}
15
15
16
+ private $ lastValue ;
17
+
18
+ public function getLastValue ()
19
+ {
20
+ return $ this ->lastValue ;
21
+ }
22
+
16
23
public function value ($ value )
17
24
{
18
25
if ($ value === null ) {
26
+ $ this ->lastValue = null ;
19
27
return null ;
20
28
}
21
29
foreach ($ this ->processors as $ processor ) {
@@ -24,6 +32,7 @@ public function value($value)
24
32
break ;
25
33
}
26
34
}
35
+ $ this ->lastValue = $ value ;
27
36
return $ value ;
28
37
}
29
38
}
You can’t perform that action at this time.
0 commit comments