-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.test.js
353 lines (321 loc) · 12.3 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
let preProcess;
function preload(file) {
const fs = require('fs');
let data = fs.readFileSync(file);
return data.toString();
}
const DJISRTParser = require('./');
let data = preload(`./samples/mavic_pro.SRT`);
let MavicPro = DJISRTParser(data, 'mavic_pro.SRT');
test('Reading Mavic Pro file should return valid data', () => {
expect(MavicPro).toBeDefined();
});
test('Result should contain raw metadata', () => {
expect(MavicPro.rawMetadata()).toBeDefined();
});
test('Result should contain processed metadata', () => {
expect(MavicPro.metadata()).toBeDefined();
});
test('Filename should be present', () => {
expect(MavicPro.getFileName()).toBe('mavic_pro.SRT');
});
test('Date should be present', () => {
expect(typeof MavicPro.metadata().stats.DATE).toBe('number');
});
test('This sample should contain a Home point', () => {
expect(MavicPro.metadata().stats.HOME[0]).toEqual({
LATITUDE: -20.2532,
LONGITUDE: 149.0251
});
});
test('The average 3D speed should be set', () => {
expect(MavicPro.metadata().stats.SPEED.THREED.avg).toBe(21.56914922116961);
});
test('The max altitude should be readable from the barometer', () => {
expect(MavicPro.metadata().stats.BAROMETER.max).toBe(118.65000000000002);
});
test('The duration should be a readable number', () => {
expect(MavicPro.metadata().stats.DURATION).toBe(468000);
});
test('We should get the flight distance', () => {
expect(MavicPro.metadata().stats.DISTANCE).toBe(2804.6421264700957);
});
test('We should be able to read the aperture', () => {
expect(MavicPro.metadata().packets[0].FNUM).toBe(2.2);
});
test('We should be able to read the iso', () => {
expect(MavicPro.metadata().packets[0].ISO).toBe(100);
});
test('We should be able to read the shutter speed', () => {
expect(MavicPro.metadata().packets[0].SHUTTER).toBe(60);
});
//Mavic Air (no gps data)
data = preload(`./samples/mavic_air.SRT`);
let Mavic_Air = DJISRTParser(data, 'mavic_air.SRT');
test('Mavic Air result should contain at least some metadata', () => {
expect(Mavic_Air.metadata()).toBeDefined();
});
//Old format
data = preload(`./samples/old_format.SRT`);
let Old_Format = DJISRTParser(data, 'old_format.SRT');
test('Old Format result should contain metadata', () => {
expect(Old_Format.metadata()).toBeDefined();
});
test('The average 3D speed should be set in the old format', () => {
expect(Old_Format.metadata().stats.SPEED.THREED.avg).toBe(21.56914922116961);
});
test('The max altitude should be readable from the HB field', () => {
expect(Old_Format.metadata().stats.HB.max).toBe(118.65000000000002);
});
test('We should be able to read the aperture in the old format', () => {
expect(Old_Format.metadata().packets[0].FNUM).toBe(2.8);
});
test('We should be able to read the exposure in the old format', () => {
expect(Old_Format.metadata().stats.EV.avg).toBe(0);
});
//mavic 2
data = preload(`./samples/mavic_2_style.SRT`);
let Mavic_2 = DJISRTParser(data, 'mavic_2_style.SRT');
test('Mavic 2 Format result should contain metadata', () => {
expect(Mavic_2.metadata()).toBeDefined();
});
test('The average 2D speed should be set in the Mavic 2 format', () => {
expect(Mavic_2.metadata().stats.SPEED.TWOD.avg).toBe(19.531079073870547);
});
test('We should be able to read the aperture in the Mavic 2 format', () => {
expect(Mavic_2.metadata().packets[0].FNUM).toBe(2.2);
});
test('We should be able to read the exposure in the Mavic 2 format', () => {
expect(Mavic_2.metadata().stats.EV.avg).toBe(0);
});
//mavic 2 zoom
data = preload(`./samples/m2zoom.SRT`);
let m2z = DJISRTParser(data, 'm2zoom.SRT');
test('Mavic 2 Zoom Format result should contain metadata', () => {
expect(m2z.metadata()).toBeDefined();
});
test('The average 2D speed should be set in the Mavic 2 Zoom format', () => {
expect(m2z.metadata().stats.SPEED.TWOD.avg).toBe(10.102267576077548);
});
test('We should be able to read the aperture in the Mavic 2 Zoom format', () => {
expect(m2z.metadata().packets[0].FNUM).toBe(2.8);
});
test('We should be able to read the exposure in the Mavic 2 Zoom format', () => {
expect(m2z.metadata().stats.EV.avg).toBe(0);
});
//mavic pro buggy format
data = preload(`./samples/mavic_pro_buggy.SRT`);
let Buggy = DJISRTParser(data, 'mavic_pro_buggy.SRT');
test('Buggy Format result should contain metadata', () => {
expect(Buggy.metadata()).toBeDefined();
});
test('The average 3D speed should be set in the buggy format', () => {
expect(Buggy.metadata().stats.SPEED.THREED.avg).toBe(13.40770963200714);
});
test('The max satellites should be readable from the SATELLITES field', () => {
expect(Buggy.metadata().stats.GPS.SATELLITES.max).toBe(18);
});
test('We should be able to read the aperture in the buggy format', () => {
expect(Buggy.metadata().packets[0].FNUM).toBe(2.2);
});
//p4p attempt
data = preload(`./samples/p4p_sample.SRT`);
let p4p = DJISRTParser(data, 'p4p_sample.SRT');
test('p4p Format result should contain metadata', () => {
expect(p4p.metadata()).toBeDefined();
});
test('The max satellites should be readable from the SATELLITES field', () => {
expect(p4p.metadata().stats.GPS.SATELLITES.max).toBe(18);
});
test('We should be able to read the aperture in the p4p format', () => {
expect(p4p.metadata().packets[0].FNUM).toBe(3.2);
});
//p4rtk
data = preload(`./samples/p4_rtk.SRT`);
let p4rtk = DJISRTParser(data, 'p4_rtk.SRT');
test('p4 RTK Format result should contain metadata', () => {
expect(p4rtk.metadata()).toBeDefined();
});
test('The max satellites should be readable from the SATELLITES field', () => {
expect(p4rtk.metadata().stats.GPS.SATELLITES.max).toBe(15);
});
test('We should be able to read the aperture in the p4p rtk format', () => {
expect(p4rtk.metadata().packets[0].FNUM).toBe(5.6);
});
test('We should be able to read G_PRY in the p4p rtk format', () => {
expect(p4rtk.metadata().packets[0].G_PRY).toBeDefined();
});
//mavic 2 pro extra large - Milliseconds
data = preload(`./samples/mavic_2pro_new.SRT`);
let Mavic_2_pro = DJISRTParser(data, 'mavic_2pro_new.SRT');
Mavic_2_pro.setSmoothing(0);
test('Mavic 2 large - all the packets', () => {
expect(Mavic_2_pro.metadata().packets.length).toBe(8952);
});
test('Mavic 2 large - aprox. half the packets', () => {
Mavic_2_pro.setMillisecondsPerSample(80);
expect(Mavic_2_pro.metadata().packets.length).toBe(4559);
});
test('Mavic 2 large - low quantity packets', () => {
Mavic_2_pro.setMillisecondsPerSample(1500);
expect(Mavic_2_pro.metadata().packets.length).toBe(243);
});
test('Mavic 2 large - get Milliseconds function', () => {
Mavic_2_pro.setMillisecondsPerSample(700);
expect(Mavic_2_pro.getMillisecondsPerSample()).toBe(700);
});
test('Mavic 2 Pro Format result should contain metadata', () => {
expect(Mavic_2_pro.metadata()).toBeDefined();
});
test('We should be able to read the focal length in the Mavic 2 format', () => {
expect(Mavic_2_pro.metadata().packets[0].FOCAL_LEN).toBe(280);
});
// EXPORT TO FORMATS
let data_p4_rtk2 = preload(`./samples/p4_rtk.SRT`);
let p4_rtk2 = DJISRTParser(data_p4_rtk2, 'p4_rtk.SRT');
test('Single file to CSV. Some "V_S" have negative values', () => {
expect(p4_rtk2.toCSV().length).toBe(16419);
});
test('Single file to CSV, rawMetadata enabled', () => {
expect(p4_rtk2.toCSV(true).length).toBe(10238);
});
test('Single file to GeoJSON with waypoints', () => {
preProcess = p4_rtk2.toGeoJSON(
/* rawMetadata = */ false,
/* waypoints = */ true
);
expect(preProcess.length).toBe(34647);
let coordinate = JSON.parse(preProcess).features[0].geometry.coordinates[0];
expect(typeof coordinate).toBe('number'); // Very important, coordinates must be numbers
});
test('Single file to GeoJSON with waypoints, rawMetadata enabled', () => {
preProcess = p4_rtk2.toGeoJSON(
/* rawMetadata = */ true,
/* waypoints = */ true
);
expect(preProcess.length).toBe(21242);
let coordinate = JSON.parse(preProcess).features[0].geometry.coordinates[0];
expect(typeof coordinate).toBe('number'); // Very important, coordinates must be numbers
});
// Set custom properties and export
data = preload(`./samples/mavic_pro.SRT`);
let mavic_pro_ = DJISRTParser(data, 'mavic_pro.SRT');
test('Set custom properties and export', () => {
// expect(mavic_pro_.toCSV().length).toBe(96532);
mavic_pro_.setProperties({ propInt: 123, propInt2: 456 });
mavic_pro_.setProperties({ propExtra: 'Prop added in a second instance' });
// expect(mavic_pro_.toCSV().length).toBe(118087);
let geoJSONProps = JSON.parse(mavic_pro_.toGeoJSON(false, true)).features[0]
.properties;
expect(geoJSONProps.propInt).toBe(123);
expect(geoJSONProps.propExtra).toBe('Prop added in a second instance');
});
// Multiple Files
let multi_mavic_pro_p4_rtk = DJISRTParser(
[data, data_p4_rtk2],
['mavic_pro.SRT', 'p4_rtk.SRT']
);
test('Get multiple files name', () => {
expect(multi_mavic_pro_p4_rtk.getFileName()).toEqual([
'mavic_pro.SRT',
'p4_rtk.SRT'
]);
});
// test('Multiple files to CSV', () => {
// expect(multi_mavic_pro_p4_rtk.toCSV().length).toBe(124137);
// });
test('Multiple files to CSV, rawMetadata enabled', () => {
expect(multi_mavic_pro_p4_rtk.toCSV(true).length).toBe(81330);
});
// test('Multiple files to GeoJSON with waypoints', () => {
// expect(multi_mavic_pro_p4_rtk.toGeoJSON(false, true).length).toBe(247337);
// });
test('Multiple files to GeoJSON with waypoints, rawMetadata enabled', () => {
expect(multi_mavic_pro_p4_rtk.toGeoJSON(true, true).length).toBe(154735);
});
test('Get metadata from a particular file', () => {
expect(
multi_mavic_pro_p4_rtk.metadata('mavic_pro.SRT').stats.GPS.SATELLITES.max
).toBe(16);
});
test('Get rawMetadata from a particular file', () => {
expect(
multi_mavic_pro_p4_rtk.rawMetadata('mavic_pro.SRT')[0].TIMECODE
).toBeDefined();
});
test('Get rawMetadata from another particular file', () => {
expect(
multi_mavic_pro_p4_rtk.rawMetadata('p4_rtk.SRT')[0].F_PRY
).toBeDefined(); // Method 1
expect(
multi_mavic_pro_p4_rtk.rawMetadata()['p4_rtk.SRT'][0].F_PRY
).toBeDefined(); // Method 2
});
test('Set milliseconds on multiple files', () => {
expect(
JSON.parse(multi_mavic_pro_p4_rtk.toGeoJSON()).features[1].geometry
.coordinates.length
).toBe(55); // Original coordinates
multi_mavic_pro_p4_rtk.setMillisecondsPerSample(7000);
expect(
JSON.parse(multi_mavic_pro_p4_rtk.toGeoJSON()).features[1].geometry
.coordinates.length
).toBe(8); // Reduced coordinates
});
test('Set smoothing on multiple files', () => {
multi_mavic_pro_p4_rtk.setSmoothing(0);
expect(multi_mavic_pro_p4_rtk.toGeoJSON()).toBeDefined();
});
// Load PreparedData
let preparedData = require('./samples/preparedData.json');
let loadPrepared = DJISRTParser(
preparedData,
'preparedData.SRT',
/* isPreparedData = */ true
);
test('Loading prepared data in json format', () => {
expect(loadPrepared.metadata().stats).toBeDefined();
});
loadPrepared = DJISRTParser(
JSON.stringify(preparedData),
'preparedData.SRT',
/* isPreparedData = */ true
);
test('Loading prepared data as dataString', () => {
expect(loadPrepared.metadata().stats).toBeDefined();
});
// Incomplete and Empty Data
let empty = preload(`./samples/broken_empty.SRT`);
let empty2 = preload(`./samples/broken_empty2.SRT`);
let incomplete = preload(`./samples/broken_incomplete.SRT`);
let brokenData = DJISRTParser(
[empty, empty2, incomplete],
['broken_empty.SRT', 'broken_empty2.SRT', 'broken_incomplete.SRT']
);
test('Loading multiple files with no data, or incomplete', () => {
expect(brokenData).toBeDefined();
expect(brokenData.toGeoJSON()).toBeDefined();
expect(brokenData.toCSV()).toBeDefined();
});
let incompleteData = DJISRTParser(
[incomplete, data],
['broken_incomplete.SRT', 'mavic_pro.SRT']
);
// test('Loading multiples files, one with incomplete/broken data', () => {
// expect(incompleteData.toGeoJSON(false, true).length).toBe(221451);
// });
let incompleteData2 = preload(`./samples/broken_incomplete2.SRT`);
let incomplete2 = DJISRTParser(incompleteData2, 'broken_incomplete2.SRT');
test('Loading file with incomplete/broken GPS data and filling it', () => {
incomplete2.setSmoothing(0);
expect(
JSON.parse(incomplete2.toGeoJSON(false, true)).features[4].geometry
.coordinates
).toEqual([-57.823383, -34.869941]);
});
let mixedData = preload(`./samples/mix_p4rtk_mavic2pro.srt`);
let mixed = DJISRTParser(mixedData, 'mix_p4rtk_mavic2pro.srt');
test('Mixed data', () => {
mixed.setSmoothing(0);
expect(mixed.toGeoJSON(false, true)).toBeDefined();
});