Example #1
0
        /// <summary>
        /// Given a design used as an elevation range filter aspect, retrieve the existence map for the design and
        /// includes it in the supplied overall existence map for the query
        /// </summary>
        public static bool ProcessDesignElevationsForFilter(ISiteModel siteModel, //Guid siteModelID,
                                                            ICombinedFilter filter,
                                                            ISubGridTreeBitMask overallExistenceMap)
        {
            if (filter == null)
            {
                return(true);
            }

            if (overallExistenceMap == null)
            {
                return(false);
            }

            if (filter.AttributeFilter.HasElevationRangeFilter && filter.AttributeFilter.ElevationRangeDesign.DesignID != Guid.Empty)
            {
                var designExistenceMap = DIContext.Obtain <IExistenceMaps>().GetSingleExistenceMap
                                             (siteModel.ID, Consts.EXISTENCE_MAP_DESIGN_DESCRIPTOR, filter.AttributeFilter.ElevationRangeDesign.DesignID);

                if (designExistenceMap != null)
                {
                    // Not sure this is really needed...
                    designExistenceMap.CellSize = SubGridTreeConsts.SubGridTreeDimension * siteModel.CellSize;
                    overallExistenceMap.SetOp_OR(designExistenceMap);
                }
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Perform the request extracting all required existence maps and combine them together
        /// </summary>
        public ISubGridTreeBitMask Execute(INonSpatialAffinityKey[] keys)
        {
            ISubGridTreeBitMask combinedMask = null;

            foreach (var key in keys)
            {
                var Mask = _singleRequest.Execute(key);

                if (Mask != null)
                {
                    if (combinedMask == null)
                    {
                        combinedMask = Mask;
                    }
                    else
                    {
                        combinedMask.SetOp_OR(Mask);
                    }
                }
            }

            return(combinedMask);
        }
Example #3
0
        /// <summary>
        /// Given a filter compute which of the surfaces in the list match any given time aspect
        /// of the filter, and the overall existence map of the surveyed surfaces that match the filter.
        /// ComparisonList denotes a possibly pre-filtered set of surfaces for another filter; if this is the same as the
        /// filtered set of surfaces then the overall existence map for those surfaces will not be computed as it is
        /// assumed to be the same.
        /// </summary>
        public bool ProcessSurveyedSurfacesForFilter(Guid siteModelId,
                                                     ICombinedFilter filter,
                                                     ISurveyedSurfaces comparisonList,
                                                     ISurveyedSurfaces filteredSurveyedSurfaces,
                                                     ISubGridTreeBitMask overallExistenceMap)
        {
            // Filter out any surveyed surfaces which don't match current filter (if any) - realistically, this is time filters we're thinking of here
            FilterSurveyedSurfaceDetails(filter.AttributeFilter.HasTimeFilter,
                                         filter.AttributeFilter.StartTime, filter.AttributeFilter.EndTime,
                                         filter.AttributeFilter.ExcludeSurveyedSurfaces(),
                                         filteredSurveyedSurfaces,
                                         filter.AttributeFilter.SurveyedSurfaceExclusionList);

            if (filteredSurveyedSurfaces != null)
            {
                if (filteredSurveyedSurfaces.IsSameAs(comparisonList))
                {
                    return(true);
                }

                if (filteredSurveyedSurfaces.Count > 0)
                {
                    var surveyedSurfaceExistenceMap = GetExistenceMaps().GetCombinedExistenceMap(siteModelId,
                                                                                                 filteredSurveyedSurfaces.Select(x => new Tuple <long, Guid>(Consts.EXISTENCE_SURVEYED_SURFACE_DESCRIPTOR, x.ID)).ToArray());

                    if (overallExistenceMap == null)
                    {
                        return(false);
                    }

                    overallExistenceMap.SetOp_OR(surveyedSurfaceExistenceMap);
                }
            }

            return(true);
        }
Example #4
0
        public RequestErrorStatus ExecutePipeline()
        {
            SubGridPipelineAggregative <SubGridsRequestArgument, SimpleVolumesResponse> PipeLine;

            var Result = RequestErrorStatus.Unknown;

            var PipelineAborted = false;

            // bool ShouldAbortDueToCompletedEventSet  = false;

            try
            {
                ProdDataExistenceMap = SiteModel.ExistenceMap;

                try
                {
                    if (ActiveDesign != null && (VolumeType == VolumeComputationType.BetweenFilterAndDesign || VolumeType == VolumeComputationType.BetweenDesignAndFilter))
                    {
                        if (ActiveDesign == null || ActiveDesign.Design.DesignDescriptor.IsNull)
                        {
                            Log.LogError($"No design provided to prod data/design volumes calc for datamodel {SiteModel.ID}");
                            return(RequestErrorStatus.NoDesignProvided);
                        }

                        DesignSubgridOverlayMap = GetExistenceMaps().GetSingleExistenceMap(SiteModel.ID, ExistenceMaps.Interfaces.Consts.EXISTENCE_MAP_DESIGN_DESCRIPTOR, ActiveDesign.Design.ID);

                        if (DesignSubgridOverlayMap == null)
                        {
                            return(RequestErrorStatus.NoDesignProvided);
                        }
                    }

                    OverallExistenceMap = new SubGridTreeSubGridExistenceBitMask();

                    // Work out the surveyed surfaces and coverage areas that need to be taken into account

                    var SurveyedSurfaces = SiteModel.SurveyedSurfaces;

                    if (SurveyedSurfaces != null)
                    {
                        // See if we need to handle surveyed surface data for 'base'
                        // Filter out any surveyed surfaces which don't match current filter (if any) - realistically, this is time filters we're thinking of here
                        if (VolumeType == VolumeComputationType.Between2Filters || VolumeType == VolumeComputationType.BetweenFilterAndDesign)
                        {
                            if (!SurveyedSurfaces.ProcessSurveyedSurfacesForFilter(SiteModel.ID, BaseFilter, FilteredTopSurveyedSurfaces, FilteredBaseSurveyedSurfaces, OverallExistenceMap))
                            {
                                return(RequestErrorStatus.Unknown);
                            }
                        }

                        // See if we need to handle surveyed surface data for 'top'
                        // Filter out any surveyed surfaces which don't match current filter (if any) - realistically, this is time filters we're thinking of here
                        if (VolumeType == VolumeComputationType.Between2Filters || VolumeType == VolumeComputationType.BetweenDesignAndFilter)
                        {
                            if (!SurveyedSurfaces.ProcessSurveyedSurfacesForFilter(SiteModel.ID, TopFilter, FilteredBaseSurveyedSurfaces, FilteredTopSurveyedSurfaces, OverallExistenceMap))
                            {
                                return(RequestErrorStatus.Unknown);
                            }
                        }
                    }

                    // Add in the production data existence map to the computed surveyed surfaces existence maps
                    OverallExistenceMap.SetOp_OR(ProdDataExistenceMap);

                    // If necessary, impose spatial constraints from filter design(s)
                    if (VolumeType == VolumeComputationType.Between2Filters || VolumeType == VolumeComputationType.BetweenFilterAndDesign)
                    {
                        if (!DesignFilterUtilities.ProcessDesignElevationsForFilter(SiteModel, BaseFilter, OverallExistenceMap))
                        {
                            return(RequestErrorStatus.Unknown);
                        }
                    }

                    if (VolumeType == VolumeComputationType.Between2Filters || VolumeType == VolumeComputationType.BetweenDesignAndFilter)
                    {
                        if (!DesignFilterUtilities.ProcessDesignElevationsForFilter(SiteModel, TopFilter, OverallExistenceMap))
                        {
                            return(RequestErrorStatus.Unknown);
                        }
                    }

                    var PipelinedTask = new VolumesComputationTask
                    {
                        Aggregator = Aggregator
                    };

                    try
                    {
                        PipeLine = new SubGridPipelineAggregative <SubGridsRequestArgument, SimpleVolumesResponse>(/*0, */ PipelinedTask);
                        PipelinedTask.PipeLine = PipeLine;

                        ConfigurePipeline(PipeLine);

                        if (PipeLine.Initiate())
                        {
                            var completionResult = PipeLine.WaitForCompletion();
                            Log.LogInformation(completionResult ? "WaitForCompletion successful" : $"WaitForCompletion timed out with {PipeLine.SubGridsRemainingToProcess} sub grids remaining to be processed");

                            if (PipeLine.SubGridsRemainingToProcess > 0)
                            {
                                Log.LogInformation($"Pipeline completed with {PipeLine.SubGridsRemainingToProcess} sub grids remaining to be processed");
                            }
                        }

                        /*
                         * while not FPipeLine.AllFinished and not FPipeLine.PipelineAborted do
                         * begin
                         *  WaitResult := FPipeLine.CompleteEvent.WaitFor(5000);
                         *
                         *  if VLPDSvcLocations.Debug_EmitSubgridPipelineProgressLogging then
                         *    begin
                         *      if ((FEpochCount > 0) or (FPipeLine.SubmissionNode.TotalNumberOfSubgridsScanned > 0)) and
                         *         ((FPipeLine.OperationNode.NumPendingResultsReceived > 0) or (FPipeLine.OperationNode.OustandingSubgridsToOperateOn > 0)) then
                         *        SIGLogMessage.PublishNoODS(Self, Format('%s: Pipeline (request %d, model %d): #Progress# - Scanned = %d, Submitted = %d, Processed = %d (with %d pending and %d results outstanding)',
                         *                                                [Self.ClassName,
                         *                                                 FRequestDescriptor, FPipeline.ProjectUid,
                         *                                                 FPipeLine.SubmissionNode.TotalNumberOfSubgridsScanned,
                         *                                                 FPipeLine.SubmissionNode.TotalSumbittedSubgridRequests,
                         *                                                 FPipeLine.OperationNode.TotalOperatedOnSubgrids,
                         *                                                 FPipeLine.OperationNode.NumPendingResultsReceived,
                         *                                                 FPipeLine.OperationNode.OustandingSubgridsToOperateOn]), slmcDebug);
                         *    end;
                         *
                         *  if (WaitResult = wrSignaled) and not FPipeLine.AllFinished and not FPipeLine.PipelineAborted and not FPipeLine.Terminated then
                         *    begin
                         *      if ShouldAbortDueToCompletedEventSet then
                         *        begin
                         *          if (FPipeLine.OperationNode.NumPendingResultsReceived > 0) or (FPipeLine.OperationNode.OustandingSubgridsToOperateOn > 0) then
                         *            SIGLogMessage.PublishNoODS(Self, Format('%s: Pipeline (request %d, model %d) being aborted as it''s completed event has remained set but still has work to do (%d outstanding subgrids, %d pending results to process) over a sleep epoch',
                         *                                                  [Self.ClassName,
                         *                                                   FRequestDescriptor, FPipeline.ProjectUid,
                         *                                                   FPipeLine.OperationNode.OustandingSubgridsToOperateOn,
                         *                                                   FPipeLine.OperationNode.NumPendingResultsReceived]), slmcError);
                         *          FPipeLine.Abort;
                         *          ASNodeImplInstance.AsyncResponder.ASNodeResponseProcessor.PerformTaskCancellation(FPipelinedTask);
                         *          Exit;
                         *        end
                         *      else
                         *        begin
                         *          if (FPipeLine.OperationNode.NumPendingResultsReceived > 0) or (FPipeLine.OperationNode.OustandingSubgridsToOperateOn > 0) then
                         *            SIGLogMessage.PublishNoODS(Self, Format('%s: Pipeline (request %d, model %d) has it''s completed event set but still has work to do (%d outstanding subgrids, %d pending results to process)',
                         *                                                  [Self.ClassName,
                         *                                                   FRequestDescriptor, FPipeline.ProjectUid,
                         *                                                   FPipeLine.OperationNode.OustandingSubgridsToOperateOn,
                         *                                                   FPipeLine.OperationNode.NumPendingResultsReceived]), slmcDebug);
                         *          Sleep(500);
                         *          ShouldAbortDueToCompletedEventSet := True;
                         *        end;
                         *    end;
                         *
                         *  if FPipeLine.TimeToLiveExpired then
                         *    begin
                         *      FAbortedDueToTimeout := True;
                         *      FPipeLine.Abort;
                         *      ASNodeImplInstance.AsyncResponder.ASNodeResponseProcessor.PerformTaskCancellation(FPipelinedTask);
                         *
                         *      // The pipeline has exceed its allotted time to complete. It will now
                         *      // be aborted and this request will be failed.
                         *      SIGLogMessage.PublishNoODS(Self, Format('%s: Pipeline (request %d) aborted due to time to live expiration (%d seconds)',
                         *                                              [Self.ClassName, FRequestDescriptor, FPipeLine.TimeToLiveSeconds]), slmcError);
                         *      Exit;
                         *    end;
                         */

                        PipelineAborted = PipeLine.Aborted;

                        if (!PipeLine.Terminated && !PipeLine.Aborted)
                        {
                            Result = RequestErrorStatus.OK;
                        }
                    }
                    finally
                    {
                        if (AbortedDueToTimeout)
                        {
                            Result = RequestErrorStatus.AbortedDueToPipelineTimeout;
                        }
                        else
                        if (PipelinedTask.IsCancelled || PipelineAborted)
                        {
                            Result = RequestErrorStatus.RequestHasBeenCancelled;
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.LogError(e, "ExecutePipeline raised exception");
                }

                return(Result);
            }
            catch (Exception e)
            {
                Log.LogError(e, "Exception");
            }

            return(RequestErrorStatus.Unknown);
        }