Average Lap Time Fu...
 
Notifications
Clear all

Average Lap Time Function

1 Posts
1 Users
0 Reactions
556 Views
(@terrya)
Active Member
Joined: 1 year ago
Posts: 3
Topic starter  

function taAverageLapTime()
{
// Function to calculate and return your Average Lap Time
// Terry Abbott - 2023.11.05
// UPDATED 2023.11.09 to account for a 'bad' lap (off track)
// 2023.11.20 tweaks
// 2023.11.24 major changes to account for lastlaptime data
// not available until after the lap counter
// changes.

// The 'visible' property MUST ALWAYS BE KEEP to true for this code to
// work correctly. The 'visible' property is really a 'run me,'
// 'don't run be' open. If you don't want to see 0s for the first lap,
// create a filled rectangle over the numbers and set its visible option
// dependent on 'CurrentLap' > 1

// temporary timer variables
var Ta01CurrentLap = 0;
var Ta01Anumber = 0;
var Ta01LapTime = 0;
var Ta01RtTime = 0;
var t = 0;

// initialize root variables
if (root.taSaveLapNum == null)
{
// the saved lap number for the current lap
root.taSaveLapNum = 0;

root.taLapAvg = 0.0;

root.taLapRunningTime = 0.0;

root.taCount1 = 0;

root.DelayTime = 0;
}

Ta01CurrentLap = $prop('CurrentLap');

Ta01LapRt = timespantoseconds($prop('CurrentLapTime'));

// force a reset
if (root.taSaveLapNum > Ta01CurrentLap)
{
root.taSaveLapNum = 0;

root.taLapAvg = 0;

root.taLapRunningTime = 0.0;

root.DelayTime = 0;
}

// if no lap number change, update the running time
else if (root.taSaveLapNum == Ta01CurrentLap)
{
root.taLapRunningTime = timespantoseconds($prop('CurrentLapTime'));

root.DelayTime = taGetDecimalTime();
}

// the lap number did increment
else if ((root.taSaveLapNum < Ta01CurrentLap) &&
((taGetDecimalTime() - 2) > root.DelayTime))
{
root.taSaveLapNum = Ta01CurrentLap;

root.taCount1 = root.taCount1 + 1;

// start once we've finished the first lap

if (Ta01CurrentLap > 1)
{
// if the LastLapTime is bad, use the previous running
// lap value

t = timespantoseconds($prop('LastLapTime'));

if (t > 0)
{
Ta01RtTime = t;
}
else
{
Ta01RtTime = root.taLapRunningTime;
}

if (Ta01CurrentLap == 2)
{
Ta01LapTime = Ta01RtTime;
}
else
{
Ta01Anumber = Ta01CurrentLap - 1;

Ta01LapTime = (((Ta01Anumber - 1.0)/Ta01Anumber)*root.taLapAvg) +
(1.0/Ta01Anumber)*Ta01RtTime;
}

// reset the running time
root.taLapRunningTime = 0.0;

root.taLapAvg = Ta01LapTime;
}
}

// format output as m\:ss\.ff

return secondstotimespan(root.taLapAvg);
}


   
Quote
Share: