Esempio n. 1
0
        public JsonResult NoTreatmentFacility()
        {
            var treatmentFacilityUrl = $"{NeptuneWebConfiguration.NereidUrl}/api/v1/treatment_facility/validate?state=ca&region=soc";

            var treatmentFacilities = HttpRequestStorage.DatabaseEntities.TreatmentBMPs
                                      .Where(x => x.TreatmentBMPID == 9974).ToList().Select(x => x.ToTreatmentFacility(true)).ToList();

            var treatmentFacilityTable = new TreatmentFacilityTable()
            {
                TreatmentFacilities = treatmentFacilities
            };
            bool   failed          = false;
            string responseContent = null;

            try
            {
                NereidUtilities.RunJobAtNereid <TreatmentFacilityTable, object>(treatmentFacilityTable,
                                                                                treatmentFacilityUrl,
                                                                                out responseContent, HttpClient);
            }
            catch (Exception)
            {
                failed = true;
            }

            return(Json(
                       new
            {
                firstCallFailed = failed,
                responseContent,
                requestContent = JsonConvert.SerializeObject(treatmentFacilityTable)
            }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public ContentResult TreatmentSiteTable()
        {
            var waterQualityManagementPlanNodes = NereidUtilities.GetWaterQualityManagementPlanNodes(HttpRequestStorage.DatabaseEntities);

            var list = HttpRequestStorage.DatabaseEntities.WaterQualityManagementPlans
                       .SelectMany(x => x.QuickBMPs.Where(y => y.TreatmentBMPType.IsAnalyzedInModelingModule)).Join(
                waterQualityManagementPlanNodes, x => x.WaterQualityManagementPlanID,
                x => x.WaterQualityManagementPlanID, (bmp, node) => new { bmp, node }).ToList();

            var treatmentSites = list.Select(x =>
                                             new TreatmentSite
            {
                NodeID = NereidUtilities.WaterQualityManagementPlanTreatmentNodeID(x.node.WaterQualityManagementPlanID,
                                                                                   x.node.RegionalSubbasinID),
                AreaPercentage     = x.bmp.PercentOfSiteTreated,
                CapturedPercentage = x.bmp.PercentCaptured,
                RetainedPercentage = x.bmp.PercentRetained,
                FacilityType       = x.bmp.TreatmentBMPType.TreatmentBMPModelingType.TreatmentBMPModelingTypeName
            }).ToList();

            var treatmentSiteTable = new TreatmentSiteTable()
            {
                TreatmentSites = treatmentSites
            };

            return(Content(JsonConvert.SerializeObject(treatmentSiteTable), "application/json"));
        }
Esempio n. 3
0
        public JsonResult SolutionSequence()
        {
            var solutionSequenceUrl = $"{NeptuneWebConfiguration.NereidUrl}/api/v1/network/solution_sequence?min_branch_size=12";
            var stopwatch           = new Stopwatch();

            stopwatch.Start();

            var buildGraphStartTime = stopwatch.Elapsed;
            var graph             = NereidUtilities.BuildNetworkGraph(HttpRequestStorage.DatabaseEntities);
            var buildGraphEndTime = stopwatch.Elapsed;

            var solutionSequenceRequestObject = new SolutionSequenceRequest(graph);

            var subgraphCallStartTime  = stopwatch.Elapsed;
            var solutionSequenceResult = NereidUtilities.RunJobAtNereid <SolutionSequenceRequest, SolutionSequenceResult>(solutionSequenceRequestObject,
                                                                                                                          solutionSequenceUrl, out _, HttpClient);
            var subgraphCallEndTime = stopwatch.Elapsed;

            stopwatch.Stop();
            var returnValue = new
            {
                SubgraphResult          = solutionSequenceResult.Data,
                BuildGraphElapsedTime   = (buildGraphEndTime - buildGraphStartTime).Milliseconds,
                SubgraphCallElapsedTime = (subgraphCallEndTime - subgraphCallStartTime).Milliseconds,
                NodeCount = graph.Nodes.Count,
                EdgeCount = graph.Edges.Count,
            };

            return(Json(returnValue, JsonRequestBehavior.AllowGet));
        }
Esempio n. 4
0
        public JsonResult ValidateTreatmentFacility(TreatmentBMPPrimaryKey treatmentBMPPrimaryKey)
        {
            var treatmentFacilityUrl = $"{NeptuneWebConfiguration.NereidUrl}/api/v1/treatment_facility/validate?state=ca&region=soc";

            var treatmentFacility = treatmentBMPPrimaryKey.EntityObject.ToTreatmentFacility(true);

            var treatmentFacilityTable = new TreatmentFacilityTable()
            {
                TreatmentFacilities = new List <TreatmentFacility> {
                    treatmentFacility
                }
            };

            var stopwatch = new Stopwatch();

            stopwatch.Start();
            NereidUtilities.RunJobAtNereid <TreatmentFacilityTable, object>(treatmentFacilityTable, treatmentFacilityUrl,
                                                                            out var responseContent, HttpClient);
            var stopwatchElapsedMilliseconds = stopwatch.ElapsedMilliseconds;

            return(Json(
                       new
            {
                rpcTime = stopwatchElapsedMilliseconds,
                responseContent,
                requestContent = JsonConvert.SerializeObject(treatmentFacilityTable)
            }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 5
0
        public JsonResult BaselineLoading()
        {
            var landSurfaceLoadingUrl    = $"{NeptuneWebConfiguration.NereidUrl}/api/v1/land_surface/loading?details=true&state=ca&region=soc";
            var regionalSubbasinsForTest = new List <int> {
                2377, 12394
            };
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var buildLoadingInputStartTime = stopwatch.Elapsed;
            var vNereidLoadingInputs       = HttpRequestStorage.DatabaseEntities.vNereidLoadingInputs.Where(x => regionalSubbasinsForTest.Contains(x.RegionalSubbasinID)).ToList();
            var landSurfaceLoadingRequest  = new LandSurfaceLoadingRequest(vNereidLoadingInputs, true);
            var buildLoadingInputEndTime   = stopwatch.Elapsed;

            stopwatch.Stop();

            var unused = NereidUtilities.RunJobAtNereid <LandSurfaceLoadingRequest, object>(landSurfaceLoadingRequest, landSurfaceLoadingUrl, out var responseContent, HttpClient);

            var returnValue = new
            {
                LoadingRequest = landSurfaceLoadingRequest,

                LoadingResult = responseContent,

                SubgraphCallElapsedTime = (buildLoadingInputEndTime - buildLoadingInputStartTime).Milliseconds,
            };

            return(Json(returnValue, JsonRequestBehavior.AllowGet));
        }
Esempio n. 6
0
        public ActionResult ChangeDelineationStatus(DelineationPrimaryKey delineationPrimaryKey,
                                                    ChangeDelineationStatusViewModel viewModel)
        {
            var delineation = delineationPrimaryKey.EntityObject;

            // todo: learn how to send a 400 or other error code with Json
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false }));
            }

            delineation.IsVerified         = viewModel.IsVerified;
            delineation.DateLastVerified   = DateTime.Now;
            delineation.VerifiedByPersonID = CurrentPerson.PersonID;

            // if verifying delineation, execute model at the delineation
            // if de-verifying, execute model at its BMP
            if (delineation.IsVerified)
            {
                NereidUtilities.MarkDelineationDirty(delineation, HttpRequestStorage.DatabaseEntities);
            }
            else
            {
                NereidUtilities.MarkTreatmentBMPDirty(delineation.TreatmentBMP, HttpRequestStorage.DatabaseEntities);
            }

            return(Json(new { success = true }));
        }
Esempio n. 7
0
        public JsonResult Subgraph()
        {
            var subgraphUrl = $"{NeptuneWebConfiguration.NereidUrl}/api/v1/network/subgraph";
            var stopwatch   = new Stopwatch();

            stopwatch.Start();

            var buildGraphStartTime = stopwatch.Elapsed;
            var graph             = NereidUtilities.BuildNetworkGraph(HttpRequestStorage.DatabaseEntities);
            var buildGraphEndTime = stopwatch.Elapsed;

            var subgraphRequestObject = new NereidSubgraphRequestObject(graph, new List <Node> {
                new Node("BMP_39")
            });
            var subgraphCallStartTime = stopwatch.Elapsed;

            var subgraphResult = NereidUtilities.RunJobAtNereid <NereidSubgraphRequestObject, SubgraphResult>(subgraphRequestObject,
                                                                                                              subgraphUrl, out _, HttpClient);
            var subgraphCallEndTime = stopwatch.Elapsed;

            stopwatch.Stop();

            var returnValue = new
            {
                SubgraphResult          = subgraphResult,
                BuildGraphElapsedTime   = (buildGraphEndTime - buildGraphStartTime).Milliseconds,
                SubgraphCallElapsedTime = (subgraphCallEndTime - subgraphCallStartTime).Milliseconds,
                NodeCount = graph.Nodes.Count,
                EdgeCount = graph.Edges.Count,
            };

            return(Json(returnValue, JsonRequestBehavior.AllowGet));
        }
Esempio n. 8
0
 protected override void RunJobImplementation()
 {
     // clear out all dirty nodes since the whole network is being run.
     DbContext.DirtyModelNodes.DeleteDirtyModelNode(DbContext.DirtyModelNodes.ToList());
     NereidUtilities.TotalNetworkSolve(out _, out _, out _, DbContext, HttpClient, true);
     NereidUtilities.TotalNetworkSolve(out _, out _, out _, DbContext, HttpClient, false);
 }
Esempio n. 9
0
        public JsonResult ValidateNetworkGraph()
        {
            var networkValidatorUrl = $"{NeptuneWebConfiguration.NereidUrl}/api/v1/network/validate";
            var stopwatch           = new Stopwatch();

            stopwatch.Start();
            var buildGraphStartTime = stopwatch.Elapsed;
            var graph             = NereidUtilities.BuildNetworkGraph(HttpRequestStorage.DatabaseEntities);
            var buildGraphEndTime = stopwatch.Elapsed;

            var validateCallStartTime  = stopwatch.Elapsed;
            var networkValidatorResult = NereidUtilities.RunJobAtNereid <Graph, NetworkValidatorResult>(graph, networkValidatorUrl, out _, HttpClient);

            var validateCallEndTime = stopwatch.Elapsed;

            stopwatch.Stop();

            var returnValue = new
            {
                NetworkValidatorResult   = networkValidatorResult,
                BuildGraphElapsedTime    = (buildGraphEndTime - buildGraphStartTime).Milliseconds,
                ValidateGraphElapsedTime = (validateCallEndTime - validateCallStartTime).Milliseconds,
                NodeCount = graph.Nodes.Count,
                EdgeCount = graph.Edges.Count,
            };

            return(Json(returnValue, JsonRequestBehavior.AllowGet));
        }
        public ActionResult EditWqmpParcels(WaterQualityManagementPlanPrimaryKey waterQualityManagementPlanPrimaryKey, EditWqmpParcelsViewModel viewModel)
        {
            var waterQualityManagementPlan = waterQualityManagementPlanPrimaryKey.EntityObject;

            if (!ModelState.IsValid)
            {
                return(ViewEditWqmpParcels(waterQualityManagementPlan, viewModel));
            }

            var oldBoundary = waterQualityManagementPlan.WaterQualityManagementPlanBoundary;

            viewModel.UpdateModels(waterQualityManagementPlan);
            SetMessageForDisplay($"Successfully edited {FieldDefinitionType.Parcel.GetFieldDefinitionLabelPluralized()} for {FieldDefinitionType.WaterQualityManagementPlan.GetFieldDefinitionLabel()}.");

            var newBoundary = waterQualityManagementPlan.WaterQualityManagementPlanBoundary;

            if (!(oldBoundary == null && newBoundary == null))
            {
                ModelingEngineUtilities.QueueLGURefreshForArea(oldBoundary, newBoundary);
            }

            NereidUtilities.MarkWqmpDirty(waterQualityManagementPlan, HttpRequestStorage.DatabaseEntities);

            return(RedirectToAction(new SitkaRoute <WaterQualityManagementPlanController>(c => c.Detail(waterQualityManagementPlan))));
        }
Esempio n. 11
0
        public JsonResult SolutionTestCase()
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var graph = NereidUtilities.BuildNetworkGraph(HttpRequestStorage.DatabaseEntities);

            // this subgraph is 23 nodes deep
            var single   = graph.Nodes.Single(x => x.ID == "RSB_42");
            var subgraph = graph.GetUpstreamSubgraph(single);

            var allLoadingInputs = HttpRequestStorage.DatabaseEntities.vNereidLoadingInputs.ToList();
            var allModelingBMPs  = NereidUtilities.ModelingTreatmentBMPs(HttpRequestStorage.DatabaseEntities).ToList();
            var allWaterqualityManagementPlanNodes = NereidUtilities.GetWaterQualityManagementPlanNodes(HttpRequestStorage.DatabaseEntities).ToList();
            var allModelingQuickBMPs = HttpRequestStorage.DatabaseEntities.QuickBMPs.Include(x => x.TreatmentBMPType)
                                       .Where(x => x.PercentOfSiteTreated != null && x.TreatmentBMPType.IsAnalyzedInModelingModule).ToList();

            var responseContent = NereidUtilities.SolveSubgraph(subgraph, allLoadingInputs, allModelingBMPs, allWaterqualityManagementPlanNodes, allModelingQuickBMPs, out _, NereidController.HttpClient, true);

            var stopwatchElapsedMilliseconds = stopwatch.ElapsedMilliseconds;

            stopwatch.Stop();

            return(Json(new { elapsed = stopwatchElapsedMilliseconds, responseContent }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 12
0
        public JsonResult TreatmentFacility()
        {
            var treatmentFacilityUrl = $"{NeptuneWebConfiguration.NereidUrl}/api/v1/treatment_facility/validate?state=ca&region=soc";

            var treatmentFacilities = NereidUtilities.ModelingTreatmentBMPs(HttpRequestStorage.DatabaseEntities)
                                      .ToList().Where(x => x.IsFullyParameterized())
                                      .Select(x => x.ToTreatmentFacility(false)).ToList();

            var treatmentFacilityTable = new TreatmentFacilityTable()
            {
                TreatmentFacilities = treatmentFacilities
            };

            var stopwatch = new Stopwatch();

            stopwatch.Start();
            NereidUtilities.RunJobAtNereid <TreatmentFacilityTable, object>(treatmentFacilityTable, treatmentFacilityUrl,
                                                                            out var responseContent, HttpClient);
            var stopwatchElapsedMilliseconds = stopwatch.ElapsedMilliseconds;

            return(Json(
                       new
            {
                rpcTime = stopwatchElapsedMilliseconds,
                responseContent,
                requestContent = JsonConvert.SerializeObject(treatmentFacilityTable)
            }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 13
0
        public ActionResult DeltaSolveTest()
        {
            var failed           = false;
            var exceptionMessage = "";
            var stackTrace       = "";
            var missingNodeIDs   = new List <string>();
            var graph            = new Graph();

            var dirtyModelNodes = HttpRequestStorage.DatabaseEntities.DirtyModelNodes.ToList();

            var stopwatch = new Stopwatch();

            stopwatch.Start();
            try
            {
                NereidUtilities.DeltaSolve(out stackTrace, out missingNodeIDs,
                                           out graph, HttpRequestStorage.DatabaseEntities, HttpClient, dirtyModelNodes, true);
            }
            catch (NereidException <SolutionRequestObject, SolutionResponseObject> nexc)
            {
                var data = new SolutionSummary
                {
                    NodesProcessed           = graph.Nodes.Count(x => x.Results != null),
                    MissingNodeIDs           = missingNodeIDs,
                    Failed                   = true,
                    ExceptionMessage         = nexc.Message,
                    InnerExceptionStackTrace = nexc.InnerException?.StackTrace,
                    FailingRequest           = nexc.Request,
                    FailureResponse          = nexc.Response
                };

                {
                    return(Content(JsonConvert.SerializeObject(data)));
                }
            }
            catch (Exception exception)
            {
                failed           = true;
                exceptionMessage = exception.Message;
                stackTrace       = exception.StackTrace;
            }

            var deltaSolveTime = stopwatch.ElapsedMilliseconds;

            stopwatch.Stop();


            return(Json(
                       new SolutionSummary()
            {
                SolveTime = deltaSolveTime,
                NodesProcessed = graph.Nodes.Count(x => x.Results != null),
                MissingNodeIDs = missingNodeIDs,
                Failed = failed,
                ExceptionMessage = exceptionMessage,
                InnerExceptionStackTrace = stackTrace
            }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 14
0
        protected override void RunJobImplementation()
        {
            var dirtyModelNodes = DbContext.DirtyModelNodes.ToList();

            NereidUtilities.DeltaSolve(out _, out _, out _, DbContext, HttpClient, dirtyModelNodes, true);
            NereidUtilities.DeltaSolve(out _, out _, out _, DbContext, HttpClient, dirtyModelNodes, false);

            DbContext.DirtyModelNodes.DeleteDirtyModelNode(dirtyModelNodes);
            DbContext.Database.CommandTimeout = 600;
            DbContext.SaveChangesWithNoAuditing();
        }
Esempio n. 15
0
        public ContentResult TreatmentFacilityTable()
        {
            var treatmentFacilities = NereidUtilities.ModelingTreatmentBMPs(HttpRequestStorage.DatabaseEntities)
                                      .ToList()
                                      .Select(x => x.ToTreatmentFacility(false)).ToList();

            var treatmentFacilityTable = new TreatmentFacilityTable()
            {
                TreatmentFacilities = treatmentFacilities
            };

            var serializeObject = JsonConvert.SerializeObject(treatmentFacilityTable);

            return(Content(serializeObject, "application/json"));
        }
Esempio n. 16
0
        public LandSurface(vNereidLoadingInput vNereidLoadingInput, bool isBaselineCondition)
        {
            var landUseCode = isBaselineCondition
                ? vNereidLoadingInput.BaselineLandUseCode
                : vNereidLoadingInput.LandUseCode;

            var imperviousAcres = isBaselineCondition
                ? vNereidLoadingInput.BaselineImperviousAcres
                : vNereidLoadingInput.ImperviousAcres;

            NodeID     = NereidUtilities.LandSurfaceNodeID(vNereidLoadingInput);
            SurfaceKey =
                $"{vNereidLoadingInput.LSPCBasinKey}-{landUseCode}-{vNereidLoadingInput.HydrologicSoilGroup}-{vNereidLoadingInput.SlopePercentage}";
            Area           = vNereidLoadingInput.Area;
            ImperviousArea = imperviousAcres;
        }
        public ActionResult Delete(WaterQualityManagementPlanPrimaryKey waterQualityManagementPlanPrimaryKey, ConfirmDialogFormViewModel viewModel)
        {
            var waterQualityManagementPlan = waterQualityManagementPlanPrimaryKey.EntityObject;

            if (!ModelState.IsValid)
            {
                return(ViewDelete(waterQualityManagementPlan, viewModel));
            }

            NereidUtilities.MarkDownstreamNodeDirty(waterQualityManagementPlan, HttpRequestStorage.DatabaseEntities);

            waterQualityManagementPlan.DeleteFull(HttpRequestStorage.DatabaseEntities);
            SetMessageForDisplay($"Successfully delete \"{waterQualityManagementPlan.WaterQualityManagementPlanName}\".");

            return(new ModalDialogFormJsonResult());
        }
        public ActionResult EditModelingApproach(WaterQualityManagementPlanPrimaryKey waterQualityManagementPlanPrimaryKey, EditModelingApproachViewModel viewModel)
        {
            var waterQualityManagementPlan = waterQualityManagementPlanPrimaryKey.EntityObject;

            if (!ModelState.IsValid)
            {
                return(ViewEditModelingApproach(viewModel));
            }
            viewModel.UpdateModel(waterQualityManagementPlan);

            if (waterQualityManagementPlan.WaterQualityManagementPlanBoundary != null)
            {
                ModelingEngineUtilities.QueueLGURefreshForArea(waterQualityManagementPlan.WaterQualityManagementPlanBoundary, null);
                NereidUtilities.MarkWqmpDirty(waterQualityManagementPlan, HttpRequestStorage.DatabaseEntities);
            }

            SetMessageForDisplay($"Modeling Approach successfully changed for {waterQualityManagementPlan.WaterQualityManagementPlanName}.");
            return(new ModalDialogFormJsonResult());
        }
Esempio n. 19
0
        public ActionResult MarkBMPDelineationAsVerifiedModal(BulkRowTreatmentBMPViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(new ModalDialogFormJsonResult());
            }

            var bmpDelineations = HttpRequestStorage.DatabaseEntities.Delineations.Where(x => viewModel.EntityIDList.Contains(x.DelineationID)).ToList();

            bmpDelineations.ForEach(x => x.MarkAsVerified(CurrentPerson));

            NereidUtilities.MarkDelineationDirty(bmpDelineations, HttpRequestStorage.DatabaseEntities);

            var numberOfVerifiedBMPDelineations = bmpDelineations.Count;

            SetMessageForDisplay($"{numberOfVerifiedBMPDelineations} BMP Delineations were successfully verified.");

            return(new ModalDialogFormJsonResult());
        }
        public ActionResult EditSourceControlBMPs(
            WaterQualityManagementPlanPrimaryKey waterQualityManagementPlanPrimaryKey,
            EditSourceControlBMPsViewModel viewModel)
        {
            var waterQualityManagementPlan = waterQualityManagementPlanPrimaryKey.EntityObject;

            if (!ModelState.IsValid)
            {
                return(ViewEditSourceControlBMPs(waterQualityManagementPlan, viewModel));
            }

            viewModel.UpdateModels(waterQualityManagementPlan, viewModel.SourceControlBMPSimples);
            SetMessageForDisplay(
                $"Successfully updated BMPs for {waterQualityManagementPlan.WaterQualityManagementPlanName}");

            NereidUtilities.MarkWqmpDirty(waterQualityManagementPlan, HttpRequestStorage.DatabaseEntities);

            return(RedirectToAction(new SitkaRoute <WaterQualityManagementPlanController>(c => c.Detail(waterQualityManagementPlanPrimaryKey))));
        }
Esempio n. 21
0
        /// <summary>
        /// The preference over delete-full for delineation. Nulls the DelineationID on any LGUs,
        /// deletes any overlaps, deletes the delineation itself, and marks the delineation's
        /// TreatmentBMP for a model run.
        /// </summary>
        /// <param name="treatmentBMPDelineation"></param>
        /// <param name="dbContext"></param>
        public static void DeleteDelineation(this Delineation treatmentBMPDelineation, DatabaseEntities dbContext)
        {
            var treatmentBMP = treatmentBMPDelineation.TreatmentBMP;

            foreach (var delineationLoadGeneratingUnit in treatmentBMPDelineation.LoadGeneratingUnits)
            {
                delineationLoadGeneratingUnit.DelineationID = null;
            }

            dbContext.SaveChanges();

            dbContext.DelineationOverlaps.DeleteDelineationOverlap(treatmentBMPDelineation
                                                                   .DelineationOverlaps);
            dbContext.DelineationOverlaps.DeleteDelineationOverlap(treatmentBMPDelineation
                                                                   .DelineationOverlapsWhereYouAreTheOverlappingDelineation);
            dbContext.Delineations.DeleteDelineation(treatmentBMPDelineation);
            dbContext.SaveChanges();

            NereidUtilities.MarkTreatmentBMPDirty(treatmentBMP, dbContext);
        }
Esempio n. 22
0
        public static TreatmentFacility ToTreatmentFacility(this TreatmentBMP treatmentBMP, bool isBaselineCondition)
        {
            var    treatmentBMPNodeID   = NereidUtilities.TreatmentBMPNodeID(treatmentBMP);
            var    lspcBasinKey         = treatmentBMP.LSPCBasin?.LSPCBasinKey.ToString();
            var    isFullyParameterized = treatmentBMP.IsFullyParameterized();
            double?treatmentRate        = null;
            var    modelingAttribute    = treatmentBMP.TreatmentBMPModelingAttribute;

            // in the baseline condition, anything built after 2003 is treated as if it doesn't exist.
            if (!isFullyParameterized ||
                (isBaselineCondition && treatmentBMP.YearBuilt.HasValue && treatmentBMP.YearBuilt.Value > NereidUtilities.BASELINE_CUTOFF_YEAR))
            {
                return(new TreatmentFacility
                {
                    NodeID = treatmentBMPNodeID,
                    FacilityType = "NoTreatment",
                    ReferenceDataKey = lspcBasinKey,
                    DesignStormwaterDepth = treatmentBMP.PrecipitationZone?.DesignStormwaterDepthInInches ?? .8,
                    EliminateAllDryWeatherFlowOverride = modelingAttribute?.DryWeatherFlowOverrideID == DryWeatherFlowOverride.Yes.DryWeatherFlowOverrideID
                });
            }

            // treatment rate is an alias for four different fields, so we need to pick the one that's not null
            if (modelingAttribute.InfiltrationDischargeRate != null)
            {
                treatmentRate = modelingAttribute.InfiltrationDischargeRate;
            }
            else if (modelingAttribute.TreatmentRate != null)
            {
                treatmentRate = modelingAttribute.TreatmentRate;
            }
            else if (modelingAttribute.AverageDivertedFlowrate != null)
            {
                // AverageDivertedFlowrate is collected in gallons per day instead of CFS, but we need to send CFS to Nereid.
                treatmentRate = modelingAttribute.AverageDivertedFlowrate * NereidUtilities.GPD_TO_CFS;
            }
            else if (modelingAttribute.AverageTreatmentFlowrate != null)
            {
                treatmentRate = modelingAttribute.AverageTreatmentFlowrate;
            }

            double?area = null;

            // area_sqft is an alias for four different fields, so we need to take the one that's not null
            if (modelingAttribute.EffectiveFootprint != null)
            {
                area = modelingAttribute.EffectiveFootprint;
            }
            else if (modelingAttribute.InfiltrationSurfaceArea != null)
            {
                area = modelingAttribute.InfiltrationSurfaceArea;
            }
            else if (modelingAttribute.MediaBedFootprint != null)
            {
                area = modelingAttribute.MediaBedFootprint;
            }
            else if (modelingAttribute.WettedFootprint != null)
            {
                area = modelingAttribute.WettedFootprint;
            }

            double?designCapacity = null;

            if (modelingAttribute.DesignDryWeatherTreatmentCapacity != null)
            {
                designCapacity = modelingAttribute.DesignDryWeatherTreatmentCapacity;
            }
            else if (modelingAttribute.DesignLowFlowDiversionCapacity != null)
            {
                // DesignLowFlowDiversionCapacity is collected in GPD, so convert to CFS
                designCapacity = modelingAttribute.DesignLowFlowDiversionCapacity * NereidUtilities.GPD_TO_CFS;
            }

            if (designCapacity == null)
            {
                designCapacity = treatmentRate;
            }
            else if (treatmentRate == null)
            {
                treatmentRate = designCapacity;
            }

            // null-coalescence here represents default values.
            // It's generally an anti-pattern for an API to require its clients to insert default values,
            // since the API should be written to replace nulls/absent values with defaults,
            // but it's so few that it's not worth a revision to the modeling engine at this time (4/16/2020)
            var treatmentFacility = new TreatmentFacility
            {
                NodeID                    = treatmentBMPNodeID,
                FacilityType              = treatmentBMP.TreatmentBMPType.TreatmentBMPModelingType.TreatmentBMPModelingTypeName,
                ReferenceDataKey          = lspcBasinKey,
                DesignStormwaterDepth     = treatmentBMP.PrecipitationZone.DesignStormwaterDepthInInches,
                DesignCapacity            = designCapacity,
                DesignMediaFiltrationRate = modelingAttribute.DesignMediaFiltrationRate,
                //convert Days to Hours for this field.
                DesignResidenceTimeforPermanentPool = modelingAttribute.DesignResidenceTimeforPermanentPool * 24 ?? double.PositiveInfinity,
                DiversionRate = modelingAttribute.DiversionRate,
                DrawdownTimeforWQDetentionVolume = modelingAttribute.DrawdownTimeforWQDetentionVolume,
                Area = area,
                EffectiveRetentionDepth                 = modelingAttribute.EffectiveRetentionDepth,
                MonthsOfOperation                       = modelingAttribute.MonthsOfOperation?.MonthsOfOperationNereidAlias ?? MonthsOfOperation.Both.MonthsOfOperationNereidAlias,
                PermanentPoolorWetlandVolume            = modelingAttribute.PermanentPoolorWetlandVolume,
                RoutingConfiguration                    = modelingAttribute.RoutingConfigurationID == RoutingConfiguration.Online.RoutingConfigurationID,
                StorageVolumeBelowLowestOutletElevation = modelingAttribute.StorageVolumeBelowLowestOutletElevation,
                // SummerHarvestedWaterDemand is collected in GPD, so convert to CFS
                SummerHarvestedWaterDemand = modelingAttribute.SummerHarvestedWaterDemand * NereidUtilities.GPD_TO_CFS,
                TimeOfConcentration        = modelingAttribute.TimeOfConcentration?.TimeOfConcentrationDisplayName ?? TimeOfConcentration.FiveMinutes.TimeOfConcentrationDisplayName,
                TotalDrawdownTime          = modelingAttribute.DrawdownTimeforWQDetentionVolume,
                TotalEffectiveBMPVolume    = modelingAttribute.TotalEffectiveBMPVolume,
                TreatmentRate = treatmentRate,
                UnderlyingHydrologicSoilGroup = modelingAttribute.UnderlyingHydrologicSoilGroup?.UnderlyingHydrologicSoilGroupDisplayName.ToLower() ?? UnderlyingHydrologicSoilGroup.D.UnderlyingHydrologicSoilGroupDisplayName.ToLower(),
                UnderlyingInfiltrationRate    = modelingAttribute.UnderlyingInfiltrationRate,
                UpstreamBMP = modelingAttribute.UpstreamTreatmentBMPID.HasValue ? NereidUtilities.TreatmentBMPNodeID(modelingAttribute.UpstreamTreatmentBMPID.Value) : null,
                WaterQualityDetentionVolume = modelingAttribute.WaterQualityDetentionVolume,
                // WinterHarvestedWaterDemand is collected in GPD, so convert to CFS
                WinterHarvestedWaterDemand         = modelingAttribute.WinterHarvestedWaterDemand * NereidUtilities.GPD_TO_CFS,
                EliminateAllDryWeatherFlowOverride = modelingAttribute.DryWeatherFlowOverrideID == DryWeatherFlowOverride.Yes.DryWeatherFlowOverrideID
            };

            return(treatmentFacility);
        }
Esempio n. 23
0
        public ContentResult NetworkTable()
        {
            var graph = NereidUtilities.BuildNetworkGraph(HttpRequestStorage.DatabaseEntities);

            return(Content(JsonConvert.SerializeObject(graph), "application/json"));
        }