-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
49 lines (46 loc) · 1.29 KB
/
index.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
let R = require('ramda')
let fs = require('fs')
let baby = require('babyparse')
let XMLWriter = require('xml-writer')
let pacerPath = __dirname + '/pacer/'
let stravaPath = __dirname + '/strava/'
let writeToXML = (fileName, data) => {
let ws = fs.createWriteStream(stravaPath+fileName+'.xml')
let xw = new XMLWriter
xw.startDocument('1.0', 'UTF-8')
xw.startElement('gpx')
xw.writeAttribute('creator', 'pacer iPhone')
xw.writeAttribute('version', '1.1')
// meta
xw.startElement('metadata')
xw.writeElement('time', (new Date(data[0][0])).toISOString())
xw.endElement('metadata')
// track
xw.startElement('trk')
xw.startElement('trkseg')
R.forEach(x=>{
if (x && x.length >= 6 ) {
xw.startElement('trkpt')
xw.writeAttribute('lat', x[2])
xw.writeAttribute('lon', x[3])
xw.writeElement('ele', 0)
xw.writeElement('time', (new Date(x[1])).toISOString())
xw.endElement('trkpt')
}
}, data)
xw.endElement('trkseg')
xw.endElement('trk')
xw.endDocument()
ws.write(xw.toString(), 'UTF-8')
ws.end()
}
R.compose(
R.map(obj => writeToXML(obj.fileName, obj.data)),
R.map(fileName => {
let parsed = baby.parseFiles(pacerPath+fileName)
return {
fileName: fileName,
data: R.drop(1, parsed.data)
}
})
)(fs.readdirSync(pacerPath))