The simplest way to show laptimes is to use the "laptimes" dataset. It will return the laptimes of the currently followed / focused driver, starting with the most recent and counting down. You can use a static ticker with 4 items to show the last 4 laps.
I don't believe we offer a ready-made average laptime binding. To get that you would need a script to grab the laps you want and average them yourself. In principle we can add average laptimes but then there are many questions to answer and not everyone may want the same thing (e.g. how many laps to average? How do you handle invalid laps? etc).
A relatively simple script could take as input an "entitysessionresult_object" and go through the Laps list of the result, taking only valid laps and calculating their average:
using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemesSDK.Data.Results;
using System.Collections.Generic;
using System.Linq;
namespace Scripts
{
public class AverageLaptime : IScript
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
var result = (IEntitySessionResult)value;
var lastLapIndex = result.Laps.Count - 1;
var laptimes = new List<float>();
// Loop backwards 4 laps starting from the most recent lap
for (int i = lastLapIndex; i <= lastLapIndex - 4; i--)
{
// Stop if we reached the first lap
if (i < 0)
break;
var lap = result.Laps[i];
if (lap.Time > 0) // invalid laps have -1 laptime
{
laptimes.Add(lap.Time);
}
}
// Calculate the average over the valid laps
var averageLaptime = laptimes.Average();
return averageLaptime.ToString();
}
}
}
You can adapt this depending on your needs, for example how to handle invalid laps etc.
Or if you prefer a bit shorter notation:
var averageLaptime = result.Laps // Laps list of this result
.Select(l => l.Time) // Select the laptime
.Reverse() // Reverse so we start at the last lap
.Where(t => t > 0) // Take only valid laps where the time > 0
.Take(4) // Take up to 4 laps
.Average(); // Average
return averageLaptime.ToString();