private DisplayItemWithLap <int> GetMaxGainPerLap(RaceLap lap)
            {
                DisplayItemWithLap <int>?ret = null;
                int nextPos = lap.CurrentPosition;

                lap = lap.PreviousLap as RaceLap;
                while (lap != null)
                {
                    int diff = lap.CurrentPosition - nextPos;
                    if (ret == null || ret.Value.Item <= diff)
                    {
                        ret = new DisplayItemWithLap <int>(diff, lap.LapNumber);
                    }

                    nextPos = lap.CurrentPosition;
                    lap     = lap.PreviousLap as RaceLap;
                }

                if (ret == null)
                {
                    return(new DisplayItemWithLap <int>());
                }
                else
                {
                    return(ret.Value);
                }
            }
            private DisplayItemWithLap <Time> GetBestTime(RaceLap lap)
            {
                var retLap = lap.GetThrough(i => i.BetterLap);

                DisplayItemWithLap <Time> ret = new DisplayItemWithLap <Time>(retLap.Time, retLap.LapNumber);

                return(ret);
            }
        private static RaceLap AddRaceLap(Race race, string lapLine, int lapIndex, DateTime started)
        {
            int timeOffset;

            switch ((Lane)race.Lane)
            {
            case Lane.Inner:
                timeOffset = 17;
                break;

            case Lane.Outer:
                timeOffset = 52;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            TimeSpan time;

            if (!TimeSpan.TryParseExact(lapLine.Substring(timeOffset, 10), @"mm\:ss\.ffff", CultureInfo, out time))
            {
                return(null);
            }

            if (time == TimeSpan.Zero)
            {
                return(null);
            }

            var lap = new RaceLap
            {
                Race                  = race,
                InstanceName          = ResultInstanceName,
                ApplianceInstanceName = "",
                ApplianceName         = "",
                How        = "Optical",
                Flags      = RaceEventFlags.Present,
                Time       = time,
                When       = started + time,
                FixedIndex = lapIndex
            };

            if (race.Laps == null)
            {
                race.Laps = new Collection <RaceLap>();
            }
            race.Laps.Add(lap);

            return(lap);
        }
            private int GetLapsInLead(RaceLap lap)
            {
                int ret = 0;

                while (lap != null)
                {
                    if (lap.CurrentPosition == 1)
                    {
                        ret++;
                    }
                    lap = (RaceLap)lap.PreviousLap;
                }

                return(ret);
            }
            private int GetBestPositionSoFar(RaceLap lap)
            {
                int ret = int.MaxValue;

                while (lap != null)
                {
                    if (lap.CurrentPosition < ret)
                    {
                        ret = lap.CurrentPosition;
                    }

                    lap = (RaceLap)lap.PreviousLap;
                }

                return(ret);
            }
Exemplo n.º 6
0
        private static int GetRacePoints(RaceLap item, AbstractScoring scoring, Dictionary <Driver, TempData> tmp)
        {
            int ret = 0;

            ret = scoring.GetPositionPoints(item.CurrentPosition);

            if (scoring.AtLeastOneLapLeaderPoints > 0)
            {
                if (item.Exists(
                        i => i.CurrentPosition == 1,
                        i => (i.PreviousLap as RaceLap)))
                {
                    ret += scoring.AtLeastOneLapLeaderPoints;
                }
            }

            if (scoring.MostLapLeaderPoints > 0)
            {
                if (tmp[tmp.Keys.First()].LapsInLead == tmp[item.Driver].LapsInLead)
                {
                    ret += scoring.MostLapLeaderPoints;
                }
            }

            if (scoring.QualifyWinnerPoints > 0)
            {
                if (tmp[item.Driver].QualifyPosition == 1)
                {
                    ret += scoring.QualifyWinnerPoints;
                }
            }

            if (scoring.RaceWinnerExtraPoints > 0)
            {
                if (item.CurrentPosition == 1)
                {
                    ret += scoring.RaceWinnerExtraPoints;
                }
            }

            return(ret);
        }
            public Item(List <RaceLap> laps, int i, RacePit [] pits, RaceSession rs)
            {
                RaceLap lap = laps[i];

                pits = pits.Where(k => k.LapNumber <= lap.LapNumber).ToArray();

                this.Driver   = lap.Driver.NameSurname;
                this.Number   = lap.Driver.Number;
                this.Position = lap.CurrentPosition;
                if (i == 0)
                {
                    this.GapToFirst    = RaceGap.Empty;
                    this.GapToPrevious = RaceGap.Empty;
                }
                else
                {
                    RaceLap prev = laps[i - 1];
                    this.GapToFirst    = new RaceGap(laps[0], lap);
                    this.GapToPrevious = new RaceGap(laps[i - 1], lap);
                }
                this.LapCount       = lap.LapNumber;
                this.State          = rs.Positions.GetDriverFinalStatus(lap.Driver).ToString();
                this.LapsInLead     = GetLapsInLead(lap);
                this.PitCount       = pits.Length;
                this.BestTime       = GetBestTime(lap);
                this.MeanTime       = GetMeanTime(lap);
                this.MeanTimePY     = GetMeanTimePY(lap);
                this.WorstTime      = GetWorstTime(lap);
                this.BestPitTime    = GetBestPitTime(pits);
                this.MeanPitTime    = GetMeanPitTime(pits);
                this.WorstPitTime   = GetWorstPitTime(pits);
                this.BestPosition   = GetBestPositionSoFar(lap);
                this.WorstPosition  = GetWorstPositionSoFar(lap);
                this.PitInLaps      = GetPitLapsAsString(pits);
                this.MaxGainPerLap  = GetMaxGainPerLap(lap);
                this.MaxLoosePerLap = GetMaxLoosePerLap(lap);

                this.BlackFlags =
                    lap.Sum(k => k.IsBlackFlagged ? 1 : 0, k => k.PreviousLapAsRaceLap);
            }
Exemplo n.º 8
0
        public void Fill(RaceSession session, LapCrossing te)
        {
            int carIdx = te.CarIdx;

            if (session.Weekend.Drivers.ContainsKey(carIdx) == false)
            {
                throw new ApplicationException("Failed to find driver with carIdx " + carIdx + " in registered drivers of weekend.");
            }
            Driver d = session.Weekend.Drivers[carIdx];

            RaceLap l = new RaceLap();

            l.Driver        = d;
            l.CrossedAtTime = Time.CreateFromSeconds(te.CrossedAt);
            if (l.CrossedAtTime.TotalMiliseconds < 0)
            {
                throw new ApplicationException("CrossedAt below zero.");
            }
            l.IsBlackFlagged = te.IsBlackFlagged;
            l.IsOffTrack     = te.IsOffTrack;
            l.IsPitted       = te.IsPitted;

            session.Laps.Add(l);
        }
Exemplo n.º 9
0
        private static void UpdateNewDriverStandingsByNewRace(WeekendInfo previous, WeekendInfo current, AbstractScoring scoring, Weekend weekend, RaceSession race, Dictionary <Driver, TempData> tmp, RaceLap item)
        {
            DriverStandings prevDs = null;

            if (previous != null)
            {
                prevDs = previous.Standings[item.Driver];
            }
            if (current.Standings[item.Driver] == null)
            {
                current.Standings.Add(new DriverStandings()
                {
                    Driver = item.Driver
                });
            }
            DriverStandings newDs = current.Standings[item.Driver];

            int racePoints = GetRacePoints(item, scoring, tmp);

            weekend.Points.Add(item.Driver, racePoints);

            newDs.PointsM.Add(racePoints);

            newDs.BlackFlagsMean.Add(item.Sum(
                                         i => i.IsBlackFlagged ? 1 : 0,
                                         i => i.PreviousLapAsRaceLap
                                         ));

            if (race.Positions.GetDriverFinalStatus(item.Driver) == RacePositionCollection.eStatus.Accident ||
                race.Positions.GetDriverFinalStatus(item.Driver) == RacePositionCollection.eStatus.Retired)
            {
                newDs.CrashesCount++;
            }

            if (race.Positions.GetDriverFinalStatus(item.Driver) == RacePositionCollection.eStatus.Running)
            {
                newDs.FinishesCount++;
            }

            newDs.FinishPositionsMean.Add(item.CurrentPosition);

            newDs.LapsInLead +=
                tmp[item.Driver].LapsInLead;

            newDs.QualifyPositionsMean.Add(
                tmp[item.Driver].QualifyPosition);

            newDs.RacesCount++;
            newDs.LapsCount += item.LapNumber;

            int pos = item.CurrentPosition;

            if (pos < 2)
            {
                newDs.Top1++;
            }
            if (pos < 3)
            {
                newDs.Top2++;
            }
            if (pos < 4)
            {
                newDs.Top3++;
            }
            if (pos < 6)
            {
                newDs.Top5++;
            }
            if (pos < 11)
            {
                newDs.Top10++;
            }
            if (pos < 21)
            {
                newDs.Top20++;
            }

            newDs.PreviousWeekendStanding = prevDs;
            if (prevDs != null)
            {
                prevDs.NextWeeendStanding = newDs;
            }
        }