Exemple #1
0
        public void TestNoBoundaries()
        {
            List <double>     buckets          = new List <double>();
            IBucketBoundaries bucketBoundaries = BucketBoundaries.Create(buckets);

            Assert.Equal(buckets, bucketBoundaries.Boundaries);
        }
Exemple #2
0
 public static IDistribution Create(IBucketBoundaries bucketBoundaries)
 {
     if (bucketBoundaries == null)
     {
         throw new ArgumentNullException(nameof(bucketBoundaries));
     }
     return(new Distribution(bucketBoundaries));
 }
Exemple #3
0
 Distribution(IBucketBoundaries bucketBoundaries)
 {
     if (bucketBoundaries == null)
     {
         throw new ArgumentNullException("Null bucketBoundaries");
     }
     BucketBoundaries = bucketBoundaries;
 }
Exemple #4
0
        internal static MutableDistribution Create(IBucketBoundaries bucketBoundaries)
        {
            if (bucketBoundaries == null)
            {
                throw new ArgumentNullException(nameof(bucketBoundaries));
            }

            return(new MutableDistribution(bucketBoundaries));
        }
        public void TestCreateDistribution()
        {
            IBucketBoundaries bucketBoundaries = BucketBoundaries.Create(new List <double>()
            {
                0.1, 2.2, 33.3
            });
            IDistribution distribution = Distribution.Create(bucketBoundaries);

            Assert.Equal(bucketBoundaries, distribution.BucketBoundaries);
        }
Exemple #6
0
        public void TestConstructBoundaries()
        {
            List <Double> buckets = new List <double>()
            {
                0.0, 1.0, 2.0
            };
            IBucketBoundaries bucketBoundaries = BucketBoundaries.Create(buckets);

            Assert.Equal(buckets, bucketBoundaries.Boundaries);
        }
Exemple #7
0
        public void CreateAggregationData()
        {
            IBucketBoundaries bucketBoundaries = BucketBoundaries.Create(new List <double>()
            {
                -1.0, 0.0, 1.0
            });
            List <MutableAggregation> mutableAggregations =
                new List <MutableAggregation>()
            {
                MutableCount.Create(),
                                      MutableMean.Create(),
                                      MutableDistribution.Create(bucketBoundaries)
            };
            List <IAggregationData> aggregates = new List <IAggregationData>
            {
                MutableViewData.CreateAggregationData(MutableSum.Create(), MEASURE_DOUBLE),
                MutableViewData.CreateAggregationData(MutableSum.Create(), MEASURE_LONG),
                MutableViewData.CreateAggregationData(MutableLastValue.Create(), MEASURE_DOUBLE),
                MutableViewData.CreateAggregationData(MutableLastValue.Create(), MEASURE_LONG)
            };

            foreach (MutableAggregation mutableAggregation in mutableAggregations)
            {
                aggregates.Add(MutableViewData.CreateAggregationData(mutableAggregation, MEASURE_DOUBLE));
            }

            List <IAggregationData> expected = new List <IAggregationData>()
            {
                SumDataDouble.Create(0),
                SumDataLong.Create(0),
                LastValueDataDouble.Create(double.NaN),
                LastValueDataLong.Create(0),
                CountData.Create(0),
                MeanData.Create(0, 0, double.MaxValue, double.MinValue),
                DistributionData.Create(
                    0,
                    0,
                    double.PositiveInfinity,
                    double.NegativeInfinity,
                    0,
                    new List <long>()
                {
                    0L, 0L, 0L, 0L
                })
            };

            Assert.Equal(expected, aggregates);
        }
Exemple #8
0
        /// <summary>
        /// Converts <see cref="IBucketBoundaries"/> to Stackdriver's <see cref="BucketOptions"/>.
        /// </summary>
        /// <param name="bucketBoundaries">A <see cref="IBucketBoundaries"/> representing the bucket boundaries.</param>
        /// <returns><see cref="BucketOptions"/>.</returns>
        private static BucketOptions ToBucketOptions(this IBucketBoundaries bucketBoundaries)
        {
            // The first bucket bound should be 0.0 because the Metrics first bucket is
            // [0, first_bound) but Stackdriver monitoring bucket bounds begin with -infinity
            // (first bucket is (-infinity, 0))
            var bucketOptions = new BucketOptions
            {
                ExplicitBuckets = new BucketOptions.Types.Explicit
                {
                    Bounds = { 0.0 },
                },
            };

            bucketOptions.ExplicitBuckets.Bounds.AddRange(bucketBoundaries.Boundaries);

            return(bucketOptions);
        }
Exemple #9
0
        public static Google.Api.Distribution CreateDistribution(
            IDistributionData distributionData,
            IBucketBoundaries bucketBoundaries)
        {
            var bucketOptions = bucketBoundaries.ToBucketOptions();
            var distribution  = new Google.Api.Distribution
            {
                BucketOptions         = bucketOptions,
                BucketCounts          = { CreateBucketCounts(distributionData.BucketCounts) },
                Count                 = distributionData.Count,
                Mean                  = distributionData.Mean,
                SumOfSquaredDeviation = distributionData.SumOfSquaredDeviations,
                Range                 = new Range {
                    Max = distributionData.Max, Min = distributionData.Min
                },
            };

            return(distribution);
        }
Exemple #10
0
        public void TestBoundariesDoesNotChangeWithOriginalList()
        {
            List <double> original = new List <double>();

            original.Add(0.0);
            original.Add(1.0);
            original.Add(2.0);
            IBucketBoundaries bucketBoundaries = BucketBoundaries.Create(original);

            original[2] = 3.0;
            original.Add(4.0);
            List <double> expected = new List <double>()
            {
                0.0, 1.0, 2.0
            };

            Assert.NotEqual(original, bucketBoundaries.Boundaries);
            Assert.Equal(expected, bucketBoundaries.Boundaries);
        }
Exemple #11
0
        public void TestCreateEmpty()
        {
            Assert.InRange(MutableSum.Create().Sum, 0 - TOLERANCE, 0 + TOLERANCE);
            Assert.Equal(0, MutableCount.Create().Count);
            Assert.InRange(MutableMean.Create().Mean, 0 - TOLERANCE, 0 + TOLERANCE);
            Assert.True(Double.IsNaN(MutableLastValue.Create().LastValue));

            IBucketBoundaries bucketBoundaries = BucketBoundaries.Create(new List <double>()
            {
                0.1, 2.2, 33.3
            });
            MutableDistribution mutableDistribution = MutableDistribution.Create(bucketBoundaries);

            Assert.InRange(mutableDistribution.Mean, 0, TOLERANCE);
            Assert.Equal(0, mutableDistribution.Count);
            Assert.Equal(double.PositiveInfinity, mutableDistribution.Min);
            Assert.Equal(double.NegativeInfinity, mutableDistribution.Max);
            Assert.InRange(mutableDistribution.SumOfSquaredDeviations, 0 - TOLERANCE, 0 + TOLERANCE);
            Assert.Equal(new long[4], mutableDistribution.BucketCounts);
        }
Exemple #12
0
        public void CreateMutableAggregation()
        {
            IBucketBoundaries bucketBoundaries = BucketBoundaries.Create(new List <double>()
            {
                -1.0, 0.0, 1.0
            });

            Assert.InRange(((MutableSum)MutableViewData.CreateMutableAggregation(Sum.Create())).Sum, 0.0 - EPSILON, 0.0 + EPSILON);
            Assert.Equal(0, ((MutableCount)MutableViewData.CreateMutableAggregation(Count.Create())).Count);
            Assert.InRange(((MutableMean)MutableViewData.CreateMutableAggregation(Mean.Create())).Mean, 0.0 - EPSILON, 0.0 + EPSILON);
            Assert.True(Double.IsNaN(((MutableLastValue)MutableViewData.CreateMutableAggregation(LastValue.Create())).LastValue));

            MutableDistribution mutableDistribution =
                (MutableDistribution)MutableViewData.CreateMutableAggregation(Distribution.Create(bucketBoundaries));

            Assert.Equal(double.PositiveInfinity, mutableDistribution.Min);
            Assert.Equal(double.NegativeInfinity, mutableDistribution.Max);
            Assert.InRange(mutableDistribution.SumOfSquaredDeviations, 0.0 - EPSILON, 0.0 + EPSILON);
            Assert.Equal(new long[4], mutableDistribution.BucketCounts);
        }
Exemple #13
0
 internal MutableDistribution(IBucketBoundaries bucketBoundaries)
 {
     this.BucketBoundaries = bucketBoundaries;
     this.BucketCounts     = new long[bucketBoundaries.Boundaries.Count + 1];
 }
 private Distribution(IBucketBoundaries bucketBoundaries)
 {
     this.BucketBoundaries = bucketBoundaries ?? throw new ArgumentNullException("Null bucketBoundaries");
 }