Skip to content

Commit

Permalink
First Switch to timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
JaapvanEkris authored Dec 20, 2024
1 parent fdba20f commit 9b2d2cc
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions app/recorders/tcxRecorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ export function createTCXRecorder (config) {
let intervalEndMetrics
switch (true) {
case (metrics.metricsContext.isSessionStart):
sessionData = { startTime: currentTime }
sessionData = { startTime: metrics.timestamp }
sessionData.lap = []
lapnumber = 0
sessionData.lap[lapnumber] = { startTime: currentTime }
sessionData.lap[lapnumber] = { startTime: metrics.timestamp }
sessionData.lap[lapnumber].strokes = []
addMetricsToStrokesArray(metrics)
break
Expand All @@ -106,24 +106,23 @@ export function createTCXRecorder (config) {
break
case (metrics.metricsContext.isPauseEnd):
lapnumber++
sessionData.lap[lapnumber] = { startTime: currentTime }
sessionData.lap[lapnumber] = { startTime: metrics.timestamp }
sessionData.lap[lapnumber].strokes = []
addMetricsToStrokesArray(metrics)
break
case (metrics.metricsContext.isIntervalStart):
// Please note: we deliberatly add the metrics twice as it marks both the end of the old interval and the start of a new one
updateLapMetrics(metrics)
intervalEndMetrics = { ...metrics }
// ToDo: check if next line is needed
intervalEndMetrics.intervalAndPauseMovingTime = metrics.totalMovingTime - sessionData.lap[lapnumber].strokes[0].totalMovingTime
addMetricsToStrokesArray(intervalEndMetrics)
calculateLapMetrics(metrics)
powerSeries.reset()
speedSeries.reset()
heartrateSeries.reset()
lapnumber++
// We need to calculate the start time of the interval, as delay in message handling can cause weird effects here
startTime = new Date(sessionData.lap[lapnumber - 1].startTime.getTime() + intervalEndMetrics.intervalAndPauseMovingTime * 1000)
sessionData.lap[lapnumber] = { startTime }
sessionData.lap[lapnumber] = { startTime: metrics.timestamp }
sessionData.lap[lapnumber].strokes = []
addMetricsToStrokesArray(metrics)
break
Expand Down Expand Up @@ -252,7 +251,7 @@ export function createTCXRecorder (config) {
// Add the strokes
let i = 0
while (i < lapdata.strokes.length) {
tcxData += await createTrackPoint(lapdata.startTime, lapdata.strokes[i])
tcxData += await createTrackPoint(lapdata.strokes[i])
i++
}
tcxData += ' </Track>\n'
Expand All @@ -268,12 +267,10 @@ export function createTCXRecorder (config) {
return tcxData
}

async function createTrackPoint (offset, trackpoint) {
const trackPointTime = new Date(offset.getTime() + trackpoint.intervalAndPauseMovingTime * 1000)

async function createTrackPoint (trackpoint) {
let tcxData = ''
tcxData += ' <Trackpoint>\n'
tcxData += ` <Time>${trackPointTime.toISOString()}</Time>\n`
tcxData += ` <Time>${trackpoint.timestamp.toISOString()}</Time>\n`
tcxData += ` <DistanceMeters>${trackpoint.totalLinearDistance.toFixed(2)}</DistanceMeters>\n`
tcxData += ` <Cadence>${(trackpoint.cycleStrokeRate > 0 ? Math.round(trackpoint.cycleStrokeRate) : 0)}</Cadence>\n`
if (trackpoint.cycleLinearVelocity > 0 || trackpoint.cyclePower > 0 || trackpoint.metricsContext.isPauseStart) {
Expand Down

0 comments on commit 9b2d2cc

Please sign in to comment.