Browse Source

fix more 'tude.

meyn 0.1.4
Gisle Aune 9 months ago
parent
commit
239db9758d
  1. 17
      lib/tcx.mjs

17
lib/tcx.mjs

@ -26,8 +26,8 @@ export function generateTrimlogInput(filename, name = "Walk", type = "walk") {
time: tp.Time[0], time: tp.Time[0],
longitude: parseFloat(tp.Position?.[0]?.LongitudeDegrees[0]), longitude: parseFloat(tp.Position?.[0]?.LongitudeDegrees[0]),
latitude: parseFloat(tp.Position?.[0]?.LatitudeDegrees[0]), latitude: parseFloat(tp.Position?.[0]?.LatitudeDegrees[0]),
altitude: parseFloat(tp.AltitudeMeters[0]),
distance: parseFloat(tp.DistanceMeters[0]),
altitude: parseFloat(tp.AltitudeMeters?.[0]),
distance: parseFloat(tp.DistanceMeters?.[0]),
pulse: parseFloat(tp.HeartRateBpm?.[0].Value?.[0]), pulse: parseFloat(tp.HeartRateBpm?.[0].Value?.[0]),
}; };
@ -42,6 +42,11 @@ export function generateTrimlogInput(filename, name = "Walk", type = "walk") {
} }
} }
const list = Object.keys(map).sort().map(k => map[k]);
const firstLon = list.find(e => !!e.longitude)?.longitude;
const firstLat = list.find(e => !!e.latitude)?.latitude;
const firstAlt = list.find(e => !!e.altitude)?.altitude;
const out = { const out = {
date: dateStr, date: dateStr,
contents: [{rawActivity: { contents: [{rawActivity: {
@ -49,13 +54,13 @@ export function generateTrimlogInput(filename, name = "Walk", type = "walk") {
sets: [], sets: [],
effortScale: 1, effortScale: 1,
weight: 0, weight: 0,
measurements: Object.keys(map).sort().map(k => map[k]).map(p => ({
measurements: list.map(p => ({
seconds: Math.round((new Date(p.time) - date) / 1000), seconds: Math.round((new Date(p.time) - date) / 1000),
meters: p.distance, meters: p.distance,
pulse: p.pulse, pulse: p.pulse,
longitude: p.longitude,
latitude: p.latitude,
altitude: p.altitude,
longitude: p.longitude || firstLon,
latitude: p.latitude || firstLat,
altitude: p.altitude || firstAlt,
})) }))
}}], }}],
description: name, description: name,

Loading…
Cancel
Save