From 902ae2d18c80bb49867d2b2e43fde35eb5b6f8bc Mon Sep 17 00:00:00 2001 From: Adrian Clark Date: Sun, 26 Nov 2023 14:13:32 +1000 Subject: [PATCH] Fix "Interval" on "SubsessionChartLap" I really misunderstood what the "IntervalRaw" and "IntevalUnits" properties were doing here. Makes sense now. Obvioiously sometimes your interval is in time (you are on the same lap as the leader) or your interval is in laps (you've been lapped by the leader). --- .../Package Release Notes.txt | 2 +- .../Results/SubsessionChartLap.cs | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Aydsko.iRacingData/Package Release Notes.txt b/src/Aydsko.iRacingData/Package Release Notes.txt index 1b39d81..6024930 100644 --- a/src/Aydsko.iRacingData/Package Release Notes.txt +++ b/src/Aydsko.iRacingData/Package Release Notes.txt @@ -12,7 +12,7 @@ - Check Club Image Paths (Issue: 189) - + - Fix "Interval" property on "SubsessionChartLap" so it doesn't throw an exception when driver has been lapped, which is a valid situation. Contributions: diff --git a/src/Aydsko.iRacingData/Results/SubsessionChartLap.cs b/src/Aydsko.iRacingData/Results/SubsessionChartLap.cs index 683c833..f77df7f 100644 --- a/src/Aydsko.iRacingData/Results/SubsessionChartLap.cs +++ b/src/Aydsko.iRacingData/Results/SubsessionChartLap.cs @@ -3,29 +3,29 @@ namespace Aydsko.iRacingData.Results; +/// Contains details about a particular lap for a particular driver suitable for creating a lap chart. public class SubsessionChartLap : SubsessionLap { + /// Contains the position of the car at the end of this lap. [JsonPropertyName("lap_position")] public int LapPosition { get; set; } + /// Contains the value of the interval at the end of this lap to the leader. [JsonPropertyName("interval")] public long? IntervalRaw { get; set; } + /// Describes the unit for the value. Can be either ms for milliseconds or lap if the interval is one or more laps. [JsonPropertyName("interval_units")] public string IntervalUnits { get; set; } = null!; - // If there's one thing iRacing is consistent about, it is inconsistency! - // Normally an "interval" would be in ten-thousandth's of a second (i.e. 1 minute = "600000") - // Here they have the "interval" and "interval_units". In all the results I've harvested, the units are "ms" (obviously "milliseconds") - // So we can't use the normal "JsonConverter(typeof(TenThousandthSecondDurationConverter))" on the "interval" field. + /// If is ms and is available this returns the interval to the leader. Otherwise returns . + /// There's no reasonable value that can be used to return a value here for lapped cars so if the interval is a lap count we just return . [JsonIgnore] - public TimeSpan? Interval => (IntervalRaw, IntervalUnits) switch - { - (null, _) => null, - (_, "ms") => (TimeSpan?)TimeSpan.FromMilliseconds((double)IntervalRaw), - _ => throw new NotSupportedException($"Unsupported \"IntervalUnits\" value for CustomerId \"{CustomerId}\" on lap number \"{LapNumber}\"") - }; + public TimeSpan? Interval => IntervalUnits == "ms" && IntervalRaw is not null ? TimeSpan.FromMilliseconds((double)IntervalRaw) : null; + /// + /// Indicates if this lap time was the fastest lap of the race across all drivers. + /// [JsonPropertyName("fastest_lap")] public bool FastestLap { get; set; } }