Index: Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SoilProfile1D.cs
===================================================================
diff -u -ra98b1f041d0befb17b61cbab82450309521c2fc7 -r6f3f1fabca21935a2198e59ee423f833b75a3d36
--- Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SoilProfile1D.cs (.../SoilProfile1D.cs) (revision a98b1f041d0befb17b61cbab82450309521c2fc7)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SoilProfile1D.cs (.../SoilProfile1D.cs) (revision 6f3f1fabca21935a2198e59ee423f833b75a3d36)
@@ -36,6 +36,7 @@
///
/// Creates a new instance of .
///
+ /// The database identifier of the soil profile.
/// The name of the profile.
/// The bottom level of the profile.
/// The collection of layers that should be part of the profile.
@@ -47,13 +48,16 @@
///
///
///
- public SoilProfile1D(string name, double bottom, IEnumerable layers)
+ public SoilProfile1D(long id, string name, double bottom, IEnumerable layers)
{
+ Id = id;
Name = name;
Bottom = bottom;
Layers = layers;
}
+ public long Id { get; }
+
///
/// Gets the bottom level of the .
///
Index: Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SoilProfile1DReader.cs
===================================================================
diff -u -r1d91b8411e6db990c17fade0ad12aa8ac0e54865 -r6f3f1fabca21935a2198e59ee423f833b75a3d36
--- Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SoilProfile1DReader.cs (.../SoilProfile1DReader.cs) (revision 1d91b8411e6db990c17fade0ad12aa8ac0e54865)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SoilProfile1DReader.cs (.../SoilProfile1DReader.cs) (revision 6f3f1fabca21935a2198e59ee423f833b75a3d36)
@@ -80,7 +80,6 @@
try
{
SoilProfile1D soilProfile = TryReadSoilProfile();
- MoveNext();
return soilProfile;
}
catch (SystemException exception) when (exception is FormatException ||
@@ -139,7 +138,10 @@
MoveNext();
}
- return new SoilProfile1D(properties.ProfileName, properties.Bottom, soilLayers);
+ return new SoilProfile1D(properties.ProfileId,
+ properties.ProfileName,
+ properties.Bottom,
+ soilLayers);
}
private void PrepareReader()
Index: Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/StochasticSoilModelReader.cs
===================================================================
diff -u -rbe3fdb23bcc3b82eb8766e2cc22221862634224e -r6f3f1fabca21935a2198e59ee423f833b75a3d36
--- Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/StochasticSoilModelReader.cs (.../StochasticSoilModelReader.cs) (revision be3fdb23bcc3b82eb8766e2cc22221862634224e)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/StochasticSoilModelReader.cs (.../StochasticSoilModelReader.cs) (revision 6f3f1fabca21935a2198e59ee423f833b75a3d36)
@@ -20,6 +20,7 @@
// All rights reserved.
using System;
+using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using Core.Common.Base.IO;
@@ -35,9 +36,9 @@
///
public class StochasticSoilModelReader : SqLiteDatabaseReaderBase
{
+ private readonly Dictionary soilProfile1Ds = new Dictionary();
private IDataReader dataReader;
private SegmentPointReader segmentPointReader;
- private SoilProfile1DReader soilProfile1DReader;
///
/// Creates a new instance of ,
@@ -75,6 +76,7 @@
VerifyVersion(Path);
VerifyConstraints(Path);
InitializeReaders();
+ InitializeLookups();
}
///
@@ -115,12 +117,33 @@
segmentPointReader = null;
}
- if (soilProfile1DReader != null)
+ base.Dispose(disposing);
+ }
+
+ private void InitializeLookups()
+ {
+ using (var soilProfile1DReader = new SoilProfile1DReader(Path))
{
- soilProfile1DReader.Dispose();
- soilProfile1DReader = null;
+ soilProfile1DReader.Initialize();
+
+ while (soilProfile1DReader.HasNext)
+ {
+ try
+ {
+ SoilProfile1D soilProfile1D = soilProfile1DReader.ReadSoilProfile();
+
+ long soilProfileId = soilProfile1D.Id;
+ if (!soilProfile1Ds.ContainsKey(soilProfileId))
+ {
+ soilProfile1Ds.Add(soilProfileId, soilProfile1D);
+ }
+ }
+ catch (SoilProfileReadException)
+ {
+ soilProfile1DReader.MoveNext();
+ }
+ }
}
- base.Dispose(disposing);
}
private StochasticSoilModel TryReadStochasticSoilModel()
@@ -131,16 +154,54 @@
}
StochasticSoilModel stochasticSoilModel = CreateStochasticSoilModel();
- long currentSegmentSoilModelId = ReadStochasticSoilModelSegmentId();
- do
+ long currentSoilModelId = ReadStochasticSoilModelSegmentId();
+
+ stochasticSoilModel.Geometry.AddRange(segmentPointReader.ReadSegmentPoints(currentSoilModelId));
+ stochasticSoilModel.StochasticSoilProfiles.AddRange(ReadStochasticSoilProfiles(currentSoilModelId));
+
+ return stochasticSoilModel;
+ }
+
+ private IEnumerable ReadStochasticSoilProfiles(long stochasticSoilModelId)
+ {
+ while (HasNext && ReadStochasticSoilModelSegmentId() == stochasticSoilModelId)
{
- stochasticSoilModel.Geometry.AddRange(segmentPointReader.ReadSegmentPoints(currentSegmentSoilModelId));
+ double probability = ReadStochasticSoilProfileProbability();
+
+ long? soilProfile1D = ReadSoilProfile1DId();
+ if (soilProfile1D.HasValue)
+ {
+ if (soilProfile1Ds.ContainsKey(soilProfile1D.Value))
+ {
+ yield return new StochasticSoilProfile(probability, soilProfile1Ds[soilProfile1D.Value]);
+ }
+ }
+
MoveNext();
- } while (HasNext && ReadStochasticSoilModelSegmentId() == currentSegmentSoilModelId);
+ }
+ }
- return stochasticSoilModel;
+ private double ReadStochasticSoilProfileProbability()
+ {
+ return Convert.ToDouble(dataReader[StochasticSoilProfileTableDefinitions.Probability]);
}
+ private long? ReadSoilProfile1DId()
+ {
+ object soilProfile1DId = dataReader[StochasticSoilProfileTableDefinitions.SoilProfile1DId];
+ return soilProfile1DId == Convert.DBNull
+ ? (long?) null
+ : Convert.ToInt64(soilProfile1DId);
+ }
+
+ private long? ReadSoilProfile2DId()
+ {
+ object soilProfile2DId = dataReader[StochasticSoilProfileTableDefinitions.SoilProfile2DId];
+ return soilProfile2DId == Convert.DBNull
+ ? (long?) null
+ : Convert.ToInt64(soilProfile2DId);
+ }
+
private long ReadStochasticSoilModelSegmentId()
{
return Convert.ToInt64(dataReader[StochasticSoilModelTableDefinitions.StochasticSoilModelId]);
@@ -166,9 +227,6 @@
segmentPointReader = new SegmentPointReader(Path);
segmentPointReader.Initialize();
-
- soilProfile1DReader = new SoilProfile1DReader(Path);
- soilProfile1DReader.Initialize();
}
private void MoveNext()
Index: Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/StochasticSoilProfile.cs
===================================================================
diff -u -r58d98ab4a0a75497b2752eff1a931f6f7ee3fa8a -r6f3f1fabca21935a2198e59ee423f833b75a3d36
--- Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/StochasticSoilProfile.cs (.../StochasticSoilProfile.cs) (revision 58d98ab4a0a75497b2752eff1a931f6f7ee3fa8a)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/StochasticSoilProfile.cs (.../StochasticSoilProfile.cs) (revision 6f3f1fabca21935a2198e59ee423f833b75a3d36)
@@ -38,16 +38,14 @@
///
/// Creates a new instance of .
///
- /// Database identifier of the stochastic soil profile.
/// Probability of the stochastic soil profile.
/// The soil profile.
/// Thrown when the
/// is outside the range [0, 1].
- public StochasticSoilProfile(long soilProfileId, double probability, ISoilProfile soilProfile)
+ public StochasticSoilProfile(double probability, ISoilProfile soilProfile)
{
Probability = probability;
SoilProfile = soilProfile;
- SoilProfileId = soilProfileId;
}
///
@@ -56,11 +54,6 @@
public ISoilProfile SoilProfile { get; }
///
- /// Gets the database identifier of the stochastic soil profile.
- ///
- public long SoilProfileId { get; }
-
- ///
/// Gets the probability of the stochastic soil profile.
///
/// Thrown when the
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/SoilProfile1DTest.cs
===================================================================
diff -u -ra98b1f041d0befb17b61cbab82450309521c2fc7 -r6f3f1fabca21935a2198e59ee423f833b75a3d36
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/SoilProfile1DTest.cs (.../SoilProfile1DTest.cs) (revision a98b1f041d0befb17b61cbab82450309521c2fc7)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/SoilProfile1DTest.cs (.../SoilProfile1DTest.cs) (revision 6f3f1fabca21935a2198e59ee423f833b75a3d36)
@@ -19,7 +19,6 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
-using System;
using NUnit.Framework;
using Ringtoets.Common.IO.SoilProfile;
@@ -32,6 +31,7 @@
public void Constructor_ValidArguments_ReturnsExpectedProperties()
{
// Setup
+ const long id = 123;
const string name = "some name";
const int bottom = 1;
var soilLayer1Ds = new[]
@@ -40,10 +40,11 @@
};
// Call
- var soilProfile1D = new SoilProfile1D(name, bottom, soilLayer1Ds);
+ var soilProfile1D = new SoilProfile1D(id, name, bottom, soilLayer1Ds);
// Assert
Assert.IsInstanceOf(soilProfile1D);
+ Assert.AreEqual(id, soilProfile1D.Id);
Assert.AreEqual(name, soilProfile1D.Name);
Assert.AreEqual(bottom, soilProfile1D.Bottom);
CollectionAssert.AreEqual(soilLayer1Ds, soilProfile1D.Layers);
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilModelReaderTest.cs
===================================================================
diff -u -rbe3fdb23bcc3b82eb8766e2cc22221862634224e -r6f3f1fabca21935a2198e59ee423f833b75a3d36
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilModelReaderTest.cs (.../StochasticSoilModelReaderTest.cs) (revision be3fdb23bcc3b82eb8766e2cc22221862634224e)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilModelReaderTest.cs (.../StochasticSoilModelReaderTest.cs) (revision 6f3f1fabca21935a2198e59ee423f833b75a3d36)
@@ -278,9 +278,21 @@
606
};
+ var expected1DProfileCount = new[]
+ {
+ 0,
+ 10,
+ 6,
+ 6,
+ 8,
+ 8
+ };
+
+
Assert.AreEqual(expectedSegmentAndModelNames.Length, readModels.Count);
CollectionAssert.AreEqual(expectedSegmentAndModelNames, readModels.Select(m => m.Name));
CollectionAssert.AreEqual(expectedSegmentPointCount, readModels.Select(m => m.Geometry.Count));
+ CollectionAssert.AreEqual(expected1DProfileCount, readModels.Select(m => m.StochasticSoilProfiles.Select(ssp => ssp.SoilProfile).OfType().Count()));
Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile));
}
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilProfileTest.cs
===================================================================
diff -u -r58d98ab4a0a75497b2752eff1a931f6f7ee3fa8a -r6f3f1fabca21935a2198e59ee423f833b75a3d36
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilProfileTest.cs (.../StochasticSoilProfileTest.cs) (revision 58d98ab4a0a75497b2752eff1a931f6f7ee3fa8a)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilProfileTest.cs (.../StochasticSoilProfileTest.cs) (revision 6f3f1fabca21935a2198e59ee423f833b75a3d36)
@@ -44,11 +44,8 @@
var soilProfile = mockRepository.Stub();
mockRepository.ReplayAll();
- var random = new Random(9);
- int soilProfileId = random.Next();
-
// Call
- TestDelegate test = () => new StochasticSoilProfile(soilProfileId, probability, soilProfile);
+ TestDelegate test = () => new StochasticSoilProfile(probability, soilProfile);
// Assert
const string expectedMessage = "Het aandeel van de ondergrondschematisatie in het stochastische ondergrondmodel moet in het bereik [0,0, 1,0] liggen.";
@@ -67,15 +64,13 @@
var random = new Random(9);
double probability = random.NextDouble();
- int soilProfileId = random.Next();
// Call
- var profile = new StochasticSoilProfile(soilProfileId, probability, soilProfile);
+ var profile = new StochasticSoilProfile(probability, soilProfile);
// Assert
Assert.AreEqual(probability, profile.Probability);
Assert.AreSame(soilProfile, profile.SoilProfile);
- Assert.AreEqual(soilProfileId, profile.SoilProfileId);
mockRepository.VerifyAll();
}