예제 #1
0
        /// <summary>Returns a <see cref="string"/> representation of min and max parts of a metric value.</summary>
        /// <param name="metricValues">Range of metric values.</param>
        /// <param name="metricUnit">The metric measurement unit.</param>
        /// <param name="minString">String representation of min part of a metric value.</param>
        /// <param name="maxString">String representation of max part of a metric value.</param>
        public static void GetMinMaxString(
            this MetricRange metricValues, [NotNull] MetricUnit metricUnit, out string minString, out string maxString)
        {
            metricValues = ToScaledValues(metricValues, metricUnit);
            var displayFormat = GetFormatForScaled(metricValues, metricUnit);

            minString = metricValues.Min.ToString(displayFormat, HostEnvironmentInfo.MainCultureInfo);
            maxString = metricValues.Max.ToString(displayFormat, HostEnvironmentInfo.MainCultureInfo);
        }
예제 #2
0
        public MetricUnit this[MetricRange measuredValues]
        {
            get
            {
                var min = Math.Abs(measuredValues.Min);
                var max = Math.Abs(measuredValues.Max);

                return(this[Math.Min(min, max)]);
            }
        }
예제 #3
0
        /// <summary>Returns a <see cref="string"/> representation of a metric value.</summary>
        /// <param name="metricValues">Range of metric values.</param>
        /// <param name="metricUnit">The metric measurement unit.</param>
        /// <returns>A <see cref="string"/> that represents the metric value.</returns>
        public static string ToString(this MetricRange metricValues, [NotNull] MetricUnit metricUnit)
        {
            metricValues = ToScaledValues(metricValues, metricUnit);
            var displayFormat = GetFormatForScaled(metricValues, metricUnit);

            var formattedValue = metricValues.ToString(displayFormat, HostEnvironmentInfo.MainCultureInfo);

            return((metricValues.IsEmpty || metricUnit.IsEmpty || string.IsNullOrEmpty(metricUnit.DisplayName))
                                ? formattedValue
                                : formattedValue + " " + metricUnit.DisplayName);
        }
예제 #4
0
        /// <summary>
        /// Determines whether the range contains another one.
        /// The check is performed using same rounding that will be used to store the <paramref name="metricValues"/>.
        /// </summary>
        /// <param name="metricValues">Range of metric values.</param>
        /// <param name="other">The metric range to check.</param>
        /// <param name="metricUnit">
        /// The metric measurement unit that will be used to store the <paramref name="metricValues"/>.
        /// </param>
        /// <returns><c>true</c>, if the range contains another one.</returns>
        public static bool ContainsWithRounding(
            this MetricRange metricValues, MetricRange other, [NotNull] MetricUnit metricUnit)
        {
            var scaledMetricValues      = metricValues.ToScaledValues(metricUnit);
            var scaledOtherMetricValues = other.ToScaledValues(metricUnit);

            var roundDigits = GetRoundingDigits(scaledMetricValues, metricUnit);

            scaledMetricValues      = scaledMetricValues.Round(roundDigits);
            scaledOtherMetricValues = scaledOtherMetricValues.Round(roundDigits);

            return(scaledMetricValues.Contains(scaledOtherMetricValues));
        }
예제 #5
0
        /// <summary>
        /// Determines whether the range can be represented as a single point range
        /// (scaled and rounded min and max are the same).
        /// </summary>
        /// <param name="metricValues">Range of metric values.</param>
        /// <param name="metricUnit">
        /// The metric measurement unit that will be used to store the <paramref name="metricValues"/>.
        /// </param>
        /// <returns><c>true</c>, if the range can be represented as a single point range.</returns>
        public static bool MinMaxAreSame(this MetricRange metricValues, [NotNull] MetricUnit metricUnit)
        {
            if (metricValues.IsEmpty)
            {
                return(true);
            }

            var scaledMetricValues = metricValues.ToScaledValues(metricUnit);
            var roundDigits        = GetRoundingDigits(scaledMetricValues, metricUnit);

            scaledMetricValues = scaledMetricValues.Round(roundDigits);

            return(scaledMetricValues.Min.Equals(scaledMetricValues.Max));
        }
예제 #6
0
        /// <summary>Determines if the minimum metric value should be stored.</summary>
        /// <param name="metricRange">The metric range.</param>
        /// <param name="metricUnit">The metric unit.</param>
        /// <param name="singleValueMode">The single value treatment mode.</param>
        /// <returns><c>true</c>, if the minimum metric value should be stored.</returns>
        public static bool ShouldStoreMinMetricValue(
            this MetricRange metricRange, MetricUnit metricUnit,
            MetricSingleValueMode singleValueMode)
        {
            switch (singleValueMode)
            {
            case MetricSingleValueMode.FromZeroToMax:
                return(!metricRange.Min.Equals(0));

            case MetricSingleValueMode.FromInfinityToMax:
                return(!double.IsInfinity(metricRange.Min));

            case MetricSingleValueMode.BothMinAndMax:
                return(double.IsInfinity(metricRange.Min) || !metricRange.MinMaxAreSame(metricUnit));

            default:
                throw CodeExceptions.UnexpectedArgumentValue(nameof(singleValueMode), singleValueMode);
            }
        }
예제 #7
0
        /// <summary>Determines if the minimum metric value should be stored.</summary>
        /// <param name="metricRange">The metric range.</param>
        /// <param name="metricUnit">The metric unit.</param>
        /// <param name="defaultMinValue">>Min value to be used by default.</param>
        /// <returns><c>true</c>, if the minimum metric value should be stored.</returns>
        public static bool ShouldStoreMinMetricValue(
            this MetricRange metricRange, MetricUnit metricUnit,
            DefaultMinMetricValue defaultMinValue)
        {
            switch (defaultMinValue)
            {
            case DefaultMinMetricValue.Zero:
                return(!metricRange.Min.Equals(0));

            case DefaultMinMetricValue.NegativeInfinity:
                return(!double.IsInfinity(metricRange.Min));

            case DefaultMinMetricValue.SameAsMax:
                return(double.IsInfinity(metricRange.Min) || !metricRange.MinMaxAreSame(metricUnit));

            default:
                throw CodeExceptions.UnexpectedArgumentValue(nameof(defaultMinValue), defaultMinValue);
            }
        }
예제 #8
0
 /// <summary>Returns a <see cref="string"/> representation of a metric value.</summary>
 /// <param name="metricValues">Range of metric values.</param>
 /// <param name="metricUnitScale">The metric measurement scale.</param>
 /// <returns>A <see cref="string"/> that represents the metric value.</returns>
 public static string ToString(this MetricRange metricValues, [NotNull] MetricUnitScale metricUnitScale) =>
 ToString(metricValues, metricUnitScale[metricValues]);
예제 #9
0
 private static MetricRange Round(this MetricRange metricValues, int roundingDigits) =>
 CreateMetricRange(
     metricValues.Min.Round(roundingDigits),
     metricValues.Max.Round(roundingDigits));
예제 #10
0
 private static MetricRange ToScaledValues(this MetricRange metricValues, MetricUnit metricUnit) =>
 CreateMetricRange(
     metricValues.Min.ToScaledValue(metricUnit),
     metricValues.Max.ToScaledValue(metricUnit));
예제 #11
0
 private static string GetFormatForScaled(MetricRange scaledMetricValues, MetricUnit metricUnit) =>
 "F" + GetRoundingDigits(scaledMetricValues, metricUnit);
예제 #12
0
 private static int GetRoundingDigits(MetricRange scaledMetricValues, MetricUnit metricUnit) =>
 metricUnit.RoundingDigits ??
 Math.Max(
     GetRoundingDigits(scaledMetricValues.Min),
     GetRoundingDigits(scaledMetricValues.Max));
예제 #13
0
 /// <summary>Determines if the minimum metric value should be stored.</summary>
 /// <param name="metricRange">The metric range.</param>
 /// <param name="metricUnit">The metric unit.</param>
 /// <param name="metric">The metric information.</param>
 /// <returns><c>true</c>, if the minimum metric value should be stored.</returns>
 public static bool ShouldStoreMinMetricValue(
     this MetricRange metricRange, MetricUnit metricUnit,
     [NotNull] MetricInfo metric) =>
 ShouldStoreMinMetricValue(metricRange, metricUnit, metric.SingleValueMode);
예제 #14
0
 /// <summary>Determines if the minimum metric value should be stored.</summary>
 /// <param name="metricRange">The metric range.</param>
 /// <param name="metricUnit">The metric unit.</param>
 /// <param name="metric">The metric information.</param>
 /// <returns><c>true</c>, if the minimum metric value should be stored.</returns>
 public static bool ShouldStoreMinMetricValue(
     this MetricRange metricRange, MetricUnit metricUnit,
     [NotNull] MetricInfo metric) =>
 ShouldStoreMinMetricValue(metricRange, metricUnit, metric.DefaultMinValue);