File tree Expand file tree Collapse file tree
predictive-maintenance/mapper/pkg/inference Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -70,15 +70,8 @@ func (d *Detector) Analyze(reading driver.SensorReading) AnomalyResult {
7070 d .mu .Lock ()
7171 defer d .mu .Unlock ()
7272
73- if len (d .window ) >= d .windowSize {
74- copy (d .window , d .window [1 :])
75- d .window [d .windowSize - 1 ] = reading
76- } else {
77- d .window = append (d .window , reading )
78- }
79-
80- // need 5+ readings to start
8173 if len (d .window ) < 5 {
74+ d .window = append (d .window , reading )
8275 return AnomalyResult {}
8376 }
8477
@@ -89,6 +82,14 @@ func (d *Detector) Analyze(reading driver.SensorReading) AnomalyResult {
8982 tempZ := zScore (reading .Temperature , tempMean , tempStd )
9083 maxZ := math .Max (math .Abs (vibZ ), math .Abs (tempZ ))
9184
85+ // Update window after analysis to avoid masking effect
86+ if len (d .window ) >= d .windowSize {
87+ copy (d .window , d .window [1 :])
88+ d .window [d .windowSize - 1 ] = reading
89+ } else {
90+ d .window = append (d .window , reading )
91+ }
92+
9293 isAnomaly := maxZ > d .zScoreThreshold
9394 confidence := math .Min (1.0 , maxZ / d .zScoreThreshold / 2 )
9495
You can’t perform that action at this time.
0 commit comments