|
@@ -143,6 +143,74 @@ describe('Clean data', () => {
|
|
|
|
|
|
|
|
const actual = removeSpikes(input);
|
|
const actual = removeSpikes(input);
|
|
|
should(actual).deepEqual(input);
|
|
should(actual).deepEqual(input);
|
|
|
- })
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('Does not remove too many spikes', () => {
|
|
|
|
|
+ // Test that it doesn't keep removing more and more spikes, such
|
|
|
|
|
+ // as if there was a power outage, or the temperature actually
|
|
|
|
|
+ // started to rise quickly.
|
|
|
|
|
+
|
|
|
|
|
+ // Values taken from 2024-04-26 07:49 to 10:12 EDT.
|
|
|
|
|
+ const input: TimePoint[] = [
|
|
|
|
|
+ { time: 1, value: 0.95 },
|
|
|
|
|
+ { time: 2, value: -0.52 },
|
|
|
|
|
+ { time: 3, value: -0.88 },
|
|
|
|
|
+ { time: 4, value: -0.82 },
|
|
|
|
|
+ { time: 5, value: -0.74 },
|
|
|
|
|
+ { time: 6, value: -0.5 },
|
|
|
|
|
+ { time: 7, value: 3.36 },
|
|
|
|
|
+ { time: 8, value: 7.98 }, // Some delay happened here.
|
|
|
|
|
+ { time: 9, value: 8.3 }, // And continued to affect here.
|
|
|
|
|
+ { time: 10, value: 3.94 }, // Seemingly normal temperature.
|
|
|
|
|
+ { time: 11, value: 7.23 }, // Long delay happened here.
|
|
|
|
|
+ { time: 12, value: 15.04 }, // But was really resolved here.
|
|
|
|
|
+ { time: 13, value: 8.86 }, // Device cooled back down.
|
|
|
|
|
+ { time: 14, value: 6.41 }, // Normal temperatures mostly resumed here.
|
|
|
|
|
+ { time: 15, value: 5.72 },
|
|
|
|
|
+ { time: 16, value: 5.77 },
|
|
|
|
|
+ { time: 17, value: 5.85 },
|
|
|
|
|
+ { time: 18, value: 6.07 },
|
|
|
|
|
+ { time: 19, value: 6.33 },
|
|
|
|
|
+ { time: 20, value: 6.64 },
|
|
|
|
|
+ { time: 21, value: 6.99 },
|
|
|
|
|
+ { time: 22, value: 7.26 },
|
|
|
|
|
+ { time: 23, value: 7.54 },
|
|
|
|
|
+ { time: 24, value: 7.84 },
|
|
|
|
|
+ { time: 25, value: 10.09 },
|
|
|
|
|
+ ];
|
|
|
|
|
+ const expected: TimePoint[] = [
|
|
|
|
|
+ { time: 1, value: 0.95 },
|
|
|
|
|
+ { time: 2, value: -0.52 },
|
|
|
|
|
+ { time: 3, value: -0.88 },
|
|
|
|
|
+ { time: 4, value: -0.82 },
|
|
|
|
|
+ { time: 5, value: -0.74 },
|
|
|
|
|
+ { time: 6, value: -0.5 },
|
|
|
|
|
+ { time: 7, value: 3.36 },
|
|
|
|
|
+ // These two are definite spikes, but the difference to #7 is within normal range.
|
|
|
|
|
+ { time: 8, value: 7.98 }, // Some delay happened here.
|
|
|
|
|
+ { time: 9, value: 8.3 }, // And continued to affect here.
|
|
|
|
|
+ // This one should be included, but the "compare to previous diff" sees too big of a drop.
|
|
|
|
|
+ // TODO: Figure out how to include this one.
|
|
|
|
|
+ // { time: 10, value: 3.94 },
|
|
|
|
|
+ { time: 11, value: 7.23 }, // Long delay happened here.
|
|
|
|
|
+ // Remove 12, since it was way too big.
|
|
|
|
|
+ { time: 13, value: 8.86 }, // Device cooled back down.
|
|
|
|
|
+ { time: 14, value: 6.41 }, // Normal temperatures mostly resumed here.
|
|
|
|
|
+ { time: 15, value: 5.72 },
|
|
|
|
|
+ { time: 16, value: 5.77 },
|
|
|
|
|
+ { time: 17, value: 5.85 },
|
|
|
|
|
+ { time: 18, value: 6.07 },
|
|
|
|
|
+ { time: 19, value: 6.33 },
|
|
|
|
|
+ { time: 20, value: 6.64 },
|
|
|
|
|
+ { time: 21, value: 6.99 },
|
|
|
|
|
+ { time: 22, value: 7.26 },
|
|
|
|
|
+ { time: 23, value: 7.54 },
|
|
|
|
|
+ { time: 24, value: 7.84 },
|
|
|
|
|
+ { time: 25, value: 10.09 },
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ const actual = removeSpikes(input);
|
|
|
|
|
+ should(actual).deepEqual(expected);
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|