fixes an issue with data types in tcx files
This commit is contained in:
parent
602766c4a0
commit
53ddec27da
|
|
@ -21,19 +21,28 @@ function createWorkoutRecorder () {
|
||||||
if (startTime === undefined) {
|
if (startTime === undefined) {
|
||||||
startTime = new Date()
|
startTime = new Date()
|
||||||
}
|
}
|
||||||
|
// impulse recordings a currently only used to create raw data files, so we can skip it
|
||||||
|
// if raw data file creation is disabled
|
||||||
|
if (config.recordRawData) {
|
||||||
rotationImpulses.push(impulse)
|
rotationImpulses.push(impulse)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function recordStroke (stroke) {
|
function recordStroke (stroke) {
|
||||||
if (startTime === undefined) {
|
if (startTime === undefined) {
|
||||||
startTime = new Date()
|
startTime = new Date()
|
||||||
}
|
}
|
||||||
|
// stroke recordings a currently only used to create tcx files, so we can skip it
|
||||||
|
// if tcx file creation is disabled
|
||||||
|
if (config.createTcxFiles) {
|
||||||
strokes.push(stroke)
|
strokes.push(stroke)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function createTcxFile () {
|
async function createTcxFile () {
|
||||||
|
const stringifiedStartTime = startTime.toISOString().replace(/T/, '_').replace(/:/g, '-').replace(/\..+/, '')
|
||||||
const directory = `${config.dataDirectory}/recordings/${startTime.getFullYear()}/${(startTime.getMonth() + 1).toString().padStart(2, '0')}`
|
const directory = `${config.dataDirectory}/recordings/${startTime.getFullYear()}/${(startTime.getMonth() + 1).toString().padStart(2, '0')}`
|
||||||
const filename = `${directory}/${startTime.toISOString()}_rowing.tcx`
|
const filename = `${directory}/${stringifiedStartTime}_rowing.tcx`
|
||||||
log.info(`saving session as tcx file ${filename}...`)
|
log.info(`saving session as tcx file ${filename}...`)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -53,8 +62,9 @@ function createWorkoutRecorder () {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createRawDataFile () {
|
async function createRawDataFile () {
|
||||||
|
const stringifiedStartTime = startTime.toISOString().replace(/T/, '_').replace(/:/g, '-').replace(/\..+/, '')
|
||||||
const directory = `${config.dataDirectory}/recordings/${startTime.getFullYear()}/${(startTime.getMonth() + 1).toString().padStart(2, '0')}`
|
const directory = `${config.dataDirectory}/recordings/${startTime.getFullYear()}/${(startTime.getMonth() + 1).toString().padStart(2, '0')}`
|
||||||
const filename = `${directory}/${startTime.toISOString()}_raw.csv`
|
const filename = `${directory}/${stringifiedStartTime}_raw.csv`
|
||||||
log.info(`saving session as raw data file ${filename}...`)
|
log.info(`saving session as raw data file ${filename}...`)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -87,7 +97,7 @@ function createWorkoutRecorder () {
|
||||||
DistanceMeters: lastStroke.distanceTotal.toFixed(1),
|
DistanceMeters: lastStroke.distanceTotal.toFixed(1),
|
||||||
// tcx uses meters per second as unit for speed
|
// tcx uses meters per second as unit for speed
|
||||||
MaximumSpeed: (workout.strokes.map((stroke) => stroke.speed).reduce((acc, speed) => Math.max(acc, speed)) / 3.6).toFixed(2),
|
MaximumSpeed: (workout.strokes.map((stroke) => stroke.speed).reduce((acc, speed) => Math.max(acc, speed)) / 3.6).toFixed(2),
|
||||||
Calories: lastStroke.caloriesTotal.toFixed(1),
|
Calories: Math.round(lastStroke.caloriesTotal),
|
||||||
/* todo: calculate heart rate metrics...
|
/* todo: calculate heart rate metrics...
|
||||||
AverageHeartRateBpm: { Value: 76 },
|
AverageHeartRateBpm: { Value: 76 },
|
||||||
MaximumHeartRateBpm: { Value: 76 },
|
MaximumHeartRateBpm: { Value: 76 },
|
||||||
|
|
@ -105,7 +115,7 @@ function createWorkoutRecorder () {
|
||||||
const trackpoint = {
|
const trackpoint = {
|
||||||
Time: trackPointTime.toISOString(),
|
Time: trackPointTime.toISOString(),
|
||||||
DistanceMeters: stroke.distanceTotal.toFixed(2),
|
DistanceMeters: stroke.distanceTotal.toFixed(2),
|
||||||
Cadence: stroke.strokesPerMinute.toFixed(1),
|
Cadence: Math.round(stroke.strokesPerMinute),
|
||||||
Extensions: {
|
Extensions: {
|
||||||
'ns2:TPX': {
|
'ns2:TPX': {
|
||||||
// tcx uses meters per second as unit for speed
|
// tcx uses meters per second as unit for speed
|
||||||
|
|
|
||||||
|
|
@ -70,9 +70,7 @@ const gpioTimerService = fork('./app/gpio/GpioTimerService.js')
|
||||||
gpioTimerService.on('message', handleRotationImpulse)
|
gpioTimerService.on('message', handleRotationImpulse)
|
||||||
|
|
||||||
function handleRotationImpulse (dataPoint) {
|
function handleRotationImpulse (dataPoint) {
|
||||||
if (config.recordRawData) {
|
|
||||||
workoutRecorder.recordRotationImpulse(dataPoint)
|
workoutRecorder.recordRotationImpulse(dataPoint)
|
||||||
}
|
|
||||||
rowingEngine.handleRotationImpulse(dataPoint)
|
rowingEngine.handleRotationImpulse(dataPoint)
|
||||||
// fs.appendFile('recordings/WRX700_2magnets.csv', `${dataPoint}\n`, (err) => { if (err) log.error(err) })
|
// fs.appendFile('recordings/WRX700_2magnets.csv', `${dataPoint}\n`, (err) => { if (err) log.error(err) })
|
||||||
}
|
}
|
||||||
|
|
@ -89,10 +87,7 @@ rowingStatistics.on('strokeFinished', (metrics) => {
|
||||||
`, cal/hour: ${metrics.caloriesPerHour.toFixed(1)}kcal, cal/minute: ${metrics.caloriesPerMinute.toFixed(1)}kcal`)
|
`, cal/hour: ${metrics.caloriesPerHour.toFixed(1)}kcal, cal/minute: ${metrics.caloriesPerMinute.toFixed(1)}kcal`)
|
||||||
webServer.notifyClients(metrics)
|
webServer.notifyClients(metrics)
|
||||||
peripheralManager.notifyMetrics('strokeFinished', metrics)
|
peripheralManager.notifyMetrics('strokeFinished', metrics)
|
||||||
// currently recording is only used if we want to create tcx files
|
|
||||||
if (config.createTcxFiles) {
|
|
||||||
workoutRecorder.recordStroke(metrics)
|
workoutRecorder.recordStroke(metrics)
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
rowingStatistics.on('strokeStateChanged', (metrics) => {
|
rowingStatistics.on('strokeStateChanged', (metrics) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue