enhance: change -3 to -4 to handle outliers in timebased bf#1649
Merged
LaurenceJJones merged 1 commit intocrowdsecurity:masterfrom Jan 21, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Problem
With [-3:] (3 events = 2 intervals), the median calculation is vulnerable to outliers:
Events: 09:17:15, 09:17:17, 09:17:18, 10:17:14
Last 3: 09:17:17, 09:17:18, 10:17:14
Intervals: [1s, 60min]
Median of 2 = average = (1s + 60min) / 2 ≈ 30min → TRIGGERS (false positive)
With only 2 intervals, there's no true "middle" value—the median becomes the average of both, so a single outlier heavily skews the result.
Solution
With [-4:] (4 events = 3 intervals), we get a true median:
Events: 13:00:00, 13:00:02, 13:00:04, 14:00:04
Intervals: [2s, 2s, 60min]
Sorted: [2s, 2s, 60min]
Median of 3 = middle value = 2s → NO trigger ✓
A single outlier can never exceed 1/3 of the intervals, so the median reliably reflects the typical pattern rather than being skewed by one anomalous gap.
Summary
Checklist