Lap Time Formatting Within a Script

Posts: 100
Hi all,

Does anyone know how to properly format lap times in a script?

returning the FastestLapTime binding will give 71.xxx instead of 1:11.xxx - the only way I currently know how to format any sort of label binding like this is to do FastestLapTime.ToString("0.000").

What's the proper way to do this?

Thank you!

Kyle
Posts: 785
There are several examples in various topics. The simplest/easiest one I think is quite recent: https://atvo.appgineering.com/Forum/Thread/340

I am also considering to add a built-in function for it which you can call but it will do something similar.
Posts: 61
Kyle Heyer wrote:
Hi all,

Does anyone know how to properly format lap times in a script?

returning the FastestLapTime binding will give 71.xxx instead of 1:11.xxx - the only way I currently know how to format any sort of label binding like this is to do FastestLapTime.ToString("0.000").

What's the proper way to do this?

Thank you!

Kyle
If you click the link posted by Nick, you see a script of mine where I used a function to convert the exact same thing that you are looking for:
// If the car is in the same lap just return the time
// If the car is in same lap but over a minute behind, convert total seconds to proper format
var min = 0;
float sectime;
if (gap > 60)
{
    min = (int) (gap / 60);
            sectime = gap % 60;
            return "+" + min + ":" + sectime.ToString("00.000");
}
else
return "+" + gap.ToString("0.000");


Just make sure to add it on the proper spot in your script :)
Edit: you can swap out the "gap" variables for intervals too, just make sure the variable exists in your script.
Edited (1 time)
Posts: 100
Thank you both!
Posts: 785
Next update will get two helper methods you can call in your script to format laptimes and session times:

TimeHelpers.SecondsToLaptime: converts total seconds (83.12345) to a formatted laptime (1:23.123).
TimeHelpers.SecondsToSessionTime: converts total seconds (11933.12345) to a formatted session time including hours (03:18:53).
Posts: 100
Nick Thissen wrote:
Next update will get two helper methods you can call in your script to format laptimes and session times:

TimeHelpers.SecondsToLaptime: converts total seconds (83.12345) to a formatted laptime (1:23.123).
TimeHelpers.SecondsToSessionTime: converts total seconds (11933.12345) to a formatted session time including hours (03:18:53).

Awesome! I got the previous method working but this will be nice as well. Side note, unrelated but since I have you here - I'm trying to build up a big .csv full of custom track names/short names, including columns for banking, local population, etc.

iRacing has something like 360+ track IDs - is it going to be super inefficient to attach this file and loop through all those lines to find the track ID that corresponds, or is there a better way to do this? I've been trying to use the track ID binding to reference a specific row but I'm struggling a bit.

Kyle
Posts: 785
You can add the spreadsheet to the theme, and use the spreadsheet functions to efficiently grab the row corresponding to the track. Since the track won't change you only need to do this once and you can just remember the result. But even if it was done every update, I think it's still efficient enough. Maybe thousands of rows will become a problem.

You can use the Spreadsheet.FindRow function to find any row by an identifier. By default it matches the first column but you can also specify the column index to search. You get back a DataRow object which is just a container for the column data in that row. You can then get at each column data either by its index or by its header name.

In a simple converter script you could then use the parameter to pass which column you want to display. For example, you can have a bunch of labels that all use the same converter script but pass a different parameter; one to show the banking, another to show the name, another to show the population, etc. You'd just need to know which data is in which column index (or use the header name).

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

namespace Scripts
{
public class GetTrackData : IScript
{
private DataRow _row;

public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
// On first execution, find the spreadsheet and the row corresponding to track ID
if (_row == null)
{
var sheet = item.Theme.Spreadsheets.Find("tracks.csv");
_row = sheet.FindRow(sim.Session.Track.Id.ToString());
}

if (_row != null)
{
// Take the desired column. You can pass column name or index via the parameter value.
// For example if the parameter is the index (1,2,3,4 etc)
var colIndex = int.Parse(parameter);
return _row[colIndex];
}
return "";
}
}
}


Use this script as a converter for any label. Note that the actual data binding you use is irrelevant here (it's not used), but you still need to pick one (anything) otherwise the script isn't called.
Posts: 100
Nick Thissen wrote:
You can add the spreadsheet to the theme, and use the spreadsheet functions to efficiently grab the row corresponding to the track. Since the track won't change you only need to do this once and you can just remember the result. But even if it was done every update, I think it's still efficient enough. Maybe thousands of rows will become a problem.

You can use the Spreadsheet.FindRow function to find any row by an identifier. By default it matches the first column but you can also specify the column index to search. You get back a DataRow object which is just a container for the column data in that row. You can then get at each column data either by its index or by its header name.

In a simple converter script you could then use the parameter to pass which column you want to display. For example, you can have a bunch of labels that all use the same converter script but pass a different parameter; one to show the banking, another to show the name, another to show the population, etc. You'd just need to know which data is in which column index (or use the header name).

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

namespace Scripts
{
public class GetTrackData : IScript
{
private DataRow _row;

public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
// On first execution, find the spreadsheet and the row corresponding to track ID
if (_row == null)
{
var sheet = item.Theme.Spreadsheets.Find("tracks.csv");
_row = sheet.FindRow(sim.Session.Track.Id.ToString());
}

if (_row != null)
{
// Take the desired column. You can pass column name or index via the parameter value.
// For example if the parameter is the index (1,2,3,4 etc)
var colIndex = int.Parse(parameter);
return _row[colIndex];
}
return "";
}
}
}


Use this script as a converter for any label. Note that the actual data binding you use is irrelevant here (it's not used), but you still need to pick one (anything) otherwise the script isn't called.


Much appreciated. I had things almost working but it was the column index thing I couldn't figure out. I haven't really messed with different parameter outputs in a script, usually just have one value I'm looking for, so this is great!

Kyle