예제 #1
0
        public static RoundPosition ParseRating(string line, DateTime roundStartTime)
        {
            var parts    = line.Split(new[] { ' ', '\t', '[', ']', 'L', 'F' }, StringSplitOptions.RemoveEmptyEntries);
            var riderId  = parts[0];
            var finished = line.StartsWith('F');

            if (parts.Length == 1)
            {
                return(RoundPosition.FromLaps(riderId, new Lap[0], false));
            }
            var lapCount = int.Parse(parts[1]);

            if (parts.Length - lapCount < 2)
            {
                throw new FormatException(
                          $"Input should be in format: <rider_number> <number_of_laps> [<lap_time1> ... <lap_time_number_of_laps]. Found lapCount={lapCount} but {parts.Length - 2} lap times");
            }

            Lap prevLap = null;
            var laps    = parts.Skip(2)
                          .Select((x, i) =>
            {
                var cp  = new Checkpoint(riderId, roundStartTime + TimeSpanExt.Parse(x));
                var l   = prevLap?.CreateNext(cp) ?? new Lap(cp, roundStartTime);
                prevLap = l;
                return(l);
            });

            return(RoundPosition.FromLaps(riderId, laps, finished));
        }
예제 #2
0
        public static Checkpoint ParseCheckpoint(string stringCp, DateTime roundStartTime)
        {
            var parts = stringCp.Split('[', ']');

            if (parts.Length > 1)
            {
                return(new Checkpoint(parts[0], roundStartTime + TimeSpanExt.Parse(parts[1])));
            }
            return(new Checkpoint(parts[0], Constants.DefaultUtcDate));
        }
예제 #3
0
        public static (DateTime roundStartTime, TimeSpan duration) ParseTrackHeader(string trackHeader)
        {
            var parts = trackHeader.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

            if (parts.Length == 2)
            {
                return(DateTime.MinValue, TimeSpanExt.Parse(parts[1]));
            }
            if (parts.Length >= 3)
            {
                return(DateTime.Parse(parts[1]), TimeSpanExt.Parse(parts[2]));
            }
            return(DateTime.MinValue, TimeSpan.Zero);
        }