Ejemplo n.º 1
0
        public async Task Test_SummaryTemperatureStatistics_SiteModelWithSingleTAGFile_FullExtents_WithTemperatureTargetOverrides
            (ushort minTarget, ushort maxTarget, double percentBelow, double percentWithin, double percentAbove)
        {
            AddClusterComputeGridRouting();
            AddApplicationGridRouting();

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

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

            var temperatureSummaryResult = await operation.ExecuteAsync(SimpleTemperatureStatisticsArgument(siteModel, minTarget, maxTarget));

            temperatureSummaryResult.Should().NotBeNull();
            temperatureSummaryResult.ResultStatus.Should().Be(RequestErrorStatus.OK);
            temperatureSummaryResult.ReturnCode.Should().Be(MissingTargetDataResultType.NoProblems);
            temperatureSummaryResult.MinimumTemperature.Should().Be(minTarget == 0 ? MACHINE_TARGET_MIN : minTarget);
            temperatureSummaryResult.MaximumTemperature.Should().Be(maxTarget == 0 ? MACHINE_TARGET_MAX : maxTarget);
            temperatureSummaryResult.IsTargetTemperatureConstant.Should().BeTrue();
            temperatureSummaryResult.Counts.Should().BeNull();
            temperatureSummaryResult.Percents.Should().BeNull();
            temperatureSummaryResult.BelowTargetPercent.Should().BeApproximately(percentBelow, 0.001);
            temperatureSummaryResult.AboveTargetPercent.Should().BeApproximately(percentAbove, 0.001);
            temperatureSummaryResult.WithinTargetPercent.Should().BeApproximately(percentWithin, 0.001);
            temperatureSummaryResult.TotalAreaCoveredSqMeters.Should().BeApproximately(3054 * SubGridTreeConsts.DefaultCellSize * SubGridTreeConsts.DefaultCellSize, 0.000001);
        }
Ejemplo n.º 2
0
        public async Task Test_SummaryTemperatureStatistics_SiteModelWithSingleCell_FullExtents_NoTemperatureTargetOverride_WithMachineTemperatureTarget()
        {
            const ushort TARGET_TEMPERATURE_MIN = 25;
            const ushort TARGET_TEMPERATURE_MAX = 80;

            AddClusterComputeGridRouting();
            AddApplicationGridRouting();

            var siteModel = BuildModelForSingleCellTemperature(TEMPERATURE_INCREMENT);

            siteModel.MachinesTargetValues[0].TargetMinMaterialTemperature.PutValueAtDate(VSS.TRex.Common.Consts.MIN_DATETIME_AS_UTC, TARGET_TEMPERATURE_MIN);
            siteModel.MachinesTargetValues[0].TargetMaxMaterialTemperature.PutValueAtDate(VSS.TRex.Common.Consts.MIN_DATETIME_AS_UTC, TARGET_TEMPERATURE_MAX);

            var operation = new TemperatureStatisticsOperation();

            var temperatureSummaryResult = await operation.ExecuteAsync(SimpleTemperatureStatisticsArgument(siteModel, 0, 0));

            temperatureSummaryResult.Should().NotBeNull();
            temperatureSummaryResult.ResultStatus.Should().Be(RequestErrorStatus.OK);
            temperatureSummaryResult.ReturnCode.Should().Be(MissingTargetDataResultType.NoProblems);
            temperatureSummaryResult.MinimumTemperature.Should().Be(TARGET_TEMPERATURE_MIN);
            temperatureSummaryResult.MaximumTemperature.Should().Be(TARGET_TEMPERATURE_MAX);
            temperatureSummaryResult.IsTargetTemperatureConstant.Should().BeTrue();
            temperatureSummaryResult.Counts.Should().BeNull();
            temperatureSummaryResult.Percents.Should().BeNull();
            temperatureSummaryResult.BelowTargetPercent.Should().Be(0.0);
            temperatureSummaryResult.AboveTargetPercent.Should().Be(100.0);
            temperatureSummaryResult.WithinTargetPercent.Should().Be(0.0);
            temperatureSummaryResult.TotalAreaCoveredSqMeters.Should().BeApproximately(SubGridTreeConsts.DefaultCellSize * SubGridTreeConsts.DefaultCellSize, 0.000001);
        }
Ejemplo n.º 3
0
        public async Task Test_DetailedTemperatureStatistics_SiteModelWithSingleCell_FullExtents
            (ushort minTarget, ushort maxTarget, double percentBelow, double percentWithin, double percentAbove)
        {
            AddClusterComputeGridRouting();
            AddApplicationGridRouting();

            var siteModel = BuildModelForSingleCellTemperature(TEMPERATURE_INCREMENT);
            var operation = new TemperatureStatisticsOperation();

            var arg = SimpleTemperatureStatisticsArgument(siteModel, minTarget, maxTarget);

            arg.TemperatureDetailValues = new[] { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150 };
            var temperatureDetailResult = await operation.ExecuteAsync(arg);

            temperatureDetailResult.Should().NotBeNull();

            // Checks counts and percentages
            temperatureDetailResult.Counts.Sum().Should().Be(1);
            temperatureDetailResult.Counts[9].Should().Be(1);
            temperatureDetailResult.Percents.Sum().Should().BeApproximately(100.0, 0.000001);
            temperatureDetailResult.Percents[9].Should().BeApproximately(100.0, 0.000001);

            // Check summary related fields are zero
            temperatureDetailResult.ResultStatus.Should().Be(RequestErrorStatus.OK);
            temperatureDetailResult.ReturnCode.Should().Be(MissingTargetDataResultType.NoResult);
            temperatureDetailResult.MinimumTemperature.Should().Be(CellPassConsts.NullMaterialTemperatureValue);
            temperatureDetailResult.MaximumTemperature.Should().Be(CellPassConsts.NullMaterialTemperatureValue);
            temperatureDetailResult.IsTargetTemperatureConstant.Should().BeTrue();
            temperatureDetailResult.BelowTargetPercent.Should().BeApproximately(percentBelow, 0.001);
            temperatureDetailResult.AboveTargetPercent.Should().BeApproximately(percentAbove, 0.001);
            temperatureDetailResult.WithinTargetPercent.Should().BeApproximately(percentWithin, 0.001);
            temperatureDetailResult.TotalAreaCoveredSqMeters.Should().BeApproximately(0, 0.000001); // This being zero seems strange...
        }
Ejemplo n.º 4
0
        public async Task <JsonResult> GetTemperatureSummary([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);

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

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

                    if (result != null)
                    {
                        string resultString = $"<b>Temperature Summary Results (in {sw.Elapsed}) :</b><br/>";
                        resultString += "<b>================================================</b><br/>";
                        resultString += $"<b>Above Temperature Percentage:</b> {result.AboveTargetPercent}<br/>";
                        resultString += $"<b>Within Temperature Percentage Range:</b> {result.WithinTargetPercent}<br/>";
                        resultString += $"<b>Below Temperature Percentage:</b> {result.BelowTargetPercent}<br/>";
                        resultString += $"<b>Total Area Covered in Sq Meters:</b> {result.TotalAreaCoveredSqMeters}<br/>";

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

            return(new JsonResult(resultToReturn));
        }
Ejemplo n.º 5
0
        public async Task Test_SummaryTemperatureStatistics_EmptySiteModel_FullExtents_NoTemperatureTargetOverride()
        {
            AddClusterComputeGridRouting();
            AddApplicationGridRouting();

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

            var temperatureSummaryResult = await operation.ExecuteAsync(SimpleTemperatureStatisticsArgument(siteModel, 0, 0));

            temperatureSummaryResult.Should().NotBeNull();
            temperatureSummaryResult.ResultStatus.Should().Be(RequestErrorStatus.FailedToRequestDatamodelStatistics);
        }
Ejemplo n.º 6
0
        protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item)
        {
            var request = item as TemperatureDetailRequest;

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

            var siteModel = GetSiteModel(request.ProjectUid);

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

            var operation = new TemperatureStatisticsOperation();
            var temperatureDetailResult = await operation.ExecuteAsync(new TemperatureStatisticsArgument()
            {
                ProjectID = siteModel.ID,
                Filters   = new FilterSet(filter),
                TemperatureDetailValues = request.TemperatureList,
                LiftParams = ConvertLift(request.LiftSettings, request.Filter?.LayerType),
                Overrides  = AutoMapperUtility.Automapper.Map <OverrideParameters>(request.Overrides)
            });

            if (temperatureDetailResult != null)
            {
                if (temperatureDetailResult.ResultStatus == RequestErrorStatus.OK)
                {
                    return(new TemperatureDetailResult(new TemperatureTargetData()
                    {
                        MaxTemperatureMachineTarget = temperatureDetailResult.MaximumTemperature,
                        MinTemperatureMachineTarget = temperatureDetailResult.MinimumTemperature,
                        TargetVaries = temperatureDetailResult.IsTargetTemperatureConstant
                    },
                                                       temperatureDetailResult.Percents
                                                       ));
                }

                throw CreateServiceException <DetailedTemperatureExecutor>(temperatureDetailResult.ResultStatus);
            }

            throw CreateServiceException <DetailedTemperatureExecutor>();
        }
Ejemplo n.º 7
0
        public async Task Test_SummaryTemperatureStatistics_SiteModelWithSingleCell_FullExtents_NoTemperatureTargetOverride()
        {
            AddClusterComputeGridRouting();
            AddApplicationGridRouting();

            var siteModel = BuildModelForSingleCellTemperature(TEMPERATURE_INCREMENT);
            var operation = new TemperatureStatisticsOperation();

            var temperatureSummaryResult = await operation.ExecuteAsync(SimpleTemperatureStatisticsArgument(siteModel, 0, 0));

            temperatureSummaryResult.Should().NotBeNull();
            temperatureSummaryResult.ResultStatus.Should().Be(RequestErrorStatus.OK);
            temperatureSummaryResult.ReturnCode.Should().Be(MissingTargetDataResultType.NoResult);
            temperatureSummaryResult.MinimumTemperature.Should().Be(CellPassConsts.NullMaterialTemperatureValue);
            temperatureSummaryResult.MaximumTemperature.Should().Be(CellPassConsts.NullMaterialTemperatureValue);
            temperatureSummaryResult.IsTargetTemperatureConstant.Should().BeTrue();
            temperatureSummaryResult.Counts.Should().BeNull();
            temperatureSummaryResult.Percents.Should().BeNull();
            temperatureSummaryResult.AboveTargetPercent.Should().Be(0.0);
            temperatureSummaryResult.WithinTargetPercent.Should().Be(0.0);
            temperatureSummaryResult.BelowTargetPercent.Should().Be(0.0);
            temperatureSummaryResult.TotalAreaCoveredSqMeters.Should().Be(0.0);
        }
Ejemplo n.º 8
0
        public async Task Test_SummaryTemperatureStatistics_SiteModelWithSingleCell_FullExtents_WithTemperatureTargetOverrides
            (ushort minTarget, ushort maxTarget, double percentBelow, double percentWithin, double percentAbove)
        {
            AddClusterComputeGridRouting();
            AddApplicationGridRouting();

            var siteModel = BuildModelForSingleCellTemperature(TEMPERATURE_INCREMENT);
            var operation = new TemperatureStatisticsOperation();

            var temperatureSummaryResult = await operation.ExecuteAsync(SimpleTemperatureStatisticsArgument(siteModel, minTarget, maxTarget));

            temperatureSummaryResult.Should().NotBeNull();
            temperatureSummaryResult.ResultStatus.Should().Be(RequestErrorStatus.OK);
            temperatureSummaryResult.ReturnCode.Should().Be(MissingTargetDataResultType.NoProblems);
            temperatureSummaryResult.MinimumTemperature.Should().Be(minTarget);
            temperatureSummaryResult.MaximumTemperature.Should().Be(maxTarget);
            temperatureSummaryResult.IsTargetTemperatureConstant.Should().BeTrue();
            temperatureSummaryResult.Counts.Should().BeNull();
            temperatureSummaryResult.Percents.Should().BeNull();
            temperatureSummaryResult.BelowTargetPercent.Should().BeApproximately(percentBelow, 0.001);
            temperatureSummaryResult.AboveTargetPercent.Should().BeApproximately(percentAbove, 0.001);
            temperatureSummaryResult.WithinTargetPercent.Should().BeApproximately(percentWithin, 0.001);
            temperatureSummaryResult.TotalAreaCoveredSqMeters.Should().BeApproximately(SubGridTreeConsts.DefaultCellSize * SubGridTreeConsts.DefaultCellSize, 0.000001);
        }
Ejemplo n.º 9
0
        protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item)
        {
            var request = item as TemperatureSummaryRequest;

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

            var siteModel = GetSiteModel(request.ProjectUid);

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

            var operation = new TemperatureStatisticsOperation();
            var temperatureSummaryResult = await operation.ExecuteAsync(
                new TemperatureStatisticsArgument()
            {
                ProjectID  = siteModel.ID,
                Filters    = new FilterSet(filter),
                Overrides  = AutoMapperUtility.Automapper.Map <OverrideParameters>(request.Overrides),
                LiftParams = ConvertLift(request.LiftSettings, request.Filter?.LayerType)
            }
                );

            if (temperatureSummaryResult != null)
            {
                if (temperatureSummaryResult.ResultStatus == RequestErrorStatus.OK)
                {
                    return(ConvertResult(temperatureSummaryResult));
                }

                throw CreateServiceException <SummaryTemperatureExecutor>(temperatureSummaryResult.ResultStatus);
            }

            throw CreateServiceException <SummaryTemperatureExecutor>();
        }
Ejemplo n.º 10
0
        public async Task Test_DetailedTemperatureStatistics_SiteModelWithSingleTAGFile_FullExtents
            (ushort minTarget, ushort maxTarget, double percentBelow, double percentWithin, double percentAbove)
        {
            AddClusterComputeGridRouting();
            AddApplicationGridRouting();

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

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

            var arg = SimpleTemperatureStatisticsArgument(siteModel, minTarget, maxTarget);

            arg.TemperatureDetailValues = new[] { 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500 };
            var temperatureDetailResult = await operation.ExecuteAsync(arg);

            temperatureDetailResult.Should().NotBeNull();

            // Checks counts and percentages
            long[] expectedCounts    = { 0, 0, 231, 10, 7, 0, 8, 105, 275, 957, 1461, 0, 0, 0, 0 };
            long   expectedCountsSum = 0;

            for (int i = 0; i < expectedCounts.Length; i++)
            {
                expectedCountsSum += (i + 1) * expectedCounts[i];
            }

            // Is sum of counts the same?
            long TemperatureDetailResultSum = 0;

            for (int i = 0; i < temperatureDetailResult.Counts.Length; i++)
            {
                TemperatureDetailResultSum += (i + 1) * temperatureDetailResult.Counts[i];
            }

            TemperatureDetailResultSum.Should().Be(expectedCountsSum);

            // Are all counts the same and do percentages match?

            long totalCount = temperatureDetailResult.Counts.Sum();

            for (int i = 0; i < expectedCounts.Length; i++)
            {
                expectedCounts[i].Should().Be(temperatureDetailResult.Counts[i]);
                temperatureDetailResult.Percents[i].Should().BeApproximately(100.0 * expectedCounts[i] / (1.0 * totalCount), 0.001);
            }

            // Check summary related fields are zero
            temperatureDetailResult.ResultStatus.Should().Be(RequestErrorStatus.OK);
            temperatureDetailResult.ReturnCode.Should().Be(MissingTargetDataResultType.NoProblems);
            temperatureDetailResult.BelowTargetPercent.Should().BeApproximately(percentBelow, 0.001);
            temperatureDetailResult.AboveTargetPercent.Should().BeApproximately(percentAbove, 0.001);
            temperatureDetailResult.WithinTargetPercent.Should().BeApproximately(percentWithin, 0.001);
            temperatureDetailResult.TotalAreaCoveredSqMeters.Should().BeApproximately(3054 * SubGridTreeConsts.DefaultCellSize * SubGridTreeConsts.DefaultCellSize, 0.000001);
            temperatureDetailResult.MinimumTemperature.Should().Be(MACHINE_TARGET_MIN);
            temperatureDetailResult.MaximumTemperature.Should().Be(MACHINE_TARGET_MAX);
            temperatureDetailResult.IsTargetTemperatureConstant.Should().BeTrue();
        }
Ejemplo n.º 11
0
        public async Task <JsonResult> GetTemperatureDetails([FromRoute] string siteModelID, [FromBody] OverrideParameters overrides)
        {
            const int TEMP_DENOMINATOR = 10;
            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 temperatureBands = new[] { 0, 120, 140, 160, 4000 };

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

                    var operation = new TemperatureStatisticsOperation();
                    var result    = await operation.ExecuteAsync(
                        new TemperatureStatisticsArgument()
                    {
                        ProjectID = siteModel.ID,
                        Filters   = new FilterSet()
                        {
                            Filters = new[] { new CombinedFilter() }
                        },
                        TemperatureDetailValues = temperatureBands,
                        Overrides = overrides
                    }
                        );

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

                        var anyTwoDigitsNumber   = temperatureBands.ToList().Find(s => (s / TEMP_DENOMINATOR) >= TWO_DIGITS_NUMBER && (s / TEMP_DENOMINATOR) < THREE_DIGITS_NUMBER);
                        var anyThreeDigitsNumber = temperatureBands.ToList().Find(s => (s / TEMP_DENOMINATOR) >= THREE_DIGITS_NUMBER);

                        for (int i = 0; i < temperatureBands.Length; i++)
                        {
                            string space = anyThreeDigitsNumber > 0 && temperatureBands[i] / TEMP_DENOMINATOR < THREE_DIGITS_NUMBER ? "&nbsp;&nbsp;" : string.Empty;

                            if (anyTwoDigitsNumber > 0 && temperatureBands[i] / TEMP_DENOMINATOR < TWO_DIGITS_NUMBER)
                            {
                                space += "&nbsp;&nbsp;";
                            }

                            resultString += $"<b>{space}{(temperatureBands[i] / TEMP_DENOMINATOR):##0.0}</b> - {result.Percents[i]:##0.#0}%<br/>";
                        }

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

            return(new JsonResult(resultToReturn));
        }