skiz-parser 4.1.0 → 4.2.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.d.ts +1 -1
- package/index.js +90 -68
- package/package.json +9 -9
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { parse as CSVParser } from 'csv-parse';
|
|
2
2
|
import { XMLParser } from 'fast-xml-parser';
|
|
3
3
|
import yauzl from 'yauzl';
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const xmlParserOptions = {
|
|
6
6
|
attributeNamePrefix: '',
|
|
7
7
|
ignoreAttributes: false,
|
|
8
|
-
}
|
|
8
|
+
};
|
|
9
9
|
|
|
10
10
|
const convertReadStreamToBuffer = (readStream) => {
|
|
11
11
|
return new Promise((resolve, reject) => {
|
|
@@ -31,69 +31,84 @@ const openReadStream = (zipFile, entry) => {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
const parseBatteryCsvFile = (readStream) => {
|
|
34
|
+
const parser = CSVParser();
|
|
35
|
+
|
|
34
36
|
return new Promise((resolve, reject) => {
|
|
35
37
|
const batteryUsage = [];
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
.pipe(csv({ headers: false }))
|
|
39
|
+
parser
|
|
39
40
|
.on('error', reject)
|
|
40
|
-
.on('
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
.on('readable', () => {
|
|
42
|
+
let record;
|
|
43
|
+
|
|
44
|
+
while ((record = parser.read()) !== null) {
|
|
45
|
+
batteryUsage.push({
|
|
46
|
+
timestamp: new Date(record[0]),
|
|
47
|
+
status: record[1],
|
|
48
|
+
level: parseFloat(record[2]),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
48
51
|
})
|
|
49
52
|
.once('end', () => {
|
|
50
53
|
resolve({ batteryUsage });
|
|
51
54
|
});
|
|
55
|
+
|
|
56
|
+
readStream.pipe(parser);
|
|
52
57
|
});
|
|
53
58
|
};
|
|
54
59
|
|
|
55
60
|
const parseNodeCsvFile = (readStream) => {
|
|
61
|
+
const parser = CSVParser();
|
|
62
|
+
|
|
56
63
|
return new Promise((resolve, reject) => {
|
|
57
64
|
const trackNodes = [];
|
|
58
65
|
|
|
59
|
-
|
|
60
|
-
.pipe(csv({ headers: false }))
|
|
66
|
+
parser
|
|
61
67
|
.on('error', reject)
|
|
62
|
-
.on('
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
.on('readable', () => {
|
|
69
|
+
let record;
|
|
70
|
+
|
|
71
|
+
while ((record = parser.read()) !== null) {
|
|
72
|
+
trackNodes.push({
|
|
73
|
+
timestamp: new Date(parseFloat(record[0]) * 1000.0),
|
|
74
|
+
latitude: parseFloat(record[1]),
|
|
75
|
+
longitude: parseFloat(record[2]),
|
|
76
|
+
altitude: parseFloat(record[3]),
|
|
77
|
+
heading: parseFloat(record[4]),
|
|
78
|
+
velocity: parseFloat(record[5]),
|
|
79
|
+
hAccuracy: parseFloat(record[6]),
|
|
80
|
+
vAccuracy: parseFloat(record[7]),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
75
83
|
})
|
|
76
84
|
.once('end', () => {
|
|
77
85
|
resolve({ trackNodes });
|
|
78
86
|
});
|
|
87
|
+
|
|
88
|
+
readStream.pipe(parser);
|
|
79
89
|
});
|
|
80
90
|
};
|
|
81
91
|
|
|
82
92
|
const parseRelativeAltitudeSensorCsvFile = (readStream) => {
|
|
93
|
+
const parser = CSVParser();
|
|
94
|
+
|
|
83
95
|
return new Promise((resolve, reject) => {
|
|
84
96
|
const relativeAltitude = [];
|
|
85
97
|
|
|
86
|
-
readStream
|
|
87
|
-
.pipe(csv({ headers: false }))
|
|
88
|
-
.on('error', reject)
|
|
89
|
-
.on('data', (data) => {
|
|
90
|
-
const values = Object.values(data);
|
|
98
|
+
readStream.pipe(parser);
|
|
91
99
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
parser
|
|
101
|
+
.on('error', reject)
|
|
102
|
+
.on('readable', (data) => {
|
|
103
|
+
let record;
|
|
104
|
+
|
|
105
|
+
while ((record = parser.read()) !== null) {
|
|
106
|
+
relativeAltitude.push({
|
|
107
|
+
timestamp: new Date(record[0]),
|
|
108
|
+
pressure: parseFloat(record[1]),
|
|
109
|
+
relativeAltitude: parseFloat(record[2]),
|
|
110
|
+
});
|
|
111
|
+
}
|
|
97
112
|
})
|
|
98
113
|
.once('end', () => {
|
|
99
114
|
resolve({ relativeAltitude });
|
|
@@ -102,48 +117,54 @@ const parseRelativeAltitudeSensorCsvFile = (readStream) => {
|
|
|
102
117
|
};
|
|
103
118
|
|
|
104
119
|
const parseSegmentCsvFile = (readStream) => {
|
|
120
|
+
const parser = CSVParser({ fromLine: 2 });
|
|
121
|
+
|
|
105
122
|
return new Promise((resolve, reject) => {
|
|
106
123
|
const trackSegments = [];
|
|
107
124
|
|
|
108
|
-
|
|
109
|
-
.pipe(csv({ headers: false, skipLines: 1 }))
|
|
125
|
+
parser
|
|
110
126
|
.on('error', reject)
|
|
111
|
-
.on('
|
|
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
|
-
|
|
127
|
+
.on('readable', () => {
|
|
128
|
+
let record;
|
|
129
|
+
|
|
130
|
+
while ((record = parser.read()) !== null) {
|
|
131
|
+
trackSegments.push({
|
|
132
|
+
startTime: new Date(parseFloat(record[0]) * 1000),
|
|
133
|
+
endTime: new Date(parseFloat(record[1]) * 1000),
|
|
134
|
+
number: parseInt(record[4], 10),
|
|
135
|
+
name: record[5],
|
|
136
|
+
comment: record[6],
|
|
137
|
+
type: record[7],
|
|
138
|
+
category: record[8],
|
|
139
|
+
link: record[9],
|
|
140
|
+
uuid: record[10],
|
|
141
|
+
metrics: {
|
|
142
|
+
time: parseFloat(record[11]),
|
|
143
|
+
speed: parseFloat(record[12]),
|
|
144
|
+
distance: parseFloat(record[13]),
|
|
145
|
+
vertical: parseFloat(record[14]),
|
|
146
|
+
maxSpeed: parseFloat(record[15]),
|
|
147
|
+
slope: parseFloat(record[16]),
|
|
148
|
+
maxSlope: parseFloat(record[17]),
|
|
149
|
+
minAltitude: parseFloat(record[18]),
|
|
150
|
+
maxAltitude: parseFloat(record[19]),
|
|
151
|
+
startAltitude: parseFloat(record[20]),
|
|
152
|
+
finishAltitude: parseFloat(record[21]),
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
}
|
|
138
156
|
})
|
|
139
157
|
.once('end', () => {
|
|
140
158
|
resolve({ trackSegments });
|
|
141
159
|
});
|
|
160
|
+
|
|
161
|
+
readStream.pipe(parser);
|
|
142
162
|
});
|
|
143
163
|
};
|
|
144
164
|
|
|
145
165
|
const parseTrackXmlFile = async (readStream) => {
|
|
146
166
|
const buffer = await convertReadStreamToBuffer(readStream);
|
|
167
|
+
const parser = new XMLParser(xmlParserOptions);
|
|
147
168
|
const parsed = parser.parse(buffer.toString('utf-8'));
|
|
148
169
|
|
|
149
170
|
const track = parsed.track;
|
|
@@ -201,6 +222,7 @@ const parseTrackXmlFile = async (readStream) => {
|
|
|
201
222
|
|
|
202
223
|
const parseEventsXmlFile = async (readStream) => {
|
|
203
224
|
const buffer = await convertReadStreamToBuffer(readStream);
|
|
225
|
+
const parser = new XMLParser(xmlParserOptions);
|
|
204
226
|
const parsed = parser.parse(buffer.toString('utf-8'));
|
|
205
227
|
|
|
206
228
|
const events = parsed.events.event || [];
|
|
@@ -272,6 +294,6 @@ export const parseSkizFile = (contents, callback) => {
|
|
|
272
294
|
};
|
|
273
295
|
|
|
274
296
|
return typeof callback === 'function'
|
|
275
|
-
? parse(callback.bind(null,
|
|
297
|
+
? parse(callback.bind(null, null), callback)
|
|
276
298
|
: new Promise(parse);
|
|
277
299
|
};
|
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "skiz-parser",
|
|
3
3
|
"description": "Parse a .skiz file exported from Ski Tracks",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.2.0",
|
|
5
5
|
"author": "Kirk Eaton <contact@kirkeaton.ca>",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/kirkeaton/skiz-parser/issues"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"csv-
|
|
11
|
-
"fast-xml-parser": "4.
|
|
10
|
+
"csv-parse": "5.5.6",
|
|
11
|
+
"fast-xml-parser": "4.4.0",
|
|
12
12
|
"yauzl": "3.1.3"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@kirkeaton/prettier-config": "1.0.2",
|
|
16
|
-
"@kirkeaton/semantic-release-config": "1.0.
|
|
17
|
-
"@types/node": "20.
|
|
18
|
-
"prettier": "3.2
|
|
19
|
-
"semantic-release": "
|
|
20
|
-
"tsd": "0.31.
|
|
16
|
+
"@kirkeaton/semantic-release-config": "1.0.1",
|
|
17
|
+
"@types/node": "20.14.9",
|
|
18
|
+
"prettier": "3.3.2",
|
|
19
|
+
"semantic-release": "24.0.0",
|
|
20
|
+
"tsd": "0.31.1"
|
|
21
21
|
},
|
|
22
22
|
"engines": {
|
|
23
23
|
"node": ">=18"
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"skiz"
|
|
39
39
|
],
|
|
40
40
|
"license": "BSD-3-Clause",
|
|
41
|
-
"packageManager": "pnpm@9.0
|
|
41
|
+
"packageManager": "pnpm@9.4.0",
|
|
42
42
|
"repository": {
|
|
43
43
|
"type": "git",
|
|
44
44
|
"url": "git+https://github.com/kirkeaton/skiz-parser.git"
|