/// <summary> /// Performs functional initialization of ComputeVolumes state that is dependent on the initial state /// set via the constructor /// </summary> private void InitialiseVolumesCalculator(VolumesCalculator computeVolumes) { // Set up the volumes calc parameters VolumesUtilities.SetProdReportSelectionType(VolumeType, out var fromSelectionType, out var toSelectionType); computeVolumes.FromSelectionType = fromSelectionType; computeVolumes.ToSelectionType = toSelectionType; computeVolumes.UseEarliestData = BaseFilter.AttributeFilter.ReturnEarliestFilteredCellPass; computeVolumes.RefOriginal = BaseDesign == null || BaseDesign.DesignID == Guid.Empty ? null : siteModel.Designs.Locate(BaseDesign.DesignID); computeVolumes.RefDesign = TopDesign == null || TopDesign.DesignID == Guid.Empty ? null : siteModel.Designs.Locate(TopDesign.DesignID); if (computeVolumes.FromSelectionType == ProdReportSelectionType.Surface) { computeVolumes.ActiveDesign = computeVolumes.RefOriginal != null ? new DesignWrapper(BaseDesign, computeVolumes.RefOriginal) : null; } else { computeVolumes.ActiveDesign = computeVolumes.ToSelectionType == ProdReportSelectionType.Surface && computeVolumes.RefDesign != null ? new DesignWrapper(TopDesign, computeVolumes.RefDesign) : null; } // Assign the active design into the aggregator for use Aggregator.ActiveDesign = computeVolumes.ActiveDesign; }
/// <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); }