Beispiel #1
0
        public async Task Test_SummaryCCAStatisticsRequest_SiteModelWithSingleCell_FullExtents()
        {
            const byte TARGET_CMV = 50;

            AddClusterComputeGridRouting();
            AddApplicationGridRouting();

            var siteModel = BuildModelForSingleCellCMV(CMV_INCREMENT, TARGET_CMV);
            var operation = new CMVChangeStatisticsOperation();

            var cmvChangeStatisticsResult = await operation.ExecuteAsync(SimpleCMVChangeStatisticsArgument(siteModel, new[] { -50.0, -20.0, -10.0, 0.0, 10.0, 20.0, 50.0 }));

            cmvChangeStatisticsResult.Should().NotBeNull();
            cmvChangeStatisticsResult.ResultStatus.Should().Be(RequestErrorStatus.OK);
            cmvChangeStatisticsResult.BelowTargetPercent.Should().Be(0);
            cmvChangeStatisticsResult.AboveTargetPercent.Should().Be(0);
            cmvChangeStatisticsResult.WithinTargetPercent.Should().Be(0);
            cmvChangeStatisticsResult.TotalAreaCoveredSqMeters.Should().BeApproximately(SubGridTreeConsts.DefaultCellSize * SubGridTreeConsts.DefaultCellSize, 0.000001);
            cmvChangeStatisticsResult.Counts.Should().NotBeNull();
            cmvChangeStatisticsResult.Counts.Length.Should().Be(LENGTH);

            for (var i = 0; i < cmvChangeStatisticsResult.Counts.Length; i++)
            {
                cmvChangeStatisticsResult.Counts[i].Should().Be(i != 4 ? 0 : 1);
            }

            cmvChangeStatisticsResult.Percents.Should().NotBeNull();
            cmvChangeStatisticsResult.Percents.Length.Should().Be(LENGTH);

            for (var i = 0; i < cmvChangeStatisticsResult.Percents.Length; i++)
            {
                cmvChangeStatisticsResult.Percents[i].Should().Be(i != 4 ? 0 : 100);
            }
        }
Beispiel #2
0
        public async Task Test_CMVChangeStatisticsRequest_SiteModelWithMultipleCells_FullExtents()
        {
            const double TOLERANCE               = 0.000001;
            const short  NUMBER_OF_CELLS         = 2165;
            const short  NUMBER_OF_CELLS_SCANNED = 2165;

            double[] expectedPercentages =
            {
                2.3094688221709005,
                11.36258660508083,
                28.175519630484992,
                25.496535796766747,
                12.979214780600461,
                5.3579676674364896,
                14.318706697459586
            };

            int[] expectedCounts = { 50, 246, 610, 552, 281, 116, 310 };

            AddClusterComputeGridRouting();
            AddApplicationGridRouting();

            var tagFiles = new[]
            {
                Path.Combine(TestHelper.CommonTestDataPath, "TestTAGFile.tag"),
            };

            var siteModel = DITAGFileAndSubGridRequestsFixture.BuildModel(tagFiles, out _);
            var operation = new CMVChangeStatisticsOperation();

            var cmvChangeStatisticsResult = await operation.ExecuteAsync(SimpleCMVChangeStatisticsArgument(siteModel, new[] { -50.0, -20.0, -10.0, 0.0, 10.0, 20.0, 50.0 }));

            cmvChangeStatisticsResult.Should().NotBeNull();
            cmvChangeStatisticsResult.ResultStatus.Should().Be(RequestErrorStatus.OK);
            cmvChangeStatisticsResult.BelowTargetPercent.Should().Be(0);
            cmvChangeStatisticsResult.AboveTargetPercent.Should().Be(0);
            cmvChangeStatisticsResult.WithinTargetPercent.Should().Be(0);
            cmvChangeStatisticsResult.TotalAreaCoveredSqMeters.Should().BeApproximately(NUMBER_OF_CELLS_SCANNED * SubGridTreeConsts.DefaultCellSize * SubGridTreeConsts.DefaultCellSize, TOLERANCE);
            cmvChangeStatisticsResult.Counts.Should().NotBeNull();
            cmvChangeStatisticsResult.Counts.Length.Should().Be(LENGTH);
            cmvChangeStatisticsResult.Counts.Sum().Should().Be(NUMBER_OF_CELLS);

            for (var i = 0; i < cmvChangeStatisticsResult.Counts.Length; i++)
            {
                cmvChangeStatisticsResult.Counts[i].Should().Be(expectedCounts[i]);
            }

            cmvChangeStatisticsResult.Percents.Should().NotBeNull();
            cmvChangeStatisticsResult.Percents.Length.Should().Be(LENGTH);

            for (var i = 0; i < cmvChangeStatisticsResult.Percents.Length; i++)
            {
                cmvChangeStatisticsResult.Percents[i].Should().BeApproximately(expectedPercentages[i], TOLERANCE);
            }
        }
Beispiel #3
0
        public async Task Test_CMVChangeStatisticsRequest_EmptySiteModel_FullExtents()
        {
            AddClusterComputeGridRouting();
            AddApplicationGridRouting();

            var siteModel = DITAGFileAndSubGridRequestsWithIgniteFixture.NewEmptyModel();
            var operation = new CMVChangeStatisticsOperation();

            var cmvChangeStatisticsResult = await operation.ExecuteAsync(SimpleCMVChangeStatisticsArgument(siteModel, new [] { -50.0, -20.0, -10.0, 0.0, 10.0, 20.0, 50.0 }));

            cmvChangeStatisticsResult.Should().NotBeNull();
            cmvChangeStatisticsResult.ResultStatus.Should().Be(RequestErrorStatus.FailedToRequestDatamodelStatistics);
        }
Beispiel #4
0
        protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item)
        {
            var request = item as CMVChangeDetailsRequest;

            if (request == null)
            {
                ThrowRequestTypeCastException <CMVChangeDetailsRequest>();
            }

            var siteModel = GetSiteModel(request?.ProjectUid);

            var filter = ConvertFilter(request?.Filter, siteModel);

            // Insert an extra element at the lower bound ...
            var tempList = request?.CMVChangeDetailsValues.ToList();

            tempList?.Insert(0, short.MinValue);

            var operation = new CMVChangeStatisticsOperation();
            var cmvChangeDetailsResult = await operation.ExecuteAsync(new CMVChangeStatisticsArgument()
            {
                ProjectID = siteModel.ID,
                Filters   = new FilterSet(filter),
                CMVChangeDetailsDataValues = tempList?.ToArray(),
                Overrides  = AutoMapperUtility.Automapper.Map <OverrideParameters>(request.Overrides),
                LiftParams = ConvertLift(request.LiftSettings, request.Filter?.LayerType)
            });

            if (cmvChangeDetailsResult != null)
            {
                if (cmvChangeDetailsResult.ResultStatus == RequestErrorStatus.OK)
                {
                    return(new CMVChangeSummaryResult(cmvChangeDetailsResult.Percents, cmvChangeDetailsResult.TotalAreaCoveredSqMeters));
                }

                throw CreateServiceException <DetailedCMVChangeExecutor>(cmvChangeDetailsResult.ResultStatus);
            }

            throw CreateServiceException <DetailedCMVChangeExecutor>();
        }
Beispiel #5
0
        public async Task <JsonResult> GetCMVChange([FromRoute] string siteModelID, [FromBody] OverrideParameters overrides)
        {
            string resultToReturn;

            if (!Guid.TryParse(siteModelID, out var UID))
            {
                resultToReturn = $"<b>Invalid Site Model UID: {siteModelID}</b>";
            }
            else
            {
                var siteModel       = DIContext.Obtain <ISiteModels>().GetSiteModel(UID, false);
                var cmvPercentBands = new double[] { short.MinValue, -50.0, -20.0, -10.0, 0.0, 10.0, 20.0, 50.0 };

                if (siteModel == null)
                {
                    resultToReturn = $"<b>Site model {UID} is unavailable</b>";
                }
                else
                {
                    var sw = new Stopwatch();
                    sw.Start();

                    var operation = new CMVChangeStatisticsOperation();
                    var result    = await operation.ExecuteAsync(
                        new CMVChangeStatisticsArgument()
                    {
                        ProjectID = siteModel.ID,
                        Filters   = new FilterSet()
                        {
                            Filters = new[] { new CombinedFilter() }
                        },
                        CMVChangeDetailsDataValues = cmvPercentBands,
                        Overrides = overrides
                    }
                        );

                    if (result != null)
                    {
                        string resultString = $"<b>CMV Percent Change Details Results (in {sw.Elapsed}) :</b><br/>";
                        resultString += "<b>================================================</b><br/>";

                        var anyNegativeNumber  = cmvPercentBands.ToList().Find(s => s < 0);
                        var anyTwoDigitsNumber = cmvPercentBands.ToList().Find(s => Math.Abs(s) >= TWO_DIGITS_NUMBER);

                        for (int i = 0; i < cmvPercentBands.Length; i++)
                        {
                            string space = anyNegativeNumber < 0 && cmvPercentBands[i] >= 0 ? "&nbsp;&nbsp;" : string.Empty;

                            if (Math.Abs(anyTwoDigitsNumber) > 0 && Math.Abs(cmvPercentBands[i]) >= 0 && Math.Abs(cmvPercentBands[i]) < TWO_DIGITS_NUMBER)
                            {
                                space += "&nbsp;&nbsp;";
                            }

                            if (cmvPercentBands[i] == short.MinValue)
                            {
                                resultString += $"<b>{space}<{cmvPercentBands[i + 1]:##0.#0}%</b> - {result.Percents[i]:##0.#0}%<br/>";
                            }
                            else
                            {
                                resultString += $"<b>{space}{cmvPercentBands[i]:##0.#0}%</b> - {result.Percents[i]:##0.#0}%<br/>";
                            }
                        }

                        resultToReturn = resultString;
                    }
                    else
                    {
                        resultToReturn = "<b>No result</b>";
                    }
                }
            }

            return(new JsonResult(resultToReturn));
        }
Beispiel #6
0
        public void Test_CMVChangeStatisticsRequest_Creation()
        {
            var operation = new CMVChangeStatisticsOperation();

            operation.Should().NotBeNull();
        }