using System;
using ATVO.ThemesSDK;
using ATVO.ThemesSDK.Data.Results;
using ATVO.ThemeEditor.ThemeModels;
namespace Scripts
{
public class Script
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
IEntitySessionResult result = (IEntitySessionResult) value;
if (result.DidNotStart == true)
return "DNS";
if (result.Out == true)
return "DNF";
if (result.Entity.Car.Movement.IsInPits == true)
return "PIT";
if (result.Finished == true)
return "FIN";
else
return "";
}
}
}
using System;
using ATVO.ThemesSDK;
using ATVO.ThemesSDK.Data.Results;
using ATVO.ThemeEditor.ThemeModels;
namespace Scripts
{
public class Script
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
IEntitySessionResult result = (IEntitySessionResult) value;
if (result.DidNotStart == true)
return "OUT";
if (result.Out == true)
return "OUT";
if (result.Entity.Car.Movement.IsInPits == true)
return "IN PIT";
if (result.Finished == true)
return "FINISH";
if (result.Position == 1)
return "LAP " + result.CurrentLap.Number;
else
return "+" + result.LiveGap;
}
}
}
using System;
using ATVO.ThemesSDK;
using ATVO.ThemesSDK.Data.Entity;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Controls;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemesSDK.Data.Enums;
using ATVO.ThemesSDK.Data.Results;
namespace Scripts
{
public class Script : IScript
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
// Bind to "entitysessionresult_obj" to get the IEntitySessionResult as the value
// Cast to IEntitySessionResult type
IEntitySessionResult result = (IEntitySessionResult) value;
// Check DNS, Out, Pits, etc
if (result == null)
return "";
if (result.DidNotStart)
return "DNS";
if (result.Out)
return "OUT";
if (result.Entity?.Car?.Movement?.IsInPits == true)
return "IN PITS";
if (result.Finished)
return "FIN";
// If none of these are true, then show the gap
// We need the following information to determine whether to show gap or laps
var pos = result.LivePosition;
var gap = result.LiveGap;
var laps = result.LiveGapLaps;
var type = result.Session.Type;
// Optional: there is no gap for P1 so show nothing
if (pos == 1)
return "";
// If car is lapped AND this is a race session,
// then show nr of gap laps instead of gap time
if (laps > 0 && type == SessionType.Race)
{
if (laps == 1)
return "1 Lap"; // to avoid incorrect "1 Laps"
else
return laps + " Laps";
}
// If the car is in the same lap just return the time
return gap.ToString("0.000");
}
}
}
Alex McKellar wrote:Can you check with the script performance view whether it's really this script that's taking long? I can't imagine, nothing in that script should take any time at all. Note you have to enable the script benchmarking in the script properties I think.
Hi All,
I've the script in the last post by Jason. Whilst functionally it works well, I have found that when used on a ticker, it gradually grinds ATVO to a halt. It becomes unusable until I reload the theme if I can, or I have to exit and restart ATVO.
Has anyone else had this problem?
Thanks,
Alex.
using System;
using ATVO.ThemesSDK;
using ATVO.ThemesSDK.Data.Entity;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Controls;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemesSDK.Data.Enums;
using ATVO.ThemesSDK.Data.Results;
namespace Scripts
{
public class status : IScript
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
// Bind to "entitysessionresult_obj" to get the IEntitySessionResult as the value
// Cast to IEntitySessionResult type
IEntitySessionResult result = (IEntitySessionResult) value;
// We need the following information to determine whether to show gap or laps
var pos = result.LivePosition;
var gap = result.LiveGap;
var laps = result.LiveGapLaps;
var type = result.Session.Type;
// Check the session type is RACE
if (type == SessionType.Race)
{
// Check DNS, Out, Pits, etc
if (result == null)
return "";
if (result.Finished)
return "FINISHED";
if (result.DidNotStart)
return "OUT";
if (result.Out)
return "OUT";
if (result.Entity?.Car?.Movement?.IsInPits == true)
return "in Pit";
// If none of these are true, then show the gap
// Optional: there is no gap for P1 so show nothing
if (pos == 1)
return "LAP " + result.CurrentLap.Number;
// If car is lapped AND this is a race session,
// then show nr of gap laps instead of gap time
if (laps > 0 && type == SessionType.Race)
{
if (laps == 1)
return "+" + "1 Lap"; // to avoid incorrect "1 Laps"
else
return laps + "+" + " Laps";
}
// If the car is in the same lap just return the time
return "+" + gap.ToString("0.000");
}
// If the session type not RACE return LEADER for P1 and time for the rest
if (result == null)
return "no time";
if (pos == 1)
return "LEADER";
else
return "+" + gap.ToString("0.000");
}
}
}
internal static string ConvertToTimeString(this float seconds, string secFormat = "0.000", bool withMinutes = true, string prefix = "", string def = "")
{
if (seconds <= 0)
return def;
var min = 0;
float sectime;
if (withMinutes)
{
min = (int) (seconds / 60);
sectime = seconds % 60;
}
else
{
sectime = seconds;
}
var sb = new StringBuilder(prefix);
if (min > 0)
sb.Append(min).Append(':').Append(sectime.ToString("0" + secFormat));
else
sb.Append(sectime.ToString(secFormat));
return sb.ToString().Replace(',', '.');
}
Simon Grossmann wrote:This is the exact same issue I ran into with the seconds on the same lap. Thank you Simon for this snippet of code. After some tweaks I got this working with the script shown above. Thank you for "guiding" me in some way :)
This is what we use internally for custom themes to convert gaps:internal static string ConvertToTimeString(this float seconds, string secFormat = "0.000", bool withMinutes = true, string prefix = "", string def = "")
{
if (seconds <= 0)
return def;
var min = 0;
float sectime;
if (withMinutes)
{
min = (int) (seconds / 60);
sectime = seconds % 60;
}
else
{
sectime = seconds;
}
var sb = new StringBuilder(prefix);
if (min > 0)
sb.Append(min).Append(':').Append(sectime.ToString("0" + secFormat));
else
sb.Append(sectime.ToString(secFormat));
return sb.ToString().Replace(',', '.');
}
// If the car is in the same lap just return the time
return "+" + interval.ToString("0.000");
// 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 (interval > 60)
{
min = (int) (interval / 60);
sectime = interval % 60;
return "+" + min + ":" + sectime.ToString("00.000");
}
else
return "+" + interval.ToString("0.000");
Dwayne Prins wrote:Simon Grossmann wrote:This is the exact same issue I ran into with the seconds on the same lap. Thank you Simon for this snippet of code. After some tweaks I got this working with the script shown above. Thank you for "guiding" me in some way :)
This is what we use internally for custom themes to convert gaps:internal static string ConvertToTimeString(this float seconds, string secFormat = "0.000", bool withMinutes = true, string prefix = "", string def = "")
{
if (seconds <= 0)
return def;
var min = 0;
float sectime;
if (withMinutes)
{
min = (int) (seconds / 60);
sectime = seconds % 60;
}
else
{
sectime = seconds;
}
var sb = new StringBuilder(prefix);
if (min > 0)
sb.Append(min).Append(':').Append(sectime.ToString("0" + secFormat));
else
sb.Append(sectime.ToString(secFormat));
return sb.ToString().Replace(',', '.');
}
If somebody is interested, this is the part I changed:
From this:// If the car is in the same lap just return the time
return "+" + interval.ToString("0.000");
To this:// 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 (interval > 60)
{
min = (int) (interval / 60);
sectime = interval % 60;
return "+" + min + ":" + sectime.ToString("00.000");
}
else
return "+" + interval.ToString("0.000");
Alexander Kroll wrote:
Hello,
first thank you for your help in the last time.
But now i have a new problem with the format of my gaps, i hope you can help me again.
When the gap is more than 59.999 seconds i will have this format (00:00.000).
You can see my results in here:
and here is my code:using System;
using ATVO.ThemesSDK;
using ATVO.ThemesSDK.Data.Entity;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Controls;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemesSDK.Data.Enums;
using ATVO.ThemesSDK.Data.Results;
namespace Scripts
{
public class status : IScript
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
// Bind to "entitysessionresult_obj" to get the IEntitySessionResult as the value
// Cast to IEntitySessionResult type
IEntitySessionResult result = (IEntitySessionResult) value;
// We need the following information to determine whether to show gap or laps
var pos = result.LivePosition;
var gap = result.LiveGap;
var laps = result.LiveGapLaps;
var type = result.Session.Type;
// Check the session type is RACE
if (type == SessionType.Race)
{
// Check DNS, Out, Pits, etc
if (result == null)
return "";
if (result.Finished)
return "FINISHED";
if (result.DidNotStart)
return "OUT";
if (result.Out)
return "OUT";
if (result.Entity?.Car?.Movement?.IsInPits == true)
return "in Pit";
// If none of these are true, then show the gap
// Optional: there is no gap for P1 so show nothing
if (pos == 1)
return "LAP " + result.CurrentLap.Number;
// If car is lapped AND this is a race session,
// then show nr of gap laps instead of gap time
if (laps > 0 && type == SessionType.Race)
{
if (laps == 1)
return "+" + "1 Lap"; // to avoid incorrect "1 Laps"
else
return laps + "+" + " Laps";
}
// If the car is in the same lap just return the time
return "+" + gap.ToString("0.000");
}
// If the session type not RACE return LEADER for P1 and time for the rest
if (result == null)
return "no time";
if (pos == 1)
return "LEADER";
else
return "+" + gap.ToString("0.000");
}
}
}
BR Alex
internal static string ConvertToTimeString(this float seconds, string secFormat = "0.000", bool withMinutes = true, string prefix = "", string def = "")
{
if (seconds <= 0)
return def;
var min = 0;
float sectime;
if (withMinutes)
{
min = (int) (seconds / 60);
sectime = seconds % 60;
}
else
{
sectime = seconds;
}
var sb = new StringBuilder(prefix);
if (min > 0)
sb.Append(min).Append(':').Append(sectime.ToString("0" + secFormat));
else
sb.Append(sectime.ToString(secFormat));
return sb.ToString().Replace(',', '.');
min = (int) (seconds / 60);
sectime = seconds % 60;
var sb = new StringBuilder(prefix);
if (min > 0)
sb.Append(min).Append(':').Append(sectime.ToString("0" + secFormat));
else
sb.Append(sectime.ToString(secFormat));
if (result == null && type == SessionType.Race)
return "";
if (result.Entity?.Car?.Movement?.IsInPits == true && type == SessionType.Race)
return "PITS";
if (result.DidNotStart && type == SessionType.Race)
return "DNS";
if (result.Finished && type == SessionType.Race)
return "FINISH";
if (result.Out && type == SessionType.Race)
return "OUT";