Always put value in first bucket if force is set
For a last function, the only values that matters is the last one so always add it to the first window. This avoid the problem where an OK value may be in a future window but the current window has an older alarm value. Change-Id: I20f8e91da266fdb917dd36ded60d1a5c608b74d0 Closes-Bug: #1618641
This commit is contained in:
parent
1ad8b00ae2
commit
06c23a1ade
@ -98,20 +98,21 @@ public class SlidingWindowStats {
|
||||
/**
|
||||
* Adds the {@code value} to the statistics for the slot associated with the {@code timestamp} and
|
||||
* returns true, else returns false if the {@code timestamp} is outside of the window and
|
||||
* {@code force} is false. If {@code force} is true, always add value
|
||||
* {@code force} is false. If {@code force} is true, always add value to the first window
|
||||
*
|
||||
* @param value to add
|
||||
* @param timestamp to add value for
|
||||
* @param force if true, add value to first window even if timestamp is outside of all windows
|
||||
* @param force if true, add value to first window
|
||||
* @return true if the value was added else false if it the {@code timestamp} was outside the
|
||||
* window and force was false
|
||||
*/
|
||||
public boolean addValue(double value, long timestamp, boolean force) {
|
||||
int index = indexOfTime(timescale.adjust(timestamp));
|
||||
if (index == -1) {
|
||||
if (force) {
|
||||
index = 0;
|
||||
} else {
|
||||
final int index;
|
||||
if (force) {
|
||||
index = 0;
|
||||
} else {
|
||||
index = indexOfTime(timescale.adjust(timestamp));
|
||||
if (index == -1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -170,6 +170,8 @@ public class SlidingWindowStatsTest {
|
||||
TimeResolution.ABSOLUTE, 3, 1, 2, 9);
|
||||
window.addValue(999, 3, true);
|
||||
assertEquals(window.getViewValues(), new double[] { 999 });
|
||||
window.addValue(899, 10, true);
|
||||
assertEquals(window.getViewValues(), new double[] { 899 });
|
||||
}
|
||||
|
||||
public void shouldNotAddOutOfWindowValueWithoutForce() {
|
||||
@ -177,6 +179,8 @@ public class SlidingWindowStatsTest {
|
||||
TimeResolution.ABSOLUTE, 3, 1, 2, 9);
|
||||
window.addValue(999, 3, false);
|
||||
assertEquals(window.getViewValues(), new double[] { Double.NaN });
|
||||
window.addValue(899, 10, false);
|
||||
assertEquals(window.getViewValues(), new double[] { Double.NaN });
|
||||
}
|
||||
|
||||
public void shouldIgnoreOutOfOrderValue() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user