protected override async Task <Result?> Explore()
        {
            var distinctValuesResult = await distinctValuesProvider.ResultAsync;

            if (distinctValuesResult == null)
            {
                return(null);
            }

            var config = await sampleValuesGeneratorConfigProvider.ResultAsync;

            if (config == null)
            {
                return(null);
            }

            var sampleValues = Enumerable.Empty <JsonElement>();

            if (config.CategoricalSampling)
            {
                var rand      = new Random(Environment.TickCount);
                var allValues = ValueWithCountList <JsonElement> .FromValueWithCountEnum(
                    distinctValuesResult
                    .DistinctRows
                    .Where(r => !r.IsSuppressed)
                    .Select(r => r.IsNull
                            ? ValueWithCount <JsonElement> .ValueCount(JsonNull, r.Count, r.CountNoise)
                            : r));

                sampleValues = Enumerable
                               .Range(0, Context.SamplesToPublish)
                               .Select(_ => allValues.GetRandomValue(rand));
            }
            return(new Result(sampleValues.ToList()));
        }
Esempio n. 2
0
        public void FindValueTest(int count)
        {
            var vals = ValueWithCountList <int> .FromValueWithCountEnum(
                Enumerable.Range(0, count).Select(i => ValueWithCount <int> .ValueCount(i, 1L)));

            for (var i = 0; i < vals.Count; i++)
            {
                Assert.Equal(i, vals.FindValue(i));
            }
            Assert.Throws <ArgumentException>(() => vals.FindValue(count));
            Assert.Throws <ArgumentException>(() => vals.FindValue(count + 1));
        }
Esempio n. 3
0
        public async Task TestCategoricalBool()
        {
            using var scope = await testFixture.CreateTestScope("cov_clear", "survey", "fever", this);

            await scope.ResultTest <DistinctValuesComponent, DistinctValuesComponent.Result>(result =>
            {
                var expectedValues = new List <ValueWithCount <bool> >
                {
                    ValueWithCount <bool> .ValueCount(false, 3_468),
                    ValueWithCount <bool> .ValueCount(true, 592),
                };

                Assert.NotNull(result);
                CheckDistinctCategories(result !, expectedValues, el => el.GetBoolean());
            });
        }
Esempio n. 4
0
        public async Task TestCategoricalText()
        {
            using var scope = await testFixture.CreateTestScope("gda_banking", "loans", "status", this);

            await scope.ResultTest <DistinctValuesComponent, DistinctValuesComponent.Result>(result =>
            {
                var expectedValues = new List <ValueWithCount <string> >
                {
                    ValueWithCount <string> .ValueCount("C", 491L),
                    ValueWithCount <string> .ValueCount("A", 258L),
                    ValueWithCount <string> .ValueCount("D", 45L),
                    ValueWithCount <string> .ValueCount("B", 30L),
                };

                Assert.NotNull(result);
                CheckDistinctCategories(result !, expectedValues, el => el.GetString());
            });
        }
Esempio n. 5
0
        public async Task TestCategoricalBool()
        {
            using var scope = testFixture.SimpleComponentTestScope(
                      "cov_clear",
                      "survey",
                      "fever",
                      vcrFilename: ExplorerTestFixture.GenerateVcrFilename(this));

            await scope.ResultTest <DistinctValuesComponent, DistinctValuesComponent.Result>(result =>
            {
                var expectedValues = new List <ValueWithCount <bool> >
                {
                    ValueWithCount <bool> .ValueCount(false, 3_468),
                    ValueWithCount <bool> .ValueCount(true, 592),
                };

                CheckDistinctCategories(result, expectedValues, el => el.GetBoolean());
            });
        }
Esempio n. 6
0
        public async Task TestCategoricalText()
        {
            using var scope = testFixture.SimpleComponentTestScope(
                      "gda_banking",
                      "loans",
                      "status",
                      vcrFilename: ExplorerTestFixture.GenerateVcrFilename(this));

            await scope.ResultTest <DistinctValuesComponent, DistinctValuesComponent.Result>(result =>
            {
                var expectedValues = new List <ValueWithCount <string> >
                {
                    ValueWithCount <string> .ValueCount("C", 491L),
                    ValueWithCount <string> .ValueCount("A", 258L),
                    ValueWithCount <string> .ValueCount("D", 45L),
                    ValueWithCount <string> .ValueCount("B", 30L),
                };

                CheckDistinctCategories(result, expectedValues, el => el.GetString());
            });
        }