skiz-parser 1.5.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +33 -13
- package/package.json +11 -13
package/index.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import csv from 'csv-parser';
|
|
2
|
-
import
|
|
2
|
+
import { XMLParser } from 'fast-xml-parser';
|
|
3
3
|
import { promisify } from 'util';
|
|
4
4
|
import yauzl from 'yauzl';
|
|
5
5
|
|
|
6
|
+
const parser = new XMLParser({
|
|
7
|
+
attributeNamePrefix: '',
|
|
8
|
+
ignoreAttributes: false,
|
|
9
|
+
});
|
|
10
|
+
|
|
6
11
|
const convertReadStreamToBuffer = (readStream) => {
|
|
7
12
|
return new Promise((resolve, reject) => {
|
|
8
13
|
const chunks = [];
|
|
@@ -67,6 +72,28 @@ const parseNodeCsvFile = (readStream) => {
|
|
|
67
72
|
});
|
|
68
73
|
};
|
|
69
74
|
|
|
75
|
+
const parseRelativeAltitudeSensorCsvFile = (readStream) => {
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
const relativeAltitude = [];
|
|
78
|
+
|
|
79
|
+
readStream
|
|
80
|
+
.pipe(csv({ headers: false }))
|
|
81
|
+
.on('error', reject)
|
|
82
|
+
.on('data', (data) => {
|
|
83
|
+
const values = Object.values(data);
|
|
84
|
+
|
|
85
|
+
relativeAltitude.push({
|
|
86
|
+
timestamp: new Date(parseFloat(values[0]) * 1000.0),
|
|
87
|
+
pressure: parseFloat(values[1]),
|
|
88
|
+
relativeAltitude: parseFloat(values[2]),
|
|
89
|
+
});
|
|
90
|
+
})
|
|
91
|
+
.once('end', () => {
|
|
92
|
+
resolve({ relativeAltitude });
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
|
|
70
97
|
const parseSegmentCsvFile = (readStream) => {
|
|
71
98
|
return new Promise((resolve, reject) => {
|
|
72
99
|
const trackSegments = [];
|
|
@@ -109,13 +136,8 @@ const parseSegmentCsvFile = (readStream) => {
|
|
|
109
136
|
};
|
|
110
137
|
|
|
111
138
|
const parseTrackXmlFile = async (readStream) => {
|
|
112
|
-
const options = {
|
|
113
|
-
attributeNamePrefix: '',
|
|
114
|
-
ignoreAttributes: false,
|
|
115
|
-
};
|
|
116
|
-
|
|
117
139
|
const buffer = await convertReadStreamToBuffer(readStream);
|
|
118
|
-
const parsed =
|
|
140
|
+
const parsed = parser.parse(buffer.toString('utf-8'));
|
|
119
141
|
|
|
120
142
|
const track = parsed.track;
|
|
121
143
|
const metrics = track.metrics;
|
|
@@ -171,13 +193,8 @@ const parseTrackXmlFile = async (readStream) => {
|
|
|
171
193
|
};
|
|
172
194
|
|
|
173
195
|
const parseEventsXmlFile = async (readStream) => {
|
|
174
|
-
const options = {
|
|
175
|
-
attributeNamePrefix: '',
|
|
176
|
-
ignoreAttributes: false,
|
|
177
|
-
};
|
|
178
|
-
|
|
179
196
|
const buffer = await convertReadStreamToBuffer(readStream);
|
|
180
|
-
const parsed =
|
|
197
|
+
const parsed = parser.parse(buffer.toString('utf-8'));
|
|
181
198
|
|
|
182
199
|
const events = parsed.events.event || [];
|
|
183
200
|
const trackEvents = events.map((event) => ({
|
|
@@ -214,6 +231,7 @@ export const parseSkizFile = (contents, callback) => {
|
|
|
214
231
|
'Battery.csv',
|
|
215
232
|
'Events.xml',
|
|
216
233
|
'Nodes.csv',
|
|
234
|
+
'RelativeAltitudeSensor.csv',
|
|
217
235
|
'Segment.csv',
|
|
218
236
|
'Track.xml',
|
|
219
237
|
].includes(entry.fileName)
|
|
@@ -230,6 +248,8 @@ export const parseSkizFile = (contents, callback) => {
|
|
|
230
248
|
result = await parseEventsXmlFile(readStream);
|
|
231
249
|
} else if (entry.fileName === 'Nodes.csv') {
|
|
232
250
|
result = await parseNodeCsvFile(readStream);
|
|
251
|
+
} else if (entry.fileName === 'RelativeAltitudeSensor.csv') {
|
|
252
|
+
result = await parseRelativeAltitudeSensorCsvFile(readStream);
|
|
233
253
|
} else if (entry.fileName === 'Segment.csv') {
|
|
234
254
|
result = await parseSegmentCsvFile(readStream);
|
|
235
255
|
} else if (entry.fileName === 'Track.xml') {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "skiz-parser",
|
|
3
3
|
"description": "Parse a .skiz file exported from Ski Tracks",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.7.0",
|
|
5
5
|
"author": "Kirk Eaton <contact@kirkeaton.ca>",
|
|
6
6
|
"ava": {
|
|
7
7
|
"files": [
|
|
@@ -13,15 +13,17 @@
|
|
|
13
13
|
"url": "https://github.com/kirkeaton/skiz-parser/issues"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"csv-parser": "
|
|
17
|
-
"fast-xml-parser": "
|
|
18
|
-
"yauzl": "
|
|
16
|
+
"csv-parser": "3.0.0",
|
|
17
|
+
"fast-xml-parser": "4.0.1",
|
|
18
|
+
"yauzl": "2.10.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"ava": "
|
|
22
|
-
"husky": "
|
|
23
|
-
"lint-staged": "
|
|
24
|
-
"
|
|
21
|
+
"ava": "4.0.1",
|
|
22
|
+
"husky": "7.0.0",
|
|
23
|
+
"lint-staged": "12.1.4",
|
|
24
|
+
"patch-package": "6.4.7",
|
|
25
|
+
"prettier": "2.2.1",
|
|
26
|
+
"semantic-release": "19.0.2"
|
|
25
27
|
},
|
|
26
28
|
"engines": {
|
|
27
29
|
"node": ">=12"
|
|
@@ -31,11 +33,6 @@
|
|
|
31
33
|
"index.js"
|
|
32
34
|
],
|
|
33
35
|
"homepage": "https://github.com/kirkeaton/skiz-parser#readme",
|
|
34
|
-
"husky": {
|
|
35
|
-
"hooks": {
|
|
36
|
-
"pre-commit": "lint-staged"
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
36
|
"keywords": [
|
|
40
37
|
"file",
|
|
41
38
|
"parse",
|
|
@@ -62,6 +59,7 @@
|
|
|
62
59
|
"url": "git+https://github.com/kirkeaton/skiz-parser.git"
|
|
63
60
|
},
|
|
64
61
|
"scripts": {
|
|
62
|
+
"prepare": "husky install",
|
|
65
63
|
"test": "ava -v"
|
|
66
64
|
},
|
|
67
65
|
"type": "module"
|