コード例 #1
0
 private void GenerateRandomKey(DimensionSpecification dims)
 {
     dims.Clear();
     foreach (var d in this.dimensionSet.Dimensions)
     {
         dims.Add(d.Name, GetRandom(MaxDimensionValue).ToString());
     }
 }
コード例 #2
0
        public async Task GetBucketedDataCombinesDataAcrossDimensionValuesIfFilterValueIsNotProvided()
        {
            var          anyTimestamp    = DateTime.Now;
            const string FirstDimension  = "1st";
            const string SecondDimension = "2nd";
            const string ThirdDimension  = "3rd";

            var dimensions = new DimensionSet(new HashSet <Dimension>
            {
                new Dimension(FirstDimension),
                new Dimension(SecondDimension),
                new Dimension(ThirdDimension)
            });
            var counter = await this.dataManager.CreateHitCounter(AnyCounterName, dimensions);


            var dimValues = new DimensionSpecification();

            for (int i = 0; i < 10; ++i)
            {
                dimValues[FirstDimension] = i.ToString();
                for (int j = 0; j < 10; ++j)
                {
                    dimValues[SecondDimension] = j.ToString();
                    for (int k = 0; k < 10; ++k)
                    {
                        dimValues[ThirdDimension] = k.ToString();
                        counter.Increment(dimValues, anyTimestamp);
                    }
                }
            }

            var sample =
                this.BucketedDataQuery(counter, new DimensionSpecification()).First();

            Assert.AreEqual(DataSampleType.HitCount, sample.SampleType);
            Assert.AreEqual((ulong)1000, sample.HitCount);

            dimValues.Clear();
            dimValues[FirstDimension] = "8"; // take one tenth of things by filter.
            sample = this.BucketedDataQuery(counter, dimValues).First();
            Assert.AreEqual((ulong)100, sample.HitCount);

            dimValues[SecondDimension] = "6";
            sample = this.BucketedDataQuery(counter, dimValues).First();
            Assert.AreEqual((ulong)10, sample.HitCount);

            dimValues[ThirdDimension] = "7";
            sample = this.BucketedDataQuery(counter, dimValues).First();
            Assert.AreEqual((ulong)1, sample.HitCount);
        }
コード例 #3
0
 private void GenerateRandomKey(DimensionSpecification dims)
 {
     dims.Clear();
     foreach (var d in this.dimensionSet.Dimensions)
     {
         dims.Add(d.Name, GetRandom(MaxDimensionValue).ToString());
     }
 }
コード例 #4
0
        public async Task GetBucketedDataSplitsDataByDimension()
        {
            var          anyTimestamp    = DateTime.Now;
            const string FirstDimension  = "1st";
            const string SecondDimension = "2nd";
            const string ThirdDimension  = "3rd";

            var dimensions = new DimensionSet(new HashSet <Dimension>
            {
                new Dimension(FirstDimension),
                new Dimension(SecondDimension),
                new Dimension(ThirdDimension)
            });
            var counter = await this.dataManager.CreateHitCounter(AnyCounterName, dimensions);


            var dimValues = new DimensionSpecification();

            for (int i = 0; i < 10; ++i)
            {
                dimValues[FirstDimension] = i.ToString();
                for (int j = 0; j < 10; ++j)
                {
                    dimValues[SecondDimension] = j.ToString();
                    for (int k = 0; k < 10; ++k)
                    {
                        dimValues[ThirdDimension] = k.ToString();
                        counter.Increment(dimValues, anyTimestamp);
                    }
                }
            }

            // Slice without any other filtering.
            dimValues.Clear();
            dimValues[ReservedDimensions.DimensionDimension] = FirstDimension;
            var samples = this.BucketedDataQuery(counter, dimValues, 10);
            var returnedDimensionValues = new HashSet <string>();

            foreach (var baseSample in samples)
            {
                var sample = baseSample;
                Assert.AreEqual((ulong)100, sample.HitCount);
                Assert.AreEqual(1, sample.Dimensions.Count);
                Assert.IsTrue(sample.Dimensions.ContainsKey(FirstDimension));
                Assert.IsFalse(returnedDimensionValues.Contains(sample.Dimensions[FirstDimension]));
                returnedDimensionValues.Add(sample.Dimensions[FirstDimension]);
            }
            Assert.AreEqual(10, returnedDimensionValues.Count);

            // Now slice by one dimension and split by another.
            dimValues[FirstDimension] = "4";
            dimValues[ReservedDimensions.DimensionDimension] = SecondDimension;
            samples = this.BucketedDataQuery(counter, dimValues, 10);
            returnedDimensionValues.Clear();
            foreach (var baseSample in samples)
            {
                var sample = baseSample;
                Assert.AreEqual((ulong)10, sample.HitCount);
                Assert.AreEqual(2, sample.Dimensions.Count);
                Assert.AreEqual("4", sample.Dimensions[FirstDimension]);
                Assert.IsTrue(sample.Dimensions.ContainsKey(SecondDimension));
                Assert.IsFalse(returnedDimensionValues.Contains(sample.Dimensions[SecondDimension]));
                returnedDimensionValues.Add(sample.Dimensions[SecondDimension]);
            }
            Assert.AreEqual(10, returnedDimensionValues.Count);
        }
コード例 #5
0
        public async Task GetBucketedDataSplitsDataByDimension()
        {
            var anyTimestamp = DateTime.Now;
            const string FirstDimension = "1st";
            const string SecondDimension = "2nd";
            const string ThirdDimension = "3rd";

            var dimensions = new DimensionSet(new HashSet<Dimension>
                                              {
                                                  new Dimension(FirstDimension),
                                                  new Dimension(SecondDimension),
                                                  new Dimension(ThirdDimension)
                                              });
            var counter = await this.dataManager.CreateHitCounter(AnyCounterName, dimensions);


            var dimValues = new DimensionSpecification();
            for (int i = 0; i < 10; ++i)
            {
                dimValues[FirstDimension] = i.ToString();
                for (int j = 0; j < 10; ++j)
                {
                    dimValues[SecondDimension] = j.ToString();
                    for (int k = 0; k < 10; ++k)
                    {
                        dimValues[ThirdDimension] = k.ToString();
                        counter.Increment(dimValues, anyTimestamp);
                    }
                }
            }

            // Slice without any other filtering.
            dimValues.Clear();
            dimValues[ReservedDimensions.DimensionDimension] = FirstDimension;
            var samples = this.BucketedDataQuery(counter, dimValues, 10);
            var returnedDimensionValues = new HashSet<string>();
            foreach (var baseSample in samples)
            {
                var sample = baseSample;
                Assert.AreEqual((ulong)100, sample.HitCount);
                Assert.AreEqual(1, sample.Dimensions.Count);
                Assert.IsTrue(sample.Dimensions.ContainsKey(FirstDimension));
                Assert.IsFalse(returnedDimensionValues.Contains(sample.Dimensions[FirstDimension]));
                returnedDimensionValues.Add(sample.Dimensions[FirstDimension]);
            }
            Assert.AreEqual(10, returnedDimensionValues.Count);

            // Now slice by one dimension and split by another.
            dimValues[FirstDimension] = "4";
            dimValues[ReservedDimensions.DimensionDimension] = SecondDimension;
            samples = this.BucketedDataQuery(counter, dimValues, 10);
            returnedDimensionValues.Clear();
            foreach (var baseSample in samples)
            {
                var sample = baseSample;
                Assert.AreEqual((ulong)10, sample.HitCount);
                Assert.AreEqual(2, sample.Dimensions.Count);
                Assert.AreEqual("4", sample.Dimensions[FirstDimension]);
                Assert.IsTrue(sample.Dimensions.ContainsKey(SecondDimension));
                Assert.IsFalse(returnedDimensionValues.Contains(sample.Dimensions[SecondDimension]));
                returnedDimensionValues.Add(sample.Dimensions[SecondDimension]);
            }
            Assert.AreEqual(10, returnedDimensionValues.Count);

        }
コード例 #6
0
        public async Task GetBucketedDataCombinesDataAcrossDimensionValuesIfFilterValueIsNotProvided()
        {
            var anyTimestamp = DateTime.Now;
            const string FirstDimension = "1st";
            const string SecondDimension = "2nd";
            const string ThirdDimension = "3rd";

            var dimensions = new DimensionSet(new HashSet<Dimension>
                                              {
                                                  new Dimension(FirstDimension),
                                                  new Dimension(SecondDimension),
                                                  new Dimension(ThirdDimension)
                                              });
            var counter = await this.dataManager.CreateHitCounter(AnyCounterName, dimensions);


            var dimValues = new DimensionSpecification();
            for (int i = 0; i < 10; ++i)
            {
                dimValues[FirstDimension] = i.ToString();
                for (int j = 0; j < 10; ++j)
                {
                    dimValues[SecondDimension] = j.ToString();
                    for (int k = 0; k < 10; ++k)
                    {
                        dimValues[ThirdDimension] = k.ToString();
                        counter.Increment(dimValues, anyTimestamp);
                    }
                }
            }

            var sample =
                this.BucketedDataQuery(counter, new DimensionSpecification()).First();
            Assert.AreEqual(DataSampleType.HitCount, sample.SampleType);
            Assert.AreEqual((ulong)1000, sample.HitCount);

            dimValues.Clear();
            dimValues[FirstDimension] = "8"; // take one tenth of things by filter.
            sample = this.BucketedDataQuery(counter, dimValues).First();
            Assert.AreEqual((ulong)100, sample.HitCount);

            dimValues[SecondDimension] = "6";
            sample = this.BucketedDataQuery(counter, dimValues).First();
            Assert.AreEqual((ulong)10, sample.HitCount);

            dimValues[ThirdDimension] = "7";
            sample = this.BucketedDataQuery(counter, dimValues).First();
            Assert.AreEqual((ulong)1, sample.HitCount);
        }