Index: Ringtoets/Common/src/Ringtoets.Common.Service/WaveHeightCalculationService.cs =================================================================== diff -u -r24e18b63dccdb718dac61c69cc55289553cbaa47 -r00a04da4497b53cd599b616deb0431c4cea9baeb --- Ringtoets/Common/src/Ringtoets.Common.Service/WaveHeightCalculationService.cs (.../WaveHeightCalculationService.cs) (revision 24e18b63dccdb718dac61c69cc55289553cbaa47) +++ Ringtoets/Common/src/Ringtoets.Common.Service/WaveHeightCalculationService.cs (.../WaveHeightCalculationService.cs) (revision 00a04da4497b53cd599b616deb0431c4cea9baeb) @@ -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; @@ -96,18 +97,19 @@ try { - calculator.Calculate(CreateInput(hydraulicBoundaryLocation, norm, hydraulicBoundaryDatabaseFilePath)); + WaveHeightCalculationInput calculationInput = CreateInput(hydraulicBoundaryLocation, norm, hydraulicBoundaryDatabaseFilePath); + calculator.Calculate(calculationInput); if (string.IsNullOrEmpty(calculator.LastErrorFileContent)) { hydraulicBoundaryLocation.WaveHeight = (RoundedDouble) calculator.WaveHeight; hydraulicBoundaryLocation.WaveHeightCalculationConvergence = RingtoetsCommonDataCalculationService.CalculationConverged(calculator.ReliabilityIndex, norm); - if (hydraulicBoundaryLocation.WaveHeightCalculationConvergence != CalculationConvergence.CalculatedConverged) - { - log.Warn(messageProvider.GetCalculatedNotConvergedMessage(hydraulicBoundaryLocation.Name)); - } + hydraulicBoundaryLocation.WaveHeightOutput = CreateHydraulicBoundaryLocationOutput(messageProvider, + hydraulicBoundaryLocation.Name, + calculationInput.Beta, + norm); } } catch (HydraRingFileParserException) @@ -154,6 +156,32 @@ } } + private HydraulicBoundaryLocationOutput CreateHydraulicBoundaryLocationOutput(ICalculationMessageProvider messageProvider, + string hydraulicBoundaryLocationName, + double targetReliability, + double targetProbability) + { + var designWaterLevel = calculator.WaveHeight; + 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 WaveHeightCalculationInput CreateInput(HydraulicBoundaryLocation hydraulicBoundaryLocation, double norm, string hydraulicBoundaryDatabaseFilePath) { var waveHeightCalculationInput = new WaveHeightCalculationInput(1, hydraulicBoundaryLocation.Id, norm); Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/WaveHeightCalculationActivityTest.cs =================================================================== diff -u -r122edb15a01ee908bf7774f862258b6606522c68 -r00a04da4497b53cd599b616deb0431c4cea9baeb --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/WaveHeightCalculationActivityTest.cs (.../WaveHeightCalculationActivityTest.cs) (revision 122edb15a01ee908bf7774f862258b6606522c68) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/WaveHeightCalculationActivityTest.cs (.../WaveHeightCalculationActivityTest.cs) (revision 00a04da4497b53cd599b616deb0431c4cea9baeb) @@ -123,11 +123,11 @@ calculationMessageProviderMock.Stub(calc => calc.GetCalculationName(locationName)).Return(calculationName).Repeat.AtLeastOnce(); mockRepository.ReplayAll(); - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, locationName, 0, 0) - { - WaveHeight = new RoundedDouble(2, double.NaN) - }; + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, locationName, 0, 0); + // Precondition + Assert.AreEqual((RoundedDouble)double.NaN, hydraulicBoundaryLocation.WaveHeight); + var activity = new WaveHeightCalculationActivity(hydraulicBoundaryLocation, inValidFilePath, string.Empty, 1, calculationMessageProviderMock); // Call @@ -156,11 +156,11 @@ const string ringId = "11-1"; const double norm = 1.0/30; - var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(0, locationName, 0, 0) - { - WaveHeight = new RoundedDouble(2, double.NaN) - }; + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(0, locationName, 0, 0); + // Precondition + Assert.AreEqual((RoundedDouble)double.NaN, hydraulicBoundaryLocation.WaveHeight); + var calculationMessageProviderMock = mockRepository.Stub(); calculationMessageProviderMock.Stub(calc => calc.GetActivityName(locationName)).Return(activityName); calculationMessageProviderMock.Stub(calc => calc.GetCalculationName(locationName)).Return(calculationName); Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/WaveHeightCalculationServiceTest.cs =================================================================== diff -u -rcd7078972189cf51d899754097ef3cbc0ddc26ee -r00a04da4497b53cd599b616deb0431c4cea9baeb --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/WaveHeightCalculationServiceTest.cs (.../WaveHeightCalculationServiceTest.cs) (revision cd7078972189cf51d899754097ef3cbc0ddc26ee) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/WaveHeightCalculationServiceTest.cs (.../WaveHeightCalculationServiceTest.cs) (revision 00a04da4497b53cd599b616deb0431c4cea9baeb) @@ -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.StrictMock(); @@ -158,14 +158,14 @@ new WaveHeightCalculationService().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); } @@ -186,6 +186,7 @@ { DesignWaterLevel = new RoundedDouble(2, double.NaN), }; + const double norm = 1.0/30; using (new HydraRingCalculatorFactoryConfig()) { @@ -198,7 +199,7 @@ service.Calculate(hydraulicBoundaryLocation, validFilePath, "ringId", - 30, + norm, calculationMessageProviderMock); // Assert @@ -216,6 +217,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(); @@ -244,7 +246,7 @@ new WaveHeightCalculationService().Calculate(hydraulicBoundaryLocation, validFilePath, "ringId", - 30, + norm, calculationMessageProviderMock); } catch (HydraRingFileParserException) @@ -278,6 +280,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(); @@ -305,7 +308,7 @@ new WaveHeightCalculationService().Calculate(hydraulicBoundaryLocation, validFilePath, "ringId", - 30, + norm, calculationMessageProviderMock); } catch (HydraRingFileParserException) @@ -339,6 +342,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(); @@ -368,7 +372,7 @@ new WaveHeightCalculationService().Calculate(hydraulicBoundaryLocation, validFilePath, "ringId", - 30, + norm, calculationMessageProviderMock); } catch (HydraRingCalculationException e) @@ -402,9 +406,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/HydraulicBoundaryLocationOutput.cs =================================================================== diff -u -r89a886bc06cf46e9742de7356a96c2a5fcc55f2a -r00a04da4497b53cd599b616deb0431c4cea9baeb --- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/HydraulicBoundaryLocationOutput.cs (.../HydraulicBoundaryLocationOutput.cs) (revision 89a886bc06cf46e9742de7356a96c2a5fcc55f2a) +++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Data/HydraulicBoundaryLocationOutput.cs (.../HydraulicBoundaryLocationOutput.cs) (revision 00a04da4497b53cd599b616deb0431c4cea9baeb) @@ -26,7 +26,7 @@ namespace Ringtoets.HydraRing.Data { /// - /// This class contains the result of assessment level calculation for an . + /// This class contains the result a calculation for a . /// public class HydraulicBoundaryLocationOutput { Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Data.TestUtil.Test/TestHydraulicBoundaryLocationTest.cs =================================================================== diff -u -re866d883e0603dc8613eebc581953a9b2a8f5986 -r00a04da4497b53cd599b616deb0431c4cea9baeb --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Data.TestUtil.Test/TestHydraulicBoundaryLocationTest.cs (.../TestHydraulicBoundaryLocationTest.cs) (revision e866d883e0603dc8613eebc581953a9b2a8f5986) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Data.TestUtil.Test/TestHydraulicBoundaryLocationTest.cs (.../TestHydraulicBoundaryLocationTest.cs) (revision 00a04da4497b53cd599b616deb0431c4cea9baeb) @@ -37,11 +37,16 @@ // Assert Assert.IsInstanceOf(testLocation); Assert.AreEqual(0, testLocation.Id); - Assert.IsEmpty(testLocation.Name); + Assert.IsEmpty(testLocation.Name); Assert.AreEqual(new Point2D(0, 0), testLocation.Location); Assert.IsNaN(testLocation.DesignWaterLevel); + Assert.IsNaN(testLocation.WaveHeight); Assert.AreEqual(CalculationConvergence.NotCalculated, testLocation.DesignWaterLevelCalculationConvergence); Assert.AreEqual(CalculationConvergence.NotCalculated, testLocation.WaveHeightCalculationConvergence); + + var expectedOutput = CreateHydraulicBoundaryLocationOutput(double.NaN); + AssertAreEqual(expectedOutput, testLocation.DesignWaterLevelOutput); + Assert.IsNull(testLocation.WaveHeightOutput); } [Test] @@ -56,12 +61,30 @@ // Assert Assert.IsInstanceOf(testLocation); Assert.AreEqual(0, testLocation.Id); - Assert.IsEmpty(testLocation.Name); + Assert.IsEmpty(testLocation.Name); Assert.AreEqual(new Point2D(0, 0), testLocation.Location); Assert.AreEqual(designWaterLevel, testLocation.DesignWaterLevel); Assert.AreEqual(CalculationConvergence.NotCalculated, testLocation.DesignWaterLevelCalculationConvergence); Assert.AreEqual(CalculationConvergence.NotCalculated, testLocation.WaveHeightCalculationConvergence); + + var expectedDesignWaterLevelOutput = CreateHydraulicBoundaryLocationOutput(designWaterLevel); + AssertAreEqual(expectedDesignWaterLevelOutput, testLocation.DesignWaterLevelOutput); + Assert.IsNull(testLocation.WaveHeightOutput); } - + + private static HydraulicBoundaryLocationOutput CreateHydraulicBoundaryLocationOutput(double result) + { + return new HydraulicBoundaryLocationOutput(result, 0, 0, 0, 0, CalculationConvergence.NotCalculated); + } + + private static void AssertAreEqual(HydraulicBoundaryLocationOutput expected, HydraulicBoundaryLocationOutput actual) + { + Assert.AreEqual(expected.Result, actual.Result, 1e-2); + Assert.AreEqual(expected.TargetReliability, actual.TargetReliability, 1e-5); + Assert.AreEqual(expected.TargetProbability, actual.TargetProbability); + Assert.AreEqual(expected.CalculatedReliability, actual.CalculatedReliability, 1e-5); + Assert.AreEqual(expected.CalculatedProbability, actual.CalculatedProbability); + Assert.AreEqual(expected.CalculationConvergence, actual.CalculationConvergence); + } } } \ No newline at end of file Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Data.TestUtil/TestHydraulicBoundaryLocation.cs =================================================================== diff -u -re866d883e0603dc8613eebc581953a9b2a8f5986 -r00a04da4497b53cd599b616deb0431c4cea9baeb --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Data.TestUtil/TestHydraulicBoundaryLocation.cs (.../TestHydraulicBoundaryLocation.cs) (revision e866d883e0603dc8613eebc581953a9b2a8f5986) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Data.TestUtil/TestHydraulicBoundaryLocation.cs (.../TestHydraulicBoundaryLocation.cs) (revision 00a04da4497b53cd599b616deb0431c4cea9baeb) @@ -19,7 +19,6 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; using Core.Common.Base.Data; namespace Ringtoets.HydraRing.Data.TestUtil @@ -35,14 +34,15 @@ /// specified design water level. /// /// The design water level of the location. - public TestHydraulicBoundaryLocation(RoundedDouble designWaterLevel) : base(0, String.Empty, 0, 0) + public TestHydraulicBoundaryLocation(RoundedDouble designWaterLevel) : base(0, string.Empty, 0, 0) { + DesignWaterLevelOutput = new HydraulicBoundaryLocationOutput(designWaterLevel, 0, 0, 0, 0, CalculationConvergence.NotCalculated); DesignWaterLevel = designWaterLevel; } /// /// Creates a new instance of . /// - public TestHydraulicBoundaryLocation() : this(RoundedDouble.NaN) { } + public TestHydraulicBoundaryLocation() : this(RoundedDouble.NaN) {} } } \ No newline at end of file