Index: Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs =================================================================== diff -u -r122edb15a01ee908bf7774f862258b6606522c68 -r89a886bc06cf46e9742de7356a96c2a5fcc55f2a --- Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs (.../DesignWaterLevelCalculationService.cs) (revision 122edb15a01ee908bf7774f862258b6606522c68) +++ Ringtoets/Common/src/Ringtoets.Common.Service/DesignWaterLevelCalculationService.cs (.../DesignWaterLevelCalculationService.cs) (revision 89a886bc06cf46e9742de7356a96c2a5fcc55f2a) @@ -23,6 +23,7 @@ using System.IO; using System.Linq; using Core.Common.Base.Data; +using Core.Common.Utils; using log4net; using Ringtoets.Common.IO.HydraRing; using Ringtoets.Common.Service.MessageProviders; @@ -95,18 +96,19 @@ try { - calculator.Calculate(CreateInput(hydraulicBoundaryLocation, norm, hydraulicBoundaryDatabaseFilePath)); + AssessmentLevelCalculationInput calculationInput = CreateInput(hydraulicBoundaryLocation, norm, hydraulicBoundaryDatabaseFilePath); + calculator.Calculate(calculationInput); if (string.IsNullOrEmpty(calculator.LastErrorFileContent)) { hydraulicBoundaryLocation.DesignWaterLevel = (RoundedDouble)calculator.DesignWaterLevel; hydraulicBoundaryLocation.DesignWaterLevelCalculationConvergence = RingtoetsCommonDataCalculationService.CalculationConverged(calculator.ReliabilityIndex, norm); - if (hydraulicBoundaryLocation.DesignWaterLevelCalculationConvergence != CalculationConvergence.CalculatedConverged) - { - log.Warn(messageProvider.GetCalculatedNotConvergedMessage(hydraulicBoundaryLocation.Name)); - } + hydraulicBoundaryLocation.DesignWaterLevelOutput = CreateHydraulicBoundaryLocationOutput(messageProvider, + hydraulicBoundaryLocation.Name, + calculationInput.Beta, + norm); } } catch (HydraRingFileParserException) @@ -153,6 +155,32 @@ } } + private HydraulicBoundaryLocationOutput CreateHydraulicBoundaryLocationOutput(ICalculationMessageProvider messageProvider, + string hydraulicBoundaryLocationName, + double targetReliability, + double targetProbability) + { + var designWaterLevel = calculator.DesignWaterLevel; + var reliability = calculator.ReliabilityIndex; + var probability = StatisticsConverter.ReliabilityToProbability(reliability); + + CalculationConvergence converged = RingtoetsCommonDataCalculationService.CalculationConverged( + calculator.ReliabilityIndex, targetProbability); + + if (converged != CalculationConvergence.CalculatedConverged) + { + log.Warn(messageProvider.GetCalculatedNotConvergedMessage(hydraulicBoundaryLocationName)); + } + + return new HydraulicBoundaryLocationOutput( + designWaterLevel, + targetProbability, + targetReliability, + probability, + reliability, + converged); + } + private AssessmentLevelCalculationInput CreateInput(HydraulicBoundaryLocation hydraulicBoundaryLocation, double norm, string hydraulicBoundaryDatabaseFilePath) { var assessmentLevelCalculationInput = new AssessmentLevelCalculationInput(1, hydraulicBoundaryLocation.Id, norm); Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs =================================================================== diff -u -rcd7078972189cf51d899754097ef3cbc0ddc26ee -r89a886bc06cf46e9742de7356a96c2a5fcc55f2a --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs (.../DesignWaterLevelCalculationServiceTest.cs) (revision cd7078972189cf51d899754097ef3cbc0ddc26ee) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/DesignWaterLevelCalculationServiceTest.cs (.../DesignWaterLevelCalculationServiceTest.cs) (revision 89a886bc06cf46e9742de7356a96c2a5fcc55f2a) @@ -138,7 +138,7 @@ const string calculationName = "locationName"; const string calculationNotConvergedMessage = "calculationNotConvergedMessage"; const string ringId = "ringId"; - const double returnPeriod = 30; + const double norm = 1.0/30; var mockRepository = new MockRepository(); var calculationMessageProviderMock = mockRepository.Stub(); @@ -159,14 +159,14 @@ new DesignWaterLevelCalculationService().Calculate(hydraulicBoundaryLocation, validFilePath, ringId, - returnPeriod, + norm, calculationMessageProviderMock); // Assert Assert.AreEqual(testDataPath, testCalculator.HydraulicBoundaryDatabaseDirectory); Assert.AreEqual(ringId, testCalculator.RingId); - var expectedInput = CreateInput(hydraulicBoundaryLocation, returnPeriod); + var expectedInput = CreateInput(hydraulicBoundaryLocation, norm); AssertInput(expectedInput, testCalculator.ReceivedInputs.First()); Assert.IsFalse(testCalculator.IsCanceled); } @@ -183,6 +183,8 @@ var calculationMessageProviderMock = mockRepository.Stub(); mockRepository.ReplayAll(); + const double norm = 1.0/30; + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1300001, "punt_flw_ 1", 0, 0) { DesignWaterLevel = new RoundedDouble(2, double.NaN) @@ -199,7 +201,7 @@ service.Calculate(hydraulicBoundaryLocation, validFilePath, "ringId", - 30, + norm, calculationMessageProviderMock); // Assert @@ -217,6 +219,7 @@ const string locationName = "punt_flw_ 1"; const string calculationName = "locationName"; const string calculationFailedMessage = "calculationFailedMessage"; + const double norm = 1.0/30; var mockRepository = new MockRepository(); var calculationMessageProviderMock = mockRepository.StrictMock(); @@ -245,7 +248,7 @@ new DesignWaterLevelCalculationService().Calculate(hydraulicBoundaryLocation, validFilePath, "ringId", - 30, + norm, calculationMessageProviderMock); } catch (HydraRingFileParserException) @@ -279,6 +282,7 @@ const string locationName = "punt_flw_ 1"; const string calculationName = "locationName"; const string calculationFailedMessage = "calculationFailedUnexplainedMessage"; + const double norm = 1.0/30; var mockRepository = new MockRepository(); var calculationMessageProviderMock = mockRepository.StrictMock(); @@ -306,7 +310,7 @@ new DesignWaterLevelCalculationService().Calculate(hydraulicBoundaryLocation, validFilePath, "ringId", - 30, + norm, calculationMessageProviderMock); } catch (HydraRingFileParserException) @@ -340,6 +344,7 @@ const string locationName = "punt_flw_ 1"; const string calculationName = "locationName"; const string calculationFailedMessage = "calculationFailedMessage"; + const double norm = 1.0/30; var mockRepository = new MockRepository(); var calculationMessageProviderMock = mockRepository.StrictMock(); @@ -369,7 +374,7 @@ new DesignWaterLevelCalculationService().Calculate(hydraulicBoundaryLocation, validFilePath, "ringId", - 30, + norm, calculationMessageProviderMock); } catch (HydraRingCalculationException e) @@ -403,9 +408,9 @@ Assert.AreEqual(expectedInput.Beta, hydraRingCalculationInput.Beta); } - private static AssessmentLevelCalculationInput CreateInput(HydraulicBoundaryLocation hydraulicBoundaryLocation, double returnPeriod) + private static AssessmentLevelCalculationInput CreateInput(HydraulicBoundaryLocation hydraulicBoundaryLocation, double norm) { - return new AssessmentLevelCalculationInput(1, hydraulicBoundaryLocation.Id, returnPeriod); + return new AssessmentLevelCalculationInput(1, hydraulicBoundaryLocation.Id, norm); } } } \ No newline at end of file Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/HydraulicBoundaryLocation.cs =================================================================== diff -u -r7618e47c7ff0d09102d56e2c25545f57a4269352 -r89a886bc06cf46e9742de7356a96c2a5fcc55f2a --- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/HydraulicBoundaryLocation.cs (.../HydraulicBoundaryLocation.cs) (revision 7618e47c7ff0d09102d56e2c25545f57a4269352) +++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/HydraulicBoundaryLocation.cs (.../HydraulicBoundaryLocation.cs) (revision 89a886bc06cf46e9742de7356a96c2a5fcc55f2a) @@ -56,8 +56,23 @@ } /// - /// Gets or sets the design water level of . + /// Gets the database id of the hydraulic boundary location. /// + public long Id { get; private set; } + + /// + /// Gets the name of the hydraulic boundary location. + /// + public string Name { get; private set; } + + /// + /// Gets the coordinates of the hydraulic boundary location. + /// + public Point2D Location { get; private set; } + + /// + /// Gets or sets the design water level of the hydraulic boundary location. + /// public RoundedDouble DesignWaterLevel { get @@ -71,8 +86,23 @@ } /// - /// Gets or sets the wave height of . + /// Gets or sets the output of a design water level calculation. /// + public HydraulicBoundaryLocationOutput DesignWaterLevelOutput { get; set; } + + /// + /// Gets or sets the output of a wave height calculation. + /// + public HydraulicBoundaryLocationOutput WaveHeightOutput { get; set; } + + /// + /// Gets or sets the convergence status of the design waterlevel calculation. + /// + public CalculationConvergence DesignWaterLevelCalculationConvergence { get; set; } + + /// + /// Gets or sets the wave height of the hydraulic boundary location. + /// public RoundedDouble WaveHeight { get @@ -86,21 +116,10 @@ } /// - /// Gets or sets the convergence status of the design waterlevel calculation. - /// - public CalculationConvergence DesignWaterLevelCalculationConvergence { get; set; } - - /// /// Gets or sets the convergence status of the waveheight calculation. /// public CalculationConvergence WaveHeightCalculationConvergence { get; set; } - public long Id { get; private set; } - - public string Name { get; private set; } - - public Point2D Location { get; private set; } - public override string ToString() { return Name; Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/HydraulicBoundaryLocationOutput.cs =================================================================== diff -u --- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/HydraulicBoundaryLocationOutput.cs (revision 0) +++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/HydraulicBoundaryLocationOutput.cs (revision 89a886bc06cf46e9742de7356a96c2a5fcc55f2a) @@ -0,0 +1,108 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Core.Common.Base.Data; +using Ringtoets.HydraRing.Data.Properties; + +namespace Ringtoets.HydraRing.Data +{ + /// + /// This class contains the result of assessment level calculation for an . + /// + public class HydraulicBoundaryLocationOutput + { + /// + /// Creates a new instance of . + /// + /// The calculation result. + /// The norm used during the calculation. + /// The reliability index used during the calculation. + /// the calculated probability. + /// The calculated reliability. + /// The convergence status of the calculation. + /// Thrown when + /// or falls outside the [0.0, 1.0] range and is not . + public HydraulicBoundaryLocationOutput(double result, double targetProbability, double targetReliability, + double calculatedProbability, double calculatedReliability, + CalculationConvergence calculationConvergence) + { + if (!IsValidProbability(targetProbability)) + { + throw new ArgumentOutOfRangeException("targetProbability", targetProbability, + Resources.Probability_Must_be_in_range_zero_to_one); + } + if (!IsValidProbability(calculatedProbability)) + { + throw new ArgumentOutOfRangeException("calculatedProbability", calculatedProbability, + Resources.Probability_Must_be_in_range_zero_to_one); + } + + Result = new RoundedDouble(2, result); + + TargetProbability = targetProbability; + TargetReliability = new RoundedDouble(5, targetReliability); + CalculatedProbability = calculatedProbability; + CalculatedReliability = new RoundedDouble(5, calculatedReliability); + CalculationConvergence = calculationConvergence; + } + + /// + /// Gets or sets the result of the calculation. + /// + public RoundedDouble Result { get; private set; } + + /// + /// Gets the target probability. + /// [1/year] + /// + public double TargetProbability { get; private set; } + + /// + /// Gets the target beta. + /// [-] + /// + public RoundedDouble TargetReliability { get; private set; } + + /// + /// Gets the calculated probability. + /// [1/year] + /// + public double CalculatedProbability { get; private set; } + + /// + /// Gets the calculated reliability. + /// [-] + /// + public RoundedDouble CalculatedReliability { get; private set; } + + /// + /// Gets or sets the convergence status of the calculation. + /// [-] + /// + public CalculationConvergence CalculationConvergence { get; private set; } + + private static bool IsValidProbability(double probability) + { + return double.IsNaN(probability) || (0.0 <= probability && probability <= 1.0); + } + } +} \ No newline at end of file Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/Properties/Resources.Designer.cs =================================================================== diff -u -rb4828e713796dd5e285276417c59b695a3d9cc73 -r89a886bc06cf46e9742de7356a96c2a5fcc55f2a --- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision b4828e713796dd5e285276417c59b695a3d9cc73) +++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 89a886bc06cf46e9742de7356a96c2a5fcc55f2a) @@ -107,5 +107,14 @@ return ResourceManager.GetString("CalculationConvergence_NotCalculated", resourceCulture); } } + + /// + /// Looks up a localized string similar to Kans moet in het bereik [0, 1] liggen.. + /// + internal static string Probability_Must_be_in_range_zero_to_one { + get { + return ResourceManager.GetString("Probability_Must_be_in_range_zero_to_one", resourceCulture); + } + } } } Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/Properties/Resources.resx =================================================================== diff -u -rb4828e713796dd5e285276417c59b695a3d9cc73 -r89a886bc06cf46e9742de7356a96c2a5fcc55f2a --- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/Properties/Resources.resx (.../Resources.resx) (revision b4828e713796dd5e285276417c59b695a3d9cc73) +++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/Properties/Resources.resx (.../Resources.resx) (revision 89a886bc06cf46e9742de7356a96c2a5fcc55f2a) @@ -126,4 +126,7 @@ + + Kans moet in het bereik [0, 1] liggen. + \ No newline at end of file Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/Ringtoets.HydraRing.Data.csproj =================================================================== diff -u -r8db89aecb3565f4784cedd541e7407e8360b6a6f -r89a886bc06cf46e9742de7356a96c2a5fcc55f2a --- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/Ringtoets.HydraRing.Data.csproj (.../Ringtoets.HydraRing.Data.csproj) (revision 8db89aecb3565f4784cedd541e7407e8360b6a6f) +++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/Ringtoets.HydraRing.Data.csproj (.../Ringtoets.HydraRing.Data.csproj) (revision 89a886bc06cf46e9742de7356a96c2a5fcc55f2a) @@ -42,6 +42,7 @@ + True Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Data.Test/HydraulicBoundaryLocationOutputTest.cs =================================================================== diff -u --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Data.Test/HydraulicBoundaryLocationOutputTest.cs (revision 0) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Data.Test/HydraulicBoundaryLocationOutputTest.cs (revision 89a886bc06cf46e9742de7356a96c2a5fcc55f2a) @@ -0,0 +1,102 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using NUnit.Framework; + +namespace Ringtoets.HydraRing.Data.Test +{ + [TestFixture] + public class HydraulicBoundaryLocationOutputTest + { + [Test] + public void Constructor_InvalidTargetProbability_ThrowsArgumentOutOfRangeException( + [Random(1)] double beta, + [Values(-0.01, 1.01)] double targetProbability, + [Random(1)] double targetReliability, + [Random(1)] double calculatedProbability, + [Random(1)] double calculatedReliability, + [Values(CalculationConvergence.CalculatedNotConverged, CalculationConvergence.CalculatedConverged, + CalculationConvergence.NotCalculated)] CalculationConvergence convergence) + { + // Call + TestDelegate call = () => new HydraulicBoundaryLocationOutput(beta, targetProbability, + targetReliability, + calculatedProbability, + calculatedReliability, + convergence); + + // Assert + ArgumentOutOfRangeException exception = Assert.Throws(call); + Assert.AreEqual("targetProbability", exception.ParamName); + StringAssert.Contains("Kans moet in het bereik [0, 1] liggen.", exception.Message); + } + + [Test] + public void Constructor_InvalidCalculatedProbability_ThrowsArgumentOutOfRangeException( + [Random(1)] double beta, + [Random(1)] double targetProbability, + [Random(1)] double targetReliability, + [Values(-0.01, 1.01)] double calculatedProbability, + [Random(1)] double calculatedReliability, + [Values(CalculationConvergence.CalculatedNotConverged, CalculationConvergence.CalculatedConverged, + CalculationConvergence.NotCalculated)] CalculationConvergence convergence) + { + // Call + TestDelegate call = () => new HydraulicBoundaryLocationOutput(beta, targetProbability, + targetReliability, + calculatedProbability, + calculatedReliability, + convergence); + + // Assert + ArgumentOutOfRangeException exception = Assert.Throws(call); + Assert.AreEqual("calculatedProbability", exception.ParamName); + StringAssert.Contains("Kans moet in het bereik [0, 1] liggen.", exception.Message); + } + + [Test] + public void Constructor_ValidInput_ExpectedProperties( + [Random(1)] double beta, + [Random(1)] double targetProbability, + [Random(1)] double targetReliability, + [Random(1)] double calculatedProbability, + [Random(1)] double calculatedReliability, + [Values(CalculationConvergence.CalculatedNotConverged, CalculationConvergence.CalculatedConverged, + CalculationConvergence.NotCalculated)] CalculationConvergence convergence) + { + // Call + var output = new HydraulicBoundaryLocationOutput(beta, targetProbability, + targetReliability, + calculatedProbability, + calculatedReliability, + convergence); + + // Assert + Assert.AreEqual(beta, output.Result, 1e-2); + Assert.AreEqual(targetProbability, output.TargetProbability); + Assert.AreEqual(targetReliability, output.TargetReliability, 1e-5); + Assert.AreEqual(calculatedProbability, output.CalculatedProbability); + Assert.AreEqual(calculatedReliability, output.CalculatedReliability, 1e-5); + Assert.AreEqual(convergence, output.CalculationConvergence); + } + } +} \ No newline at end of file Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Data.Test/HydraulicBoundaryLocationTest.cs =================================================================== diff -u -r7618e47c7ff0d09102d56e2c25545f57a4269352 -r89a886bc06cf46e9742de7356a96c2a5fcc55f2a --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Data.Test/HydraulicBoundaryLocationTest.cs (.../HydraulicBoundaryLocationTest.cs) (revision 7618e47c7ff0d09102d56e2c25545f57a4269352) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Data.Test/HydraulicBoundaryLocationTest.cs (.../HydraulicBoundaryLocationTest.cs) (revision 89a886bc06cf46e9742de7356a96c2a5fcc55f2a) @@ -66,6 +66,8 @@ Assert.AreEqual(2, hydraulicBoundaryLocation.WaveHeight.NumberOfDecimalPlaces); Assert.AreEqual(CalculationConvergence.NotCalculated, hydraulicBoundaryLocation.DesignWaterLevelCalculationConvergence); Assert.AreEqual(CalculationConvergence.NotCalculated, hydraulicBoundaryLocation.WaveHeightCalculationConvergence); + Assert.IsNull(hydraulicBoundaryLocation.DesignWaterLevelOutput); + Assert.IsNull(hydraulicBoundaryLocation.WaveHeightOutput); } [Test] Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Data.Test/Ringtoets.HydraRing.Data.Test.csproj =================================================================== diff -u -r2d5e2d09b0cb1a7f48e1b0a067d332347c89d4a8 -r89a886bc06cf46e9742de7356a96c2a5fcc55f2a --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Data.Test/Ringtoets.HydraRing.Data.Test.csproj (.../Ringtoets.HydraRing.Data.Test.csproj) (revision 2d5e2d09b0cb1a7f48e1b0a067d332347c89d4a8) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Data.Test/Ringtoets.HydraRing.Data.Test.csproj (.../Ringtoets.HydraRing.Data.Test.csproj) (revision 89a886bc06cf46e9742de7356a96c2a5fcc55f2a) @@ -52,6 +52,7 @@ Properties\GlobalAssembly.cs +