private void CheckResponseContainsNullValues(SimpleVolumesResponse response) { response.Should().NotBeNull(); response.Cut.Should().BeNull(); response.Fill.Should().BeNull(); response.CutArea.Should().BeNull(); response.FillArea.Should().BeNull(); response.TotalCoverageArea.Should().BeNull(); response.BoundingExtentGrid.Should().BeEquivalentTo(BoundingWorldExtent3D.Null()); }
private void CheckResponseContainsNullValues(ProgressiveVolumesResponse response) { response.Should().NotBeNull(); if (response.Volumes == null) { return; } foreach (var volume in response.Volumes) { volume.Volume.BoundingExtentGrid.Should().BeEquivalentTo(BoundingWorldExtent3D.Null()); volume.Volume.BoundingExtentLLH.Should().BeEquivalentTo(BoundingWorldExtent3D.Null()); } }
public void Remove() { var manager = new SurveyedSurfaceManager(StorageMutability.Mutable); var siteModelUid = Guid.NewGuid(); manager.Add(siteModelUid, DesignDescriptor.Null(), DateTime.UtcNow, BoundingWorldExtent3D.Null(), new SubGridTreeSubGridExistenceBitMask()); var results = manager.List(siteModelUid); results.Should().NotBeNull(); results.Count.Should().Be(1); manager.Remove(siteModelUid, results[0].ID).Should().BeTrue(); manager.List(siteModelUid).Count.Should().Be(0); }
public void Test_RequestAnalyser_NullOrInvertedSpatialExtents_YieldsNoSubGrids() { var prodDataExistenceMap = new SubGridTreeSubGridExistenceBitMask(); var PipeLine = new SubGridPipelineProgressive <SubGridsRequestArgument, SubGridRequestsResponse>(null) { FilterSet = new FilterSet(new CombinedFilter()), ProdDataExistenceMap = prodDataExistenceMap, OverallExistenceMap = prodDataExistenceMap }; var analyser = new RequestAnalyser(PipeLine, BoundingWorldExtent3D.Null()); Assert.Equal(0, analyser.CountOfSubGridsThatWillBeSubmitted()); analyser = new RequestAnalyser(PipeLine, BoundingWorldExtent3D.Inverted()); Assert.Equal(0, analyser.CountOfSubGridsThatWillBeSubmitted()); }
public void NewInstance() { var factory = new SurveyedSurfaceFactory(); var instance = factory.NewInstance(Guid.NewGuid(), DesignDescriptor.Null(), Consts.MIN_DATETIME_AS_UTC, BoundingWorldExtent3D.Null()); instance.Should().NotBeNull(); instance.Should().BeAssignableTo <ISurveyedSurface>(); }
/// <summary> /// Executes the progressive volumes computation returning a ProgressiveVolumesResponse with the results /// </summary> public async Task <ProgressiveVolumesResponse> ExecuteAsync() { var volumesResult = new ProgressiveVolumesResponse(); var resultBoundingExtents = BoundingWorldExtent3D.Null(); var requestDescriptor = Guid.NewGuid(); // TODO ASNodeImplInstance.NextDescriptor; _log.LogInformation($"#In# Performing {nameof(ComputeProgressiveVolumes_Coordinator)}.Execute for DataModel:{SiteModelID}"); try { try { ApplicationServiceRequestStatistics.Instance.NumProgressiveVolumeRequests.Increment(); // Prepare filter for use in the request var resultStatus = FilterUtilities.PrepareFiltersForUse(new[] { Filter, AdditionalSpatialFilter }, SiteModelID); if (resultStatus != RequestErrorStatus.OK) { return(volumesResult); } // Obtain the site model context for the request _siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(SiteModelID); if (_siteModel == null) { return(volumesResult); } // Determine the number of progressions that are required and establish the required aggregation states in the aggregator var numProgressions = (int)((EndDate.Ticks - StartDate.Ticks) / Interval.Ticks); if ((EndDate.Ticks - StartDate.Ticks) % Interval.Ticks == 0) { numProgressions++; } if (VolumeType == VolumeComputationType.Between2Filters) { // One fewer progressions will be calculated as each volume in the progression is computed across the interval of two // surfaces derived from production data. numProgressions--; } if (numProgressions > ClientProgressiveHeightsLeafSubGrid.MaxNumberOfHeightLayers) { throw new ArgumentException($"No more than {ClientProgressiveHeightsLeafSubGrid.MaxNumberOfHeightLayers} height layers may be requested at one time"); } // Create and configure the aggregator that contains the business logic for the underlying volume calculation Aggregator = new ProgressiveVolumesCalculationsAggregator { SiteModel = _siteModel, LiftParams = _liftParams, CellSize = _siteModel.CellSize, VolumeType = VolumeType, CutTolerance = CutTolerance, FillTolerance = FillTolerance, AggregationStates = Enumerable .Range(VolumeType == VolumeComputationType.Between2Filters ? 1 : 0, numProgressions) .Select(x => StartDate + x * Interval) .Select(d => new ProgressiveVolumeAggregationState(_siteModel.CellSize) { Date = d, CutTolerance = CutTolerance, FillTolerance = FillTolerance }).ToArray() }; // Create and configure the volumes calculation engine var computeVolumes = new ProgressiveVolumesCalculator { RequestDescriptor = requestDescriptor, SiteModel = _siteModel, Aggregator = Aggregator, Filter = Filter, VolumeType = VolumeType, LiftParams = _liftParams, StartDate = StartDate, EndDate = EndDate, Interval = Interval }; InitialiseVolumesCalculator(computeVolumes); // Perform the volume computation if (computeVolumes.ComputeVolumeInformation()) { resultStatus = RequestErrorStatus.OK; } else { resultStatus = computeVolumes.AbortedDueToTimeout ? RequestErrorStatus.AbortedDueToPipelineTimeout : RequestErrorStatus.Unknown; } if (resultStatus != RequestErrorStatus.OK) { _log.LogInformation($"Progressive volume result: Failure, error = {resultStatus}"); // Send the (empty) results back to the caller return(volumesResult); } // Instruct the Aggregator to perform any finalization logic before reading out the results Aggregator.Finalise(); var noProductionDataCount = 0; var invalidPlanExtentsCount = 0; foreach (var state in Aggregator.AggregationStates) { _log.LogInformation($"#Result# Progressive volume result: Cut={state.CutFillVolume.CutVolume:F3}, Fill={state.CutFillVolume.FillVolume:F3}, Area={state.CoverageArea:F3}"); if (!state.BoundingExtents.IsValidPlanExtent) { if (state.CoverageArea == 0 && state.CutFillVolume.CutVolume == 0 && state.CutFillVolume.FillVolume == 0) { noProductionDataCount++; } else { invalidPlanExtentsCount++; } } } if (noProductionDataCount == Aggregator.AggregationStates.Length) { resultStatus = RequestErrorStatus.NoProductionDataFound; } else if (invalidPlanExtentsCount == Aggregator.AggregationStates.Length) { resultStatus = RequestErrorStatus.InvalidPlanExtents; } if (resultStatus == RequestErrorStatus.NoProductionDataFound || resultStatus == RequestErrorStatus.InvalidPlanExtents) { _log.LogInformation($"Progressive volume invalid plan extents or no data found: {resultStatus}"); } volumesResult.ResultStatus = resultStatus; if (resultStatus == RequestErrorStatus.OK) { volumesResult.Volumes = Aggregator.AggregationStates.Select(aggregator => new ProgressiveVolumeResponseItem { Date = aggregator.Date, Volume = new SimpleVolumesResponse { Cut = aggregator.CutFillVolume.CutVolume, Fill = aggregator.CutFillVolume.FillVolume, TotalCoverageArea = aggregator.CoverageArea, CutArea = aggregator.CutArea, FillArea = aggregator.FillArea, BoundingExtentGrid = aggregator.BoundingExtents, BoundingExtentLLH = resultBoundingExtents } }).ToArray(); } } finally { ApplicationServiceRequestStatistics.Instance.NumProgressiveVolumeRequestsCompleted.Increment(); if (volumesResult.ResultStatus != RequestErrorStatus.OK) { ApplicationServiceRequestStatistics.Instance.NumProgressiveVolumeRequestsFailed.Increment(); } } } catch (Exception e) { _log.LogError(e, $"Failed to compute the progressive volumes. Site Model ID: {SiteModelID}"); } return(volumesResult); }
public void Add_FailWithNonUTCDate() { var manager = new SurveyedSurfaceManager(StorageMutability.Mutable); var siteModelUid = Guid.NewGuid(); var designUid = Guid.NewGuid(); Action act = () => manager.Add(siteModelUid, new DesignDescriptor(designUid, "", ""), DateTime.Now, BoundingWorldExtent3D.Null(), new SubGridTreeSubGridExistenceBitMask()); act.Should().Throw <ArgumentException>().WithMessage("AsAtDate must be a UTC date time"); }
public void Test_Null() { var bound = BoundingWorldExtent3D.Null(); bound.Equals(new BoundingWorldExtent3D(Consts.NullDouble, Consts.NullDouble, Consts.NullDouble, Consts.NullDouble, Consts.NullDouble, Consts.NullDouble)).Should().BeTrue(); }
/// <summary> /// Executes the simple volumes computation returning a SimpleVolumesResponse with the results /// </summary> public SimpleVolumesResponse Execute() { var volumesResult = new SimpleVolumesResponse(); var resultBoundingExtents = BoundingWorldExtent3D.Null(); var requestDescriptor = Guid.NewGuid(); // TODO ASNodeImplInstance.NextDescriptor; Log.LogInformation($"#In# Performing {nameof(ComputeSimpleVolumes_Coordinator)}.Execute for DataModel:{SiteModelID}"); try { try { ApplicationServiceRequestStatistics.Instance.NumSimpleVolumeRequests.Increment(); // Prepare filters for use in the request var resultStatus = FilterUtilities.PrepareFiltersForUse(new[] { BaseFilter, TopFilter, AdditionalSpatialFilter }, SiteModelID); if (resultStatus != RequestErrorStatus.OK) { return(volumesResult); } // Obtain the site model context for the request siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(SiteModelID); if (siteModel == null) { return(volumesResult); } // Create and configure the aggregator that contains the business logic for the // underlying volume calculation Aggregator = new SimpleVolumesCalculationsAggregator { SiteModel = siteModel, LiftParams = LiftParams, CellSize = siteModel.CellSize, VolumeType = VolumeType, CutTolerance = CutTolerance, FillTolerance = FillTolerance }; // Create and configure the volumes calculation engine var computeVolumes = new VolumesCalculator { RequestDescriptor = requestDescriptor, SiteModel = siteModel, Aggregator = Aggregator, BaseFilter = BaseFilter, TopFilter = TopFilter, VolumeType = VolumeType, LiftParams = LiftParams }; InitialiseVolumesCalculator(computeVolumes); // Perform the volume computation if (computeVolumes.ComputeVolumeInformation()) { resultStatus = RequestErrorStatus.OK; } else if (computeVolumes.AbortedDueToTimeout) { resultStatus = RequestErrorStatus.AbortedDueToPipelineTimeout; } else { resultStatus = RequestErrorStatus.Unknown; } if (resultStatus != RequestErrorStatus.OK) { Log.LogInformation($"Summary volume result: Failure, error = {resultStatus}"); // Send the (empty) results back to the caller return(volumesResult); } // Instruct the Aggregator to perform any finalization logic before reading out the results Aggregator.Finalise(); Log.LogInformation($"#Result# Summary volume result: Cut={Aggregator.CutFillVolume.CutVolume:F3}, Fill={Aggregator.CutFillVolume.FillVolume:F3}, Area={Aggregator.CoverageArea:F3}"); if (!Aggregator.BoundingExtents.IsValidPlanExtent) { if (Aggregator.CoverageArea == 0 && Aggregator.CutFillVolume.CutVolume == 0 && Aggregator.CutFillVolume.FillVolume == 0) { resultStatus = RequestErrorStatus.NoProductionDataFound; } else { resultStatus = RequestErrorStatus.InvalidPlanExtents; } Log.LogInformation($"Summary volume invalid PlanExtents or no data found: {resultStatus}"); return(volumesResult); } // Fill in the result object to pass back to the caller volumesResult.Cut = Aggregator.CutFillVolume.CutVolume; volumesResult.Fill = Aggregator.CutFillVolume.FillVolume; volumesResult.TotalCoverageArea = Aggregator.CoverageArea; volumesResult.CutArea = Aggregator.CutArea; volumesResult.FillArea = Aggregator.FillArea; volumesResult.BoundingExtentGrid = Aggregator.BoundingExtents; volumesResult.BoundingExtentLLH = resultBoundingExtents; } finally { ApplicationServiceRequestStatistics.Instance.NumSimpleVolumeRequestsCompleted.Increment(); if (volumesResult.ResponseCode != SubGridRequestsResponseResult.OK) { ApplicationServiceRequestStatistics.Instance.NumSimpleVolumeRequestsFailed.Increment(); } } } catch (Exception e) { Log.LogError(e, $"Failed to compute the simple volumes. Site Model ID: {SiteModelID}"); } return(volumesResult); }
public void Test_SiteModel_Serialization_NewModelWithSingleElements() { var guid = Guid.NewGuid(); var siteModel = new SiteModel(guid, StorageMutability.Immutable, 1.23); siteModel.SiteModelExtent.SetMaximalCoverage(); siteModel.Machines.CreateNew("Test Machine", "HardwareID", MachineType.AsphaltCompactor, 0, false, Guid.NewGuid()); siteModel.Alignments.AddAlignmentDetails(Guid.NewGuid(), DesignDescriptor.Null(), BoundingWorldExtent3D.Null()); siteModel.Designs.AddDesignDetails(Guid.NewGuid(), DesignDescriptor.Null(), BoundingWorldExtent3D.Null()); siteModel.SurveyedSurfaces.AddSurveyedSurfaceDetails(Guid.NewGuid(), DesignDescriptor.Null(), DateTime.UtcNow, BoundingWorldExtent3D.Null()); var metaData = siteModel.MetaData; metaData.ID.Should().Be(guid); metaData.LastModifiedDate.Should().Be(siteModel.LastModifiedDate); metaData.CreationDate.Should().Be(siteModel.CreationDate); metaData.AlignmentCount.Should().Be(1); metaData.DesignCount.Should().Be(1); metaData.SiteModelExtent.Should().BeEquivalentTo(siteModel.SiteModelExtent); metaData.MachineCount.Should().Be(1); metaData.SurveyedSurfaceCount.Should().Be(1); }
public void Test_RequestorUtilities_CreateIntermediaries_SingleDefaultFilter_WithSurveyedSurfaces() { var ru = new RequestorUtilities(); Guid ssGuid = Guid.NewGuid(); ISurveyedSurfaces surveyedSurfaces = DIContext.Obtain <ISurveyedSurfaces>(); surveyedSurfaces.AddSurveyedSurfaceDetails(ssGuid, DesignDescriptor.Null(), TRex.Common.Consts.MIN_DATETIME_AS_UTC, BoundingWorldExtent3D.Null()); var mockGrid = new Mock <IServerSubGridTree>(); mockGrid.Setup(x => x.CellSize).Returns(SubGridTreeConsts.DefaultCellSize); var mockSiteModel = new Mock <ISiteModel>(); mockSiteModel.Setup(x => x.SurveyedSurfacesLoaded).Returns(true); mockSiteModel.Setup(x => x.SurveyedSurfaces).Returns(surveyedSurfaces); mockSiteModel.Setup(x => x.Grid).Returns(mockGrid.Object); ICombinedFilter filter = new CombinedFilter(); IFilterSet filters = new FilterSet(filter); var intermediaries = ru.ConstructRequestorIntermediaries(mockSiteModel.Object, filters, true, GridDataType.Height); intermediaries.Length.Should().Be(1); intermediaries[0].Filter.Should().Be(filter); intermediaries[0].FilteredSurveyedSurfaces.Should().Equal(surveyedSurfaces); intermediaries[0].CacheContexts[0].Should().Be(_fixture.TRexSpatialMemoryCacheContext); intermediaries[0].surfaceElevationPatchRequest.Should().Be(_fixture.SurfaceElevationPatchRequest); }
public void Test_RequestorUtilities_CreateRequestors_DefaultFilters(int filterCount) { var ru = new RequestorUtilities(); ISurveyedSurfaces surveyedSurfaces = DIContext.Obtain <ISurveyedSurfaces>(); // Create two surveyed surfaces that bracket current time by one day either side and set the filter end time to be current time // which will cause only one surveyed surface to be filtered Guid ssGuid1 = Guid.NewGuid(); var ss1 = surveyedSurfaces.AddSurveyedSurfaceDetails(ssGuid1, DesignDescriptor.Null(), Consts.MIN_DATETIME_AS_UTC, BoundingWorldExtent3D.Null()); var mockGrid = new Mock <IServerSubGridTree>(); mockGrid.Setup(x => x.CellSize).Returns(SubGridTreeConsts.DefaultCellSize); var mockSiteModel = new Mock <ISiteModel>(); mockSiteModel.Setup(x => x.SurveyedSurfacesLoaded).Returns(true); mockSiteModel.Setup(x => x.SurveyedSurfaces).Returns(surveyedSurfaces); mockSiteModel.Setup(x => x.Grid).Returns(mockGrid.Object); ICombinedFilter[] filters = Enumerable.Range(1, filterCount).Select(x => new CombinedFilter()).ToArray(); IFilterSet filterSet = new FilterSet(filters); var intermediaries = ru.ConstructRequestorIntermediaries(mockSiteModel.Object, filterSet, true, GridDataType.Height); var requestors = ru.ConstructRequestors(new SubGridsRequestArgument(), mockSiteModel.Object, new OverrideParameters(), new LiftParameters(), intermediaries, AreaControlSet.CreateAreaControlSet(), null); requestors.Length.Should().Be(filters.Length); for (var i = 0; i < requestors.Length; i++) { requestors[i].CellOverrideMask.Should().NotBe(null); } }
public void Test_RequestorUtilities_CreateIntermediaries_MultipleFilters_WithOneOfTwoSurveyedSurfacesFilteredByTime_NoSurveyedSurfaceExclusions(int filterCount) { var ru = new RequestorUtilities(); ISurveyedSurfaces surveyedSurfaces = DIContext.Obtain <ISurveyedSurfaces>(); // Create two surveyed surfaces that bracket current time by one day either side and set the filter end time to be current time // which will cause only one surveyed surface to be filtered Guid ssGuid1 = Guid.NewGuid(); var ss1 = surveyedSurfaces.AddSurveyedSurfaceDetails(ssGuid1, DesignDescriptor.Null(), DateTime.UtcNow.AddDays(-1), BoundingWorldExtent3D.Null()); Guid ssGuid2 = Guid.NewGuid(); var ss2 = surveyedSurfaces.AddSurveyedSurfaceDetails(ssGuid2, DesignDescriptor.Null(), DateTime.UtcNow.AddDays(+1), BoundingWorldExtent3D.Null()); var mockGrid = new Mock <IServerSubGridTree>(); mockGrid.Setup(x => x.CellSize).Returns(SubGridTreeConsts.DefaultCellSize); var mockSiteModel = new Mock <ISiteModel>(); mockSiteModel.Setup(x => x.SurveyedSurfacesLoaded).Returns(true); mockSiteModel.Setup(x => x.SurveyedSurfaces).Returns(surveyedSurfaces); mockSiteModel.Setup(x => x.Grid).Returns(mockGrid.Object); ICombinedFilter[] filters = Enumerable.Range(1, filterCount).Select(x => { var filter = new CombinedFilter { AttributeFilter = { HasTimeFilter = true, StartTime = Consts.MIN_DATETIME_AS_UTC, EndTime = DateTime.UtcNow } }; return(filter); }).ToArray(); IFilterSet filterSet = new FilterSet(filters); var intermediaries = ru.ConstructRequestorIntermediaries(mockSiteModel.Object, filterSet, true, GridDataType.Height); intermediaries.Length.Should().Be(filters.Length); for (int i = 0; i < intermediaries.Length; i++) { intermediaries[i].Filter.Should().Be(filters[i]); intermediaries[i].FilteredSurveyedSurfaces.Should().Equal(new List <ISurveyedSurface> { ss1 }); intermediaries[i].CacheContexts[0].Should().NotBeNull(); intermediaries[i].surfaceElevationPatchRequest.Should().Be(_fixture.SurfaceElevationPatchRequest); } }
public void Test_RequestorUtilities_CreateIntermediaries_MultipleFilters_WithSingleExcludedSurveyedSurface(int filterCount) { var ru = new RequestorUtilities(); Guid ssGuid = Guid.NewGuid(); ISurveyedSurfaces surveyedSurfaces = DIContext.Obtain <ISurveyedSurfaces>(); surveyedSurfaces.AddSurveyedSurfaceDetails(ssGuid, DesignDescriptor.Null(), Consts.MIN_DATETIME_AS_UTC, BoundingWorldExtent3D.Null()); var mockGrid = new Mock <IServerSubGridTree>(); mockGrid.Setup(x => x.CellSize).Returns(SubGridTreeConsts.DefaultCellSize); var mockSiteModel = new Mock <ISiteModel>(); mockSiteModel.Setup(x => x.SurveyedSurfacesLoaded).Returns(true); mockSiteModel.Setup(x => x.SurveyedSurfaces).Returns(surveyedSurfaces); mockSiteModel.Setup(x => x.Grid).Returns(mockGrid.Object); ICombinedFilter[] filters = Enumerable.Range(1, filterCount).Select(x => { var filter = new CombinedFilter(); filter.AttributeFilter.SurveyedSurfaceExclusionList = new[] { ssGuid }; return(filter); }).ToArray(); IFilterSet filterSet = new FilterSet(filters); var intermediaries = ru.ConstructRequestorIntermediaries(mockSiteModel.Object, filterSet, true, GridDataType.Height); intermediaries.Length.Should().Be(filters.Length); for (int i = 0; i < intermediaries.Length; i++) { intermediaries[i].Filter.Should().Be(filters[i]); intermediaries[i].FilteredSurveyedSurfaces.Should().BeEmpty(); intermediaries[i].CacheContexts[0].Should().NotBeNull(); intermediaries[i].surfaceElevationPatchRequest.Should().Be(_fixture.SurfaceElevationPatchRequest); } }
private ISiteModel BuildModelForProductionDataAndOrSurveyedSurface(DateTime baseTime, int?totalMins, int?ssMins) { var siteModel = DITAGFileAndSubGridRequestsWithIgniteFixture.NewEmptyModel(); if (totalMins.HasValue) { var bulldozerMachineIndex = siteModel.Machines.Locate("Bulldozer", false).InternalSiteModelMachineIndex; // Ensure the machine has start and stop events (don't need actual cell passes) siteModel.MachinesTargetValues[bulldozerMachineIndex].StartEndRecordedDataEvents.PutValueAtDate(baseTime, ProductionEventType.StartEvent); siteModel.MachinesTargetValues[bulldozerMachineIndex].StartEndRecordedDataEvents.PutValueAtDate(baseTime.AddMinutes(totalMins.Value), ProductionEventType.EndEvent); siteModel.MachinesTargetValues[bulldozerMachineIndex].SaveMachineEventsToPersistentStore(siteModel.PrimaryStorageProxy); } if (ssMins.HasValue) { siteModel.SurveyedSurfaces.AddSurveyedSurfaceDetails(Guid.NewGuid(), DesignDescriptor.Null(), baseTime.AddMinutes(ssMins.Value), BoundingWorldExtent3D.Null()); } DITAGFileAndSubGridRequestsFixture.ConvertSiteModelToImmutable(siteModel); return(siteModel); }