Exemplo n.º 1
0
        public void PreventAggregationAndAggregationDataMismatch_LastValueLong_LastValueDouble()
        {
            var tagValues = TagValues.Create(new List <ITagValue>()
            {
                V1, V2
            });

            AggregationAndAggregationDataMismatch(
                CreateView(LastValue.Create(), MEASURE_LONG),
                new Dictionary <TagValues, IAggregationData>()
            {
                { tagValues, LastValueDataDouble.Create(100) },
            });
        }
Exemplo n.º 2
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);
        }
        internal static IAggregationData CreateAggregationData(MutableAggregation aggregation, IMeasure measure)
        {
            return(aggregation.Match <IAggregationData>(
                       (msum) =>
            {
                return measure.Match <IAggregationData>(
                    (mdouble) =>
                {
                    return SumDataDouble.Create(msum.Sum);
                },
                    (mlong) =>
                {
                    return SumDataLong.Create((long)Math.Round(msum.Sum));
                },
                    (invalid) =>
                {
                    throw new ArgumentException();
                });
            },
                       CreateCountData,
                       CreateMeanData,
                       CreateDistributionData,
                       (mlval) =>
            {
                return measure.Match <IAggregationData>(
                    (mdouble) =>
                {
                    return LastValueDataDouble.Create(mlval.LastValue);
                },
                    (mlong) =>
                {
                    if (double.IsNaN(mlval.LastValue))
                    {
                        return LastValueDataLong.Create(0);
                    }

                    return LastValueDataLong.Create((long)Math.Round(mlval.LastValue));
                },
                    (invalid) =>
                {
                    throw new ArgumentException();
                });
            }));
        }
Exemplo n.º 4
0
        public void TestEquals()
        {
            var a1 = SumDataDouble.Create(10.0);
            var a2 = SumDataDouble.Create(20.0);
            var a3 = SumDataLong.Create(20);
            var a5 = CountData.Create(40);
            var a6 = CountData.Create(80);
            var a7 = DistributionData.Create(10, 10, 1, 1, 0, new List <long>()
            {
                0L, 10L, 0L
            });
            var a8 = DistributionData.Create(10, 10, 1, 1, 0, new List <long>()
            {
                0L, 10L, 100L
            });
            var a9 = DistributionData.Create(110, 10, 1, 1, 0, new List <long>()
            {
                0L, 10L, 0L
            });
            var a10 = DistributionData.Create(10, 110, 1, 1, 0, new List <long>()
            {
                0L, 10L, 0L
            });
            var a11 = DistributionData.Create(10, 10, -1, 1, 0, new List <long>()
            {
                0L, 10L, 0L
            });
            var a12 = DistributionData.Create(10, 10, 1, 5, 0, new List <long>()
            {
                0L, 10L, 0L
            });
            var a13 = DistributionData.Create(10, 10, 1, 1, 55.5, new List <long>()
            {
                0L, 10L, 0L
            });
            var a14 = MeanData.Create(5.0, 1, 5.0, 5.0);
            var a15 = MeanData.Create(-5.0, 1, -5.0, -5.0);
            var a16 = LastValueDataDouble.Create(20.0);
            var a17 = LastValueDataLong.Create(20);

            var a1a = SumDataDouble.Create(10.0);
            var a2a = SumDataDouble.Create(20.0);
            var a3a = SumDataLong.Create(20);
            var a5a = CountData.Create(40);
            var a6a = CountData.Create(80);
            var a7a = DistributionData.Create(10, 10, 1, 1, 0, new List <long>()
            {
                0L, 10L, 0L
            });
            var a8a = DistributionData.Create(10, 10, 1, 1, 0, new List <long>()
            {
                0L, 10L, 100L
            });
            var a9a = DistributionData.Create(110, 10, 1, 1, 0, new List <long>()
            {
                0L, 10L, 0L
            });
            var a10a = DistributionData.Create(10, 110, 1, 1, 0, new List <long>()
            {
                0L, 10L, 0L
            });
            var a11a = DistributionData.Create(10, 10, -1, 1, 0, new List <long>()
            {
                0L, 10L, 0L
            });
            var a12a = DistributionData.Create(10, 10, 1, 5, 0, new List <long>()
            {
                0L, 10L, 0L
            });
            var a13a = DistributionData.Create(10, 10, 1, 1, 55.5, new List <long>()
            {
                0L, 10L, 0L
            });
            var a14a = MeanData.Create(5.0, 1, 5.0, 5.0);
            var a15a = MeanData.Create(-5.0, 1, -5.0, -5.0);
            var a16a = LastValueDataDouble.Create(20.0);
            var a17a = LastValueDataLong.Create(20);

            Assert.Equal(a1, a1a);
            Assert.Equal(a2, a2a);
            Assert.Equal(a3, a3a);
            Assert.Equal(a5, a5a);
            Assert.Equal(a6, a6a);
            Assert.Equal(a7, a7a);
            Assert.Equal(a8, a8a);
            Assert.Equal(a9, a9a);
            Assert.Equal(a10, a10a);
            Assert.Equal(a11, a11a);
            Assert.Equal(a12, a12a);
            Assert.Equal(a13, a13a);
            Assert.Equal(a14, a14a);
            Assert.Equal(a15, a15a);
            Assert.Equal(a16, a16a);
            Assert.Equal(a17, a17a);
        }
Exemplo n.º 5
0
        public void TestMatchAndGet()
        {
            List <IAggregationData> aggregations =
                new List <IAggregationData>()
            {
                SumDataDouble.Create(10.0),
                SumDataLong.Create(100000000),
                CountData.Create(40),
                MeanData.Create(100.0, 10, 300.0, 500.0),
                DistributionData.Create(1, 1, 1, 1, 0, new List <long>()
                {
                    0L, 10L, 0L
                }),
                LastValueDataDouble.Create(20.0),
                LastValueDataLong.Create(200000000L),
            };

            List <object> actual = new List <object>();

            foreach (IAggregationData aggregation in aggregations)
            {
                aggregation.Match <object>(
                    (arg) =>
                {
                    actual.Add(arg.Sum);
                    return(null);
                },
                    (arg) =>
                {
                    actual.Add(arg.Sum);
                    return(null);
                },
                    (arg) =>
                {
                    actual.Add(arg.Count);
                    return(null);
                },
                    (arg) =>
                {
                    actual.Add(arg.Mean);
                    return(null);
                },
                    (arg) =>
                {
                    actual.Add(arg.BucketCounts);
                    return(null);
                },
                    (arg) =>
                {
                    actual.Add(arg.LastValue);
                    return(null);
                },
                    (arg) =>
                {
                    actual.Add(arg.LastValue);
                    return(null);
                },
                    (arg) => { throw new ArgumentException(); });
            }
            Assert.Equal(10.0, actual[0]);
            Assert.Equal(100000000L, actual[1]);
            Assert.Equal(40L, actual[2]);
            Assert.Equal(100.0, actual[3]);
            Assert.Equal(new List <long>()
            {
                0L, 10L, 0L
            }, actual[4]);
            Assert.Equal(20.0, actual[5]);
            Assert.Equal(200000000L, actual[6]);
        }