-
Notifications
You must be signed in to change notification settings - Fork 11
Support manual entries which GPS data is in a Route #14
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,11 +137,15 @@ const template = (data, name) => { | |
<time>${new Date(data.created_at).toISOString()}</time> | ||
</metadata> | ||
<trk> | ||
<name>${dayTime} ${name}</name>${ | ||
<name>${data.notes ? data.notes : `${dayTime} ${name}`}</name>${ | ||
data.description | ||
? ` | ||
<desc>${data.description}</desc>` | ||
: '' | ||
}${ | ||
type | ||
? ` | ||
<type>${type}</type> | ||
`.trim() | ||
<type>${type}</type>` | ||
: '' | ||
} | ||
<trkseg> | ||
|
@@ -168,8 +172,12 @@ const template = (data, name) => { | |
|
||
return ` | ||
<trkpt lon="${gpsItem.longitude}" lat="${gpsItem.latitude}"> | ||
<ele>${gpsItem.altitude}</ele> | ||
<time>${new Date(gpsItem.timestamp).toISOString()}</time>${ | ||
<ele>${gpsItem.altitude}</ele>${ | ||
gpsItem.timestamp | ||
? ` | ||
<time>${new Date(gpsItem.timestamp).toISOString()}</time>` | ||
: '' | ||
}${ | ||
heartRate | ||
? ` | ||
<extensions> | ||
|
@@ -209,7 +217,7 @@ const template = (data, name) => { | |
}; | ||
|
||
const fileName = (data, name) => { | ||
const createdDate = new Date(data.created_at); | ||
const createdDate = new Date(data.start_time); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will break at other activities. Can we do it in a way to handle both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could add a condition on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's do |
||
const month = createdDate.getMonth() + 1; | ||
const day = createdDate.getDate(); | ||
|
||
|
@@ -258,6 +266,31 @@ const start = async ([exportPath, outputPath = `${process.cwd()}/export`]) => { | |
.promisify(fs.readFile)(gpsPath) | ||
.catch(console.error); | ||
} | ||
else if(item.route_id) { // if session has no GPS, check if it is attached to a route which has GPS | ||
const routePath = `${exportPath}/Routes/${item.route_id}.json`; | ||
const routeGpsPath = `${exportPath}/Routes/GPS-data/${item.route_id}.json`; | ||
|
||
// get route name and description to add to session description | ||
if (fs.existsSync(routePath)) { | ||
routeFile = await util | ||
.promisify(fs.readFile)(routePath) | ||
.catch(console.error); | ||
if (routeFile) { | ||
route = parse(routeFile); | ||
item.description = `No GPS data. Route: ${route.name} / ${route.description.replace(/\r\n/g, ' - ')}`; | ||
} | ||
} | ||
|
||
// get route GPS and add start/end timestamps | ||
if (fs.existsSync(routeGpsPath)) { | ||
gpsFile = await util | ||
.promisify(fs.readFile)(routeGpsPath) | ||
.catch(console.error); | ||
gpsFile = gpsFile.toString('utf8'); // convert to string to add start and end timestamps | ||
gpsFile = gpsFile.replace('[{', `[{"timestamp":"${new Date(item.start_time).toISOString()}",`); | ||
gpsFile = gpsFile.replace('}]', `,"timestamp":"${new Date(item.end_time).toISOString()}"}]`); | ||
} | ||
} | ||
|
||
if (fs.existsSync(heartRatePath)) { | ||
heartRateFile = await util | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably better to keep them trimmed to prevent empty lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but that also removes the starting new line, and the
<type>
tag ends up on the same line as the previous tag.I actually just "manually trimmed" the line by removing the trailing new line : end of string character is just after the closing tag
</type>
instead of being on the next line.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense now, thanks!