Exemplo n.º 1
0
        /// <summary>
        /// Creates a new DriverData object that represents a single driver's time on a single stage.
        /// Data is the 'raw' string data taken from the results
        /// </summary>
        private DriverTime CreateDriverTime(Entry driverEntry)
        {
            var driverTime = new DriverTime();

            driverTime.IsDnf            = driverEntry.IsDnfEntry;
            driverTime.OverallPosition  = driverEntry.Rank;
            driverTime.DriverName       = driverEntry.Name;
            driverTime.Vehicle          = driverEntry.VehicleName;
            driverTime.OverallTime      = ParseTimeSpan(driverEntry.TotalTime);
            driverTime.OverallDiffFirst = ParseTimeSpan(driverEntry.TotalDiff);
            driverTime.StageTime        = ParseTimeSpan(driverEntry.StageTime);
            driverTime.StageDiffFirst   = ParseTimeSpan(driverEntry.StageDiff);

            return(driverTime);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a driver's stage results to the stage's collection
        /// </summary>
        /// <returns>true</returns>
        public bool AddDriver(DriverTime driverTime)
        {
            // this is a lame fix for an issue where drivers can have duplicate names
            // since I have no way of differntiating between drivers, I can only give them
            // unique names knowing they all get mixed up...
            var driverName = driverTime.DriverName;
            var id         = 1;

            while (DriverTimes.ContainsKey(driverName))
            {
                driverName = driverTime.DriverName + id.ToString();
                id++;
            }

            if (driverTime.DriverName != driverName)
            {
                driverTime.DriverName = driverName;
            }

            DriverTimes.Add(driverName, driverTime);
            return(true);
        }
Exemplo n.º 3
0
        public bool ProcessResults()
        {
            if (stages.Count < 1)
            {
                return(true);
            }

            // get a list of all drivers that ran a stage, this is used as the master entry list
            ProcessDriverInfo();

            var previousStageTimes = new Dictionary <string, DriverTime>();
            var currentStageTimes  = new Dictionary <string, DriverTime>();

            // the "previous" stage's inital value is the first stage
            previousStageTimes = stages[0].DriverTimes;

            // for each stage
            for (int i = 0; i < stages.Count; i++)
            {
                currentStageTimes = stages[i].DriverTimes;

                // if a driver's PC crashes or they alt+f4, they will not score a stage time
                // and they will not show up as DNF, but will continue on
                // go thru all results and add zero times as needed

                // for each driver that started the rally
                foreach (var driver in DriverInfoDict.Keys)
                {
                    // get the driver time for the previous and current stage
                    DriverTime currentDriverTime;
                    DriverTime previousDriverTime;
                    var        hasCurrentDriverTime  = currentStageTimes.TryGetValue(driver, out currentDriverTime);
                    var        hasPreviousDriverTime = previousStageTimes.TryGetValue(driver, out previousDriverTime);

                    // if the driver does not have a current stage, create a DNF entry for them
                    if (!hasCurrentDriverTime)
                    {
                        var dnfEntry = new DriverTime()
                        {
                            IsDnf           = true,
                            DriverName      = driver,
                            Vehicle         = DriverInfoDict[driver].Vehicle,
                            OverallPosition = 0
                        };

                        currentStageTimes.Add(driver, dnfEntry);
                    }

                    // if the driver has a current stage, but not a previous stage, mark the current stage as DNF
                    else if (hasCurrentDriverTime && !hasPreviousDriverTime)
                    {
                        currentDriverTime.IsDnf           = true;
                        currentDriverTime.OverallPosition = 0;
                    }

                    // the driver has a current stage and a previous stage, do stuff
                    else if (hasCurrentDriverTime && hasPreviousDriverTime)
                    {
                        if (previousDriverTime.IsDnf)
                        {
                            currentDriverTime.IsDnf           = true;
                            currentDriverTime.OverallPosition = 0;
                        }

                        if (!previousDriverTime.IsDnf || !currentDriverTime.IsDnf)
                        {
                            currentDriverTime.PositionChange = previousDriverTime.OverallPosition - currentDriverTime.OverallPosition;
                        }
                    }

                    // set the overall position on the DriverInfo
                    if (hasCurrentDriverTime)
                    {
                        DriverInfoDict[driver].OverallPosition = currentDriverTime.OverallPosition;
                    }
                    else
                    {
                        DriverInfoDict[driver].OverallPosition = 0;
                    }
                }

                previousStageTimes = currentStageTimes;

                var isFirstStage = (i == 0);    // i == 0 this is the first stage
                CalculateDeltas(stages[i], isFirstStage);
            }

            return(true);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Adds a driver's stage results to the stage's collection
 /// </summary>
 /// <returns>true</returns>
 public bool AddDriver(DriverTime driverTime)
 {
     DriverTimes.Add(driverTime.DriverName, driverTime);
     return(true);
 }