示例#1
0
        public TypedValue CreateTypedValue()
        {
            var buckets = _histogram
                          .Percentiles(3)
                          .Select(v => new
            {
                v.CountAddedInThisIterationStep,
                v.ValueIteratedTo
            })
                          .GroupBy(v => v.ValueIteratedTo)
                          .Select(v => v.First())
                          .ToList();

            var bucketCounts = buckets.Select(v => v.CountAddedInThisIterationStep).ToList();

            bucketCounts.Add(0);

            var bucketBounds = buckets.Select(v => (double)v.ValueIteratedTo).ToList();

            var hasZeroLowerBounds = bucketBounds[0] == 0;

            if (!hasZeroLowerBounds)
            {
                bucketBounds.Insert(0, 0);
                bucketCounts.Insert(0, 0);
            }

            return(new TypedValue
            {
                DistributionValue = new Distribution
                {
                    BucketCounts = { bucketCounts },
                    BucketOptions = new BucketOptions
                    {
                        ExplicitBuckets = new Explicit {
                            Bounds = { bucketBounds }
                        }
                    },
                    Count = bucketCounts.Sum(),
                    Mean = _histogram.GetMean(),
                    SumOfSquaredDeviation = Math.Pow(_histogram.GetStdDeviation(), 2) * _histogram.TotalCount
                }
            });
        }