Пример #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 void Laps_with_timestamps()
        {
            var cp = new Checkpoint("11", new DateTime(2000));
            var l  = new Lap(cp, new DateTime(1000));

            l.SequentialNumber.Should().Be(1);
            l.Start.Should().Be(new DateTime(1000));
            l.End.Should().Be(new DateTime(2000));
            l.Duration.Should().Be(TimeSpan.FromTicks(1000));
            l.AggDuration.Should().Be(TimeSpan.FromTicks(1000));
            l.Checkpoint.Should().BeSameAs(cp);

            var cp2 = new Checkpoint("11", new DateTime(3500));
            var l2  = l.CreateNext(cp2);

            l2.SequentialNumber.Should().Be(2);
            l2.Start.Should().Be(new DateTime(2000));
            l2.End.Should().Be(new DateTime(3500));
            l2.Duration.Should().Be(TimeSpan.FromTicks(1500));
            l2.AggDuration.Should().Be(TimeSpan.FromTicks(2500));
            l2.Checkpoint.Should().BeSameAs(cp2);
        }