Skip to content

Commit 86793b5

Browse files
Update predictive-maintenance/mapper/pkg/inference/detector.go
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent d22485c commit 86793b5

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

predictive-maintenance/mapper/pkg/inference/detector.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)