Exemplo n.º 1
0
        /// <summary>
        /// Gets the data of a variable from an episode using the parameters of the target track
        /// </summary>
        /// <param name="episode">The episode</param>
        /// <param name="trackParameters">The track parameters</param>
        /// <param name="variableIndex">Index of the variable</param>
        /// <returns>A Series objetct with the requested data or null if something fails</returns>
        public static Series GetVariableData(Log.Episode episode, Report trackParameters, int variableIndex)
        {
            if (episode.steps[episode.steps.Count - 1].episodeSimTime < trackParameters.MinEpisodeLength)
            {
                return(null);
            }

            Series data = new Series();

            foreach (Log.Step step in episode.steps)
            {
                if (step.episodeSimTime >= trackParameters.TimeOffset)
                {
                    data.AddValue(step.episodeSimTime
                                  , ProcessFunc.Get(trackParameters.ProcessFunc, step.data[variableIndex]));
                }
            }

            if (data.Values.Count == 0)
            {
                return(null);
            }

            data.CalculateStats(trackParameters);

            if (trackParameters.Resample)
            {
                data.Resample(trackParameters.NumSamples);
            }
            return(data);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the average value of a variable in an episode using the track parameters
        /// </summary>
        /// <param name="episode">The episode</param>
        /// <param name="variableIndex">Index of the variable</param>
        /// <param name="trackParameters">The track parameters</param>
        /// <returns>The averaged value</returns>
        public static double GetEpisodeAverage(Log.Episode episode, int variableIndex, Report trackParameters)
        {
            double avg   = 0.0;
            int    count = 0;

            if (episode.steps.Count == 0)
            {
                return(0.0);
            }
            foreach (Log.Step step in episode.steps)
            {
                if (step.episodeSimTime >= trackParameters.TimeOffset)
                {
                    avg += ProcessFunc.Get(trackParameters.ProcessFunc, step.data[variableIndex]);
                    count++;
                }
            }
            return(avg / count);
        }
Exemplo n.º 3
0
        public void CalculateStats(Report trackParameters)
        {
            //calculate avg, min and max
            double sum = 0.0;

            Stats.min = double.MaxValue;
            Stats.max = double.MinValue;

            //curve "beauty"
            double prevY     = Values[0].Y;
            double prevX     = Values[0].X;
            double ascBeauty = 0.0;
            double dscBeauty = 0.0;
            double sumSlopes = 0.0;
            double slope;

            foreach (XYValue val in Values)
            {
                if (val.Y > Stats.max)
                {
                    Stats.max = val.Y;
                }
                if (val.Y < Stats.min)
                {
                    Stats.min = val.Y;
                }

                if (val.X - prevX != 0.0)
                {
                    slope = (ProcessFunc.Get(trackParameters.ProcessFunc, val.Y)
                             - prevY) / (val.X - prevX);


                    if (slope > 0.0)
                    {
                        ascBeauty += slope;
                        dscBeauty -= slope * 10.0;
                    }
                    else if (slope < 0.0)
                    {
                        ascBeauty += slope * 10.0;
                        dscBeauty -= slope;
                    }
                    sumSlopes += slope;
                }
                prevY = val.Y;
                prevX = val.X;
                sum  += ProcessFunc.Get(trackParameters.ProcessFunc, val.Y);
            }
            double avgSlope = sumSlopes / Values.Count;

            Stats.ascBeauty = ascBeauty / Values.Count;
            Stats.dscBeauty = dscBeauty / Values.Count;
            Stats.avg       = sum / Values.Count;

            //calculate std. deviation
            double diff;

            sum = 0.0;
            foreach (XYValue val in Values)
            {
                diff = val.Y - Stats.avg;
                sum += diff * diff;
            }

            Stats.stdDev = Math.Sqrt(sum / Values.Count);
        }