Skip to content

Commit

Permalink
get more data from ibt file
Browse files Browse the repository at this point in the history
  • Loading branch information
twitchyvr committed Nov 19, 2023
1 parent ad54295 commit 77eaad3
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ module.exports = async function (context, req) {
// Process telemetry
const telemetry = new Telemetry(telemetryData)

console.log('Telemetry headers:', telemetry.headers)
console.log(telemetry.header)
// console.log('Telemetry headers:', telemetry.headers)
// console.log(telemetry.header)

/**
// Example: Create a summary or extract specific data from telemetry
const telemetrySummary = {
uniqueId: telemetry.uniqueId(),
Expand All @@ -25,6 +26,17 @@ module.exports = async function (context, req) {
telemetryData: telemetry.data
// Add other telemetry properties or summaries here
}
*/

const telemetrySummary = {
uniqueId: telemetry.uniqueId(),
header: telemetry.headers, // Assuming this contains the parsed header data
sessionInfo: telemetry.sessionInfo, // Contains the parsed YAML session info
varHeaders: telemetry.varHeaders(), // Assuming this method returns the variable headers
// Add a method to extract summarized telemetry data
telemetryData: telemetry.getTelemetryDataSummary()
// You can add more methods as needed to extract different parts of the telemetry data
}

// Response
context.res = {
Expand Down
48 changes: 48 additions & 0 deletions src/telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,54 @@ class Telemetry {
return this.sessionInfo.WeekendInfo.SessionType || 'Unknown Session Type'
}

getTelemetryDataSummary () {
let totalSpeed = 0
let maxRpm = 0
let totalLaps = 0
let bestLapTime = Number.MAX_VALUE
const lapTimes = []
let highestSpeed = 0
let totalBrakePressure = 0
let totalThrottle = 0
let sampleCount = 0

for (const sample of this.samples()) {
totalSpeed += sample.speed
maxRpm = Math.max(maxRpm, sample.rpm)
highestSpeed = Math.max(highestSpeed, sample.speed)
totalBrakePressure += sample.brakePressure
totalThrottle += sample.throttle
sampleCount++

// Assuming sample.lapTime and sample.lapNumber are available
if (sample.lapTime < bestLapTime) {
bestLapTime = sample.lapTime
}
if (!lapTimes[sample.lapNumber]) {
lapTimes[sample.lapNumber] = []
}
lapTimes[sample.lapNumber].push(sample.lapTime)
}

totalLaps = lapTimes.length

// Calculate averages
const avgSpeed = totalSpeed / sampleCount
const avgBrakePressure = totalBrakePressure / sampleCount
const avgThrottle = totalThrottle / sampleCount

return {
averageSpeed: avgSpeed,
maxRPM: maxRpm,
totalLaps,
bestLapTime,
highestSpeed,
averageBrakePressure: avgBrakePressure,
averageThrottle: avgThrottle,
lapTimes: lapTimes.map(lap => lap.reduce((a, b) => a + b, 0) / lap.length)
}
}

/**
* Telemetry samples generator.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/utils/telemetry-file-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ readFileToBuffer(fd, telemetryHeader.sessionInfoOffset, telemetryHeader.sessionI
const sessionInfoStringFromFileDescriptor = (fd, telemetryHeader) => {
return readFileToBuffer(fd, telemetryHeader.sessionInfoOffset, telemetryHeader.sessionInfoLength)
.then(buffer => {
return buffer.toString('utf8') // encode as utf-8
return buffer.toString('ascii') // encode as ascii
})
}

Expand Down

0 comments on commit 77eaad3

Please sign in to comment.