|
|
@@ -1,50 +1,59 @@
|
|
|
import {alignToWindow, removeSpikes} from './cleanData';
|
|
|
import {testData} from './testData';
|
|
|
import * as should from 'should';
|
|
|
+import {TimePoint, TimeSeries} from "./types";
|
|
|
|
|
|
describe('Clean data', () => {
|
|
|
describe('Align to window', () => {
|
|
|
it('Aligns data to 15 minute increments', () => {
|
|
|
// Adapted from the data in testData.ts
|
|
|
- const expected = [
|
|
|
- { time: 1640296800000, value: -4.2 },
|
|
|
- { time: 1640297700000, value: -4.3 },
|
|
|
- { time: 1640298600000, value: -4.4 },
|
|
|
- { time: 1640299500000, value: -4.2 },
|
|
|
- { time: 1640300400000, value: -4.2 },
|
|
|
- { time: 1640301300000, value: -4.2 },
|
|
|
- { time: 1640302200000, value: -0.2 },
|
|
|
- { time: 1640303100000, value: -2.9 },
|
|
|
- { time: 1640304000000, value: -3.9 },
|
|
|
- { time: 1640304900000, value: -4.0 },
|
|
|
- { time: 1640305800000, value: -3.9 },
|
|
|
- { time: 1640306700000, value: -3.8 },
|
|
|
- { time: 1640307600000, value: -3.8 },
|
|
|
- ];
|
|
|
+ const expected: TimeSeries = {
|
|
|
+ minimum: -4.4,
|
|
|
+ maximum: 3.7,
|
|
|
+ series: [
|
|
|
+ { time: 1640296800000, value: -4.2 },
|
|
|
+ { time: 1640297700000, value: -4.3 },
|
|
|
+ { time: 1640298600000, value: -4.4 },
|
|
|
+ { time: 1640299500000, value: -4.2 },
|
|
|
+ { time: 1640300400000, value: -4.2 },
|
|
|
+ { time: 1640301300000, value: -4.2 },
|
|
|
+ { time: 1640302200000, value: -0.2 },
|
|
|
+ { time: 1640303100000, value: -2.9 },
|
|
|
+ { time: 1640304000000, value: -3.9 },
|
|
|
+ { time: 1640304900000, value: -4.0 },
|
|
|
+ { time: 1640305800000, value: -3.9 },
|
|
|
+ { time: 1640306700000, value: -3.8 },
|
|
|
+ { time: 1640307600000, value: -3.8 },
|
|
|
+ ]
|
|
|
+ };
|
|
|
|
|
|
const actual = alignToWindow(testData, 15);
|
|
|
should(actual).deepEqual(expected);
|
|
|
});
|
|
|
|
|
|
it('Skips the first period when empty', () => {
|
|
|
- const input = [
|
|
|
+ const input: TimePoint[] = [
|
|
|
{ time: 1640296752000, value: -4.21 },
|
|
|
{ time: 1640297111475, value: -4.28 },
|
|
|
{ time: 1640297410320, value: -4.29 },
|
|
|
{ time: 1640297709214, value: -4.34 },
|
|
|
];
|
|
|
|
|
|
- const expected = [
|
|
|
- { time: 1640296800000, value: -4.2 },
|
|
|
- { time: 1640297700000, value: -4.3 },
|
|
|
- ];
|
|
|
+ const expected: TimeSeries = {
|
|
|
+ minimum: -4.3,
|
|
|
+ maximum: -4.2,
|
|
|
+ series: [
|
|
|
+ { time: 1640296800000, value: -4.2 },
|
|
|
+ { time: 1640297700000, value: -4.3 },
|
|
|
+ ]
|
|
|
+ };
|
|
|
|
|
|
const actual = alignToWindow(input, 15);
|
|
|
should(actual).deepEqual(expected);
|
|
|
});
|
|
|
|
|
|
it('Inserts NaN when a middle period is empty', () => {
|
|
|
- const input = [
|
|
|
+ const input: TimePoint[] = [
|
|
|
{ time: 1640296812283, value: -4.21 },
|
|
|
{ time: 1640297111475, value: -4.28 },
|
|
|
// Empty period here
|
|
|
@@ -53,11 +62,15 @@ describe('Clean data', () => {
|
|
|
{ time: 1640298905167, value: -4.27 },
|
|
|
];
|
|
|
|
|
|
- const expected = [
|
|
|
- { time: 1640296800000, value: -4.2 },
|
|
|
- { time: 1640297700000, value: NaN },
|
|
|
- { time: 1640298600000, value: -4.4 },
|
|
|
- ];
|
|
|
+ const expected: TimeSeries = {
|
|
|
+ minimum: -4.4,
|
|
|
+ maximum: -4.2,
|
|
|
+ series: [
|
|
|
+ { time: 1640296800000, value: -4.2 },
|
|
|
+ { time: 1640297700000, value: NaN },
|
|
|
+ { time: 1640298600000, value: -4.4 },
|
|
|
+ ]
|
|
|
+ };
|
|
|
|
|
|
const actual = alignToWindow(input, 15);
|
|
|
should(actual).deepEqual(expected);
|
|
|
@@ -69,7 +82,7 @@ describe('Clean data', () => {
|
|
|
// Testing that abnormally large spikes are removed. For example, if
|
|
|
// the chip heats up and causes a 2+ Celsius spike in value.
|
|
|
|
|
|
- const input = [
|
|
|
+ const input: TimePoint[] = [
|
|
|
{ time: 1, value: -4.23 },
|
|
|
{ time: 2, value: -4.14 },
|
|
|
{ time: 3, value: -4.12 },
|
|
|
@@ -92,7 +105,7 @@ describe('Clean data', () => {
|
|
|
|
|
|
it('Sorts data', () => {
|
|
|
// Same data as earlier test, but rearranged
|
|
|
- const input = [
|
|
|
+ const input: TimePoint[] = [
|
|
|
{ time: 4, value: 3.65 }, // Large spike
|
|
|
{ time: 1, value: -4.23 },
|
|
|
{ time: 7, value: -3.63 },
|
|
|
@@ -118,7 +131,7 @@ describe('Clean data', () => {
|
|
|
// as in the summer when the sun starts setting.
|
|
|
|
|
|
// Nothing should be removed from the list.
|
|
|
- const input = [
|
|
|
+ const input: TimePoint[] = [
|
|
|
{ time: 1, value: 32.6 },
|
|
|
{ time: 2, value: 32.3 },
|
|
|
{ time: 3, value: 32.1 },
|