Beispiel #1
0
        /// <summary>
        /// Create a MeasureInfo object for generic stats.
        /// <param name="stat">The statistics to use.</param>
        /// <returns>A new GenericMeasureInfo object.</returns>
        /// </summary>
        /// <param name="shouldUseGenericMeasureInfo"></param>
        private MeasureInfo CreateGenericMeasureInfo(Statistics stat, bool shouldUseGenericMeasureInfo)
        {
            double?sum               = null;
            double?average           = null;
            double?StandardDeviation = null;
            object max               = null;
            object min               = null;

            if (!_nonNumericError)
            {
                if (_measureSum)
                {
                    sum = stat.sum;
                }

                if (_measureAverage && stat.count > 0)
                {
                    average = stat.sum / stat.count;
                }

                if (_measureStandardDeviation)
                {
                    StandardDeviation = Math.Sqrt(stat.variance);
                }
            }

            if (_measureMax)
            {
                if (shouldUseGenericMeasureInfo && (stat.max != null))
                {
                    double temp;
                    LanguagePrimitives.TryConvertTo <double>(stat.max, out temp);
                    max = temp;
                }
                else
                {
                    max = stat.max;
                }
            }

            if (_measureMin)
            {
                if (shouldUseGenericMeasureInfo && (stat.min != null))
                {
                    double temp;
                    LanguagePrimitives.TryConvertTo <double>(stat.min, out temp);
                    min = temp;
                }
                else
                {
                    min = stat.min;
                }
            }

            if (shouldUseGenericMeasureInfo)
            {
                GenericMeasureInfo gmi = new GenericMeasureInfo();
                gmi.Count             = stat.count;
                gmi.Sum               = sum;
                gmi.Average           = average;
                gmi.StandardDeviation = StandardDeviation;
                if (max != null)
                {
                    gmi.Maximum = (double)max;
                }

                if (min != null)
                {
                    gmi.Minimum = (double)min;
                }

                return(gmi);
            }
            else
            {
                GenericObjectMeasureInfo gomi = new GenericObjectMeasureInfo();
                gomi.Count   = stat.count;
                gomi.Sum     = sum;
                gomi.Average = average;
                gomi.Maximum = max;
                gomi.Minimum = min;

                return(gomi);
            }
        }
        private MeasureInfo CreateGenericMeasureInfo(Statistics stat, bool shouldUseGenericMeasureInfo)
        {
            double?nullable  = null;
            double?nullable2 = null;
            object max       = null;
            object min       = null;

            if (!this.nonNumericError)
            {
                if (this.measureSum)
                {
                    nullable = new double?(stat.sum);
                }
                if (this.measureAverage && (stat.count > 0))
                {
                    nullable2 = new double?(stat.sum / ((double)stat.count));
                }
            }
            if (this.measureMax)
            {
                if (shouldUseGenericMeasureInfo && (stat.max != null))
                {
                    double num;
                    LanguagePrimitives.TryConvertTo <double>(stat.max, out num);
                    max = num;
                }
                else
                {
                    max = stat.max;
                }
            }
            if (this.measureMin)
            {
                if (shouldUseGenericMeasureInfo && (stat.min != null))
                {
                    double num2;
                    LanguagePrimitives.TryConvertTo <double>(stat.min, out num2);
                    min = num2;
                }
                else
                {
                    min = stat.min;
                }
            }
            if (shouldUseGenericMeasureInfo)
            {
                GenericMeasureInfo info = new GenericMeasureInfo {
                    Count   = stat.count,
                    Sum     = nullable,
                    Average = nullable2
                };
                if (max != null)
                {
                    info.Maximum = new double?((double)max);
                }
                if (min != null)
                {
                    info.Minimum = new double?((double)min);
                }
                return(info);
            }
            return(new GenericObjectMeasureInfo {
                Count = stat.count, Sum = nullable, Average = nullable2, Maximum = max, Minimum = min
            });
        }