Index: Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/AssessmentSectionExtensions.cs =================================================================== diff -u -r175cb39b49a146149811954e3800bebfc0819e3d -raef20c08e43fb95b037791c98c8e088352061c5e --- Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/AssessmentSectionExtensions.cs (.../AssessmentSectionExtensions.cs) (revision 175cb39b49a146149811954e3800bebfc0819e3d) +++ Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/AssessmentSectionExtensions.cs (.../AssessmentSectionExtensions.cs) (revision aef20c08e43fb95b037791c98c8e088352061c5e) @@ -20,7 +20,9 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.ComponentModel; +using System.Linq; using Core.Common.Base.Data; using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.Hydraulics; @@ -33,14 +35,14 @@ public static class AssessmentSectionExtensions { /// - /// Gets the normative assessment level from a . + /// Gets the normative assessment level for a . /// - /// The assessment section. - /// The hydraulic boundary location to get the normative - /// assessment level from. + /// The assessment section to get the normative assessment level from. + /// The hydraulic boundary location to get the normative assessment level for. /// The normative assessment level or when: /// /// is null; + /// is not part of ; /// contains no corresponding calculation output. /// /// @@ -50,7 +52,8 @@ /// contains an invalid value of . /// Thrown when /// contains a valid value of , but unsupported. - public static RoundedDouble GetNormativeAssessmentLevel(this IAssessmentSection assessmentSection, HydraulicBoundaryLocation hydraulicBoundaryLocation) + public static RoundedDouble GetNormativeAssessmentLevel(this IAssessmentSection assessmentSection, + HydraulicBoundaryLocation hydraulicBoundaryLocation) { if (assessmentSection == null) { @@ -66,15 +69,85 @@ typeof(NormType)); } + IEnumerable calculations; + switch (normType) { case NormType.Signaling: - return hydraulicBoundaryLocation?.DesignWaterLevelCalculation2.Output?.Result ?? RoundedDouble.NaN; + calculations = assessmentSection.WaterLevelCalculationsForSignalingNorm; + break; case NormType.LowerLimit: - return hydraulicBoundaryLocation?.DesignWaterLevelCalculation3.Output?.Result ?? RoundedDouble.NaN; + calculations = assessmentSection.WaterLevelCalculationsForLowerLimitNorm; + break; default: throw new NotSupportedException(); } + + return GetAssessmentLevelFromCalculations(hydraulicBoundaryLocation, calculations); } + + /// + /// Gets the assessment level for a based on . + /// + /// The assessment section to get the assessment level from. + /// The hydraulic boundary location to get the assessment level for. + /// The category type to use while obtaining the assessment level. + /// The assessment level or when: + /// + /// is null; + /// is not part of ; + /// contains no corresponding calculation output. + /// + /// + /// Thrown when + /// is null. + /// Thrown when + /// is an invalid . + /// Thrown when + /// is a valid but unsupported . + public static RoundedDouble GetAssessmentLevel(this IAssessmentSection assessmentSection, + HydraulicBoundaryLocation hydraulicBoundaryLocation, + AssessmentSectionCategoryType categoryType) + { + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + if (!Enum.IsDefined(typeof(AssessmentSectionCategoryType), categoryType)) + { + throw new InvalidEnumArgumentException(nameof(categoryType), + (int) categoryType, + typeof(AssessmentSectionCategoryType)); + } + + IEnumerable calculations; + + switch (categoryType) + { + case AssessmentSectionCategoryType.FactorizedSignalingNorm: + calculations = assessmentSection.WaterLevelCalculationsForFactorizedSignalingNorm; + break; + case AssessmentSectionCategoryType.SignalingNorm: + calculations = assessmentSection.WaterLevelCalculationsForSignalingNorm; + break; + case AssessmentSectionCategoryType.LowerLimitNorm: + calculations = assessmentSection.WaterLevelCalculationsForLowerLimitNorm; + break; + case AssessmentSectionCategoryType.FactorizedLowerLimitNorm: + calculations = assessmentSection.WaterLevelCalculationsForFactorizedLowerLimitNorm; + break; + default: + throw new NotSupportedException(); + } + + return GetAssessmentLevelFromCalculations(hydraulicBoundaryLocation, calculations); + } + + private static RoundedDouble GetAssessmentLevelFromCalculations(HydraulicBoundaryLocation hydraulicBoundaryLocation, IEnumerable calculations) + { + return calculations.FirstOrDefault(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation))?.Output?.Result + ?? RoundedDouble.NaN; + } } } \ No newline at end of file