Example #1
0
        /// <summary>
        /// Normalises all of the strategy lines in the list of strategy lines passed to the method
        /// </summary>
        /// <param name="bestTime">The time of the fastest driver</param>
        /// <param name="laps">The number of laps in the race</param>
        /// <param name="originalTraces">The traces to normalise</param>
        /// <returns>A list of strategy lines which are normalised using the selected normalisation method</returns>
        List <StrategyLine> NormaliseAllLines(float bestTime, float laps, List <StrategyLine> originalTraces)
        {
            float        adjustPerLap       = bestTime / laps;
            StrategyLine normalisationTrace = originalTraces.Find(t => t.DriverIndex == normalisedDriverIndex);

            List <StrategyLine> tracesToReturn = new List <StrategyLine>();

            foreach (StrategyLine s in originalTraces)
            {
                if (DriverPanel.SelectedDriverIndices.Exists(s.DriverIndex))
                {
                    switch (graphNormalisationType)
                    {
                    case NormalisationType.OnAverageValue:
                    {
                        tracesToReturn.Add(GetNormalisedStrategyLine(s, adjustPerLap));
                        break;
                    }

                    case NormalisationType.OnEveryValue:
                    {
                        tracesToReturn.Add(GetNormalisedStrategyLine(s, normalisationTrace));
                        break;
                    }
                    }
                }
            }

            return(tracesToReturn);
        }
Example #2
0
        /// <summary>
        /// Normalises a strategy line on every lap.
        /// </summary>
        /// <param name="line">The line to normalise</param>
        /// <param name="normalisationTrace">The trace used for normalisation</param>
        /// <returns>The new normalised line</returns>
        StrategyLine GetNormalisedStrategyLine(StrategyLine line, StrategyLine normalisationTrace)
        {
            StrategyLine normalisedLine = new StrategyLine(line.DriverIndex);
            lapDataPoint tempPoint;

            int   normalisedDriver = normalisationTrace.DriverIndex;
            float lappedCarCyleLimit;

            float thisLapAdjust       = 0;
            float lappedCarAdjustment = 0;
            float actualTime          = 0;

            int lapIndex = 0;

            foreach (lapDataPoint p in line.Coordinates)
            {
                if (lapIndex == 0)
                {
                    lappedCarCyleLimit = normalisationTrace.Coordinates[lapIndex].time;
                }
                else
                {
                    lappedCarCyleLimit = normalisationTrace.Coordinates[lapIndex].time - normalisationTrace.Coordinates[lapIndex - 1].time;
                }
                thisLapAdjust = normalisationTrace.Coordinates[lapIndex].time;

                if (lapIndex == line.Coordinates.Count - 1)
                {
                    actualTime = p.time;
                }

                tempPoint.driver = p.driver;
                tempPoint.lap    = p.lap;
                tempPoint.time   = p.time - thisLapAdjust + lappedCarAdjustment;
                tempPoint.draw   = p.draw;

                if (tempPoint.time > (lappedCarCyleLimit / 2))
                {
                    lappedCarAdjustment -= lappedCarCyleLimit;
                    tempPoint.time      -= lappedCarCyleLimit;
                    tempPoint.draw       = false;
                }
                if (tempPoint.time < -(lappedCarCyleLimit / 2))
                {
                    lappedCarAdjustment += lappedCarCyleLimit;
                    tempPoint.time      += lappedCarCyleLimit;
                    tempPoint.draw       = false;
                }

                normalisedLine.AddPoint(tempPoint);
                ++lapIndex;
            }
            normalisedLine.TotalTime = actualTime;

            return(normalisedLine);
        }
Example #3
0
        /// <summary>
        /// Normalises a strategy on an average time
        /// </summary>
        /// <param name="line">The line to normalise</param>
        /// <param name="adjustPerLap">The amount by which to adjust the trace each lap</param>
        /// <returns>The new normalised line</returns>
        StrategyLine GetNormalisedStrategyLine(StrategyLine line, float adjustPerLap)
        {
            StrategyLine normalisedLine = new StrategyLine(line.DriverIndex);
            lapDataPoint tempPoint;

            float lappedCarAdjustment = 0;
            float actualTime          = 0;

            int lapIndex = 0;

            foreach (lapDataPoint p in line.Coordinates)
            {
                //Sets the actual time taken for the strategy to complete,
                //before any adjustments are applied
                if (lapIndex == line.Coordinates.Count - 1)
                {
                    actualTime = p.time;
                }

                //set the properties of the new point
                tempPoint.driver = p.driver;
                tempPoint.lap    = p.lap;
                tempPoint.time   = (p.time - adjustPerLap * p.lap + lappedCarAdjustment);
                tempPoint.draw   = p.draw;

                //Deals with cars being lapped
                //Decreases the time if they are too slow, or increases them if
                //they are too fast
                if (tempPoint.time > (adjustPerLap / 2))
                {
                    lappedCarAdjustment -= adjustPerLap;
                    tempPoint.time      -= adjustPerLap;
                    tempPoint.draw       = false;
                }
                if (tempPoint.time < -(adjustPerLap / 2))
                {
                    lappedCarAdjustment += adjustPerLap;
                    tempPoint.time      += adjustPerLap;
                    tempPoint.draw       = false;
                }

                normalisedLine.AddPoint(tempPoint);
                ++lapIndex;
            }
            //Reset the total time for the strategy to the original time.
            normalisedLine.TotalTime = actualTime;

            return(normalisedLine);
        }