Getting total race time from result?

Posts: 7
I am currently writing a new theme and was wanting to attempt to get the total time of the leader start to finish to display on the results page. I currently have a converter script that can return the best lap of the leader (for qualifying ticker/grid) and then returns the gap to the leader if they aren't the leader. I was trying to convert this to either show the last lap's number, or preferably the total race time of the leader.

I didn't see any intellisense for a method to return an array of all lap times from a driver, or any value of the total time. I imagine it would be costly to grab all of the laps, but it really only has to happen once, for the overall leader.


using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemesSDK.Data.Results;
using ATVO.ThemesSDK.Data.Lap;

namespace Scripts
{
public class Script : IScript
{
public object Execute(ThemeContentItem item,
object value,
string parameter,
ISimulation sim)
{
IEntitySessionResult result = (IEntitySessionResult) value;
if (result != null)
{
if (result.ClassPosition == 1)
{
var number = (ILap) result.Laps;
var lapnum = number.Number;
string str = lapnum.ToString(); //This returns a strange output, not the lap number.
return ("Lap " + str);
}
else
{
string outputStr = "DNF";
if(result.ClassGap > 0)
{
outputStr = "+" + result.ClassGap.ToString("0.000");
}
return outputStr;
}
}
else
return null;

}
}
}


So, what's the correct parameter to get the lap number from iLap, or the best way to get all laptime values out of the driver result?

Posts: 7
So, I finally got Visual Studio to understand what was happening, and it appears that Laps is actually the array of laps. Nice. I will update this with the code for both of my wishes if I get it working
Posts: 785
The Laps property should return a collection of all the laps that the car has completed. In principle you can loop over those laps and add up the "Time" property for each lap to get a total laptime. However in practice I fear this will not work very well because of several reasons, mostly:

- You must have been in the race the entire time from start to finish. If you connect halfway through a race, there is no way to obtain laptime information from laps already completed. Hence, your total laptime would only count the laps you observed, and nothing before that.
- Many times lap times return "invalid" meaning 0 seconds, for example for laps with black flags (corner cut etc) or even with incidents perhaps.

When you join a session halfway, we do add "placeholder" laps for every lap that was completed before you joined. For example, if you join in lap 18, then the Laps list will return 18 laps. However, the first 17 of them will have no laptime, because we don't know it.

You can try to get the total laptime with something as simple as this but like I said it will probably not work very well:
var totalTime = result.Laps.Sum(l => l.Time);

Edited (1 time)
Posts: 7
Nick Thissen wrote:
snip


I knew about the laps not getting saved if I wasn't in the server, but it really does suck that they get removed if they have a 1x/BF/Corner Cut. I did get this working by simply keeping a float and adding all of the laps together... shame.

I wonder if I can bug iRacing enough to expose the laps even if they are invalid, with a special format, like joker laps.

Thanks for the info Nick. It's been a great challenge to learn all of the ATVO stuff, but I'm practically done with my first fully featured overlay.
Posts: 785
If the only purpose is to get the final race time, isn't that just the finish time - green flag time? That would be much easier to calculate. You'd still need to be in the session for the whole time otherwise the green flag time is lost. I don't know if we have an easy way for you to get that time but you can at least calculate it manually using an event trigger for example.