|
|
@@ -1,51 +1,86 @@
|
|
|
-import {Reading, Values} from './types';
|
|
|
-import {splitData} from './processData';
|
|
|
+import {Minutes, Reading, TimeSeries, Timestamp, Values} from './types';
|
|
|
+import {processData, splitData} from './processData';
|
|
|
import should = require('should');
|
|
|
|
|
|
describe('Process Data', () => {
|
|
|
- it('Splits data into parts', () => {
|
|
|
- const input:Reading[] = createTestData(1);
|
|
|
-
|
|
|
- const expected:Values = {
|
|
|
- temperature: [{
|
|
|
- value: input[0].temperature,
|
|
|
- time: input[0].time
|
|
|
- }],
|
|
|
- humidity: [{
|
|
|
- value: input[0].humidity,
|
|
|
- time: input[0].time
|
|
|
- }],
|
|
|
- pressure: [{
|
|
|
- value: input[0].pressure,
|
|
|
- time: input[0].time
|
|
|
- }],
|
|
|
- light: [{
|
|
|
- value: input[0].light,
|
|
|
- time: input[0].time
|
|
|
- }],
|
|
|
- };
|
|
|
-
|
|
|
- const actual = splitData(input);
|
|
|
- should(actual).deepEqual(expected);
|
|
|
+ describe('Split Data', () => {
|
|
|
+ it('Splits data into streams', () => {
|
|
|
+ const input: Reading[] = createTestData(1);
|
|
|
+
|
|
|
+ const expected: Values = {
|
|
|
+ temperature: [{
|
|
|
+ value: input[0].temperature,
|
|
|
+ time: input[0].time
|
|
|
+ }],
|
|
|
+ humidity: [{
|
|
|
+ value: input[0].humidity,
|
|
|
+ time: input[0].time
|
|
|
+ }],
|
|
|
+ pressure: [{
|
|
|
+ value: input[0].pressure,
|
|
|
+ time: input[0].time
|
|
|
+ }],
|
|
|
+ light: [{
|
|
|
+ value: input[0].light,
|
|
|
+ time: input[0].time
|
|
|
+ }],
|
|
|
+ delay: [{
|
|
|
+ value: 0,
|
|
|
+ time: input[0].time
|
|
|
+ }],
|
|
|
+ };
|
|
|
+
|
|
|
+ const actual = splitData(input);
|
|
|
+ should(actual).deepEqual(expected);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ it('extracts a delay time series', () => {
|
|
|
+ const alignWindow = 3;
|
|
|
+
|
|
|
+ const input: Reading[] = createTestData(12, [2, 2, 2, 3, 2.25, 2, 2, 5, 3, 2, 2, 2])
|
|
|
+
|
|
|
+ const expectedMaxDelays = ['2.0', '2.0', '3.0', '2.3', '2.0', NaN, '5.0', '3.0', '2.0', '2.0'];
|
|
|
+
|
|
|
+ const expectedMaxSeries = [];
|
|
|
+ for(let i = 0; i < expectedMaxDelays.length; i++) {
|
|
|
+ const time = (i+1) * alignWindow * 60 * 1000;
|
|
|
+ expectedMaxSeries.push({
|
|
|
+ time,
|
|
|
+ value: expectedMaxDelays[i]
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ const output: Values = processData(input, {
|
|
|
+ alignWindow
|
|
|
+ });
|
|
|
+
|
|
|
+ should(output.delay).deepEqual(expectedMaxSeries);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
function createTestData(
|
|
|
numElement:number,
|
|
|
+ timeIncrements: Minutes[] = [15],
|
|
|
temperature:number = 5.2,
|
|
|
humidity:number = 45.5,
|
|
|
pressure:number = 995.6,
|
|
|
- light:number = 120,
|
|
|
- timeIncrement:number = 900000 // 15 minutes
|
|
|
+ light:number = 120
|
|
|
) {
|
|
|
let testData:Reading[] = [];
|
|
|
+ let time: Timestamp = 0;
|
|
|
for(let i = 0; i < numElement; i++) {
|
|
|
+ const delay: Minutes = i < timeIncrements.length
|
|
|
+ ? timeIncrements[i]
|
|
|
+ : timeIncrements[timeIncrements.length-1];
|
|
|
+ time += delay * 60 * 1000;
|
|
|
testData.push({
|
|
|
temperature,
|
|
|
humidity,
|
|
|
pressure,
|
|
|
light,
|
|
|
- time: (i+1) * timeIncrement
|
|
|
+ time,
|
|
|
+ delay: null,
|
|
|
});
|
|
|
}
|
|
|
return testData;
|