public void ReadLine_ValidFile_ReturnDataFromLine(int elementIndex, string expectedLocationId, string paramterId, double expectedNumericValue, double expectedVarianceValue, VarianceType expectedType) { // Setup string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("Structures", "StructuresCharacteristicsCsvFiles", "ValidFile_2Locations_AllHeightStructureParameters.csv")); using (var reader = new StructuresCharacteristicsCsvReader(filePath)) { // Call StructuresParameterRow parameter = null; for (var i = 0; i < elementIndex; i++) { parameter = reader.ReadLine(); } // Assert Assert.IsNotNull(parameter); Assert.AreEqual(expectedLocationId, parameter.LocationId); Assert.AreEqual(paramterId, parameter.ParameterId); Assert.AreEqual(expectedNumericValue, parameter.NumericalValue); Assert.AreEqual(expectedVarianceValue, parameter.VarianceValue); Assert.AreEqual(expectedType, parameter.VarianceType); Assert.AreEqual(elementIndex + 1, parameter.LineNumber); } }
/// <summary> /// Gets the coefficient of variation of a <see cref="StructuresParameterRow"/> /// of the structure. /// </summary> /// <param name="structuresParameterRow">The structure parameter row to read from.</param> /// <param name="structureName">The name of the structure.</param> /// <returns>The coefficient of variation of a structure parameter.</returns> /// <remarks>In case a standard deviation is encountered, /// it is automatically converted to a coefficient of variation.</remarks> protected RoundedDouble GetCoefficientOfVariation(StructuresParameterRow structuresParameterRow, string structureName) { if (structuresParameterRow.VarianceType == VarianceType.StandardDeviation) { Log.WarnFormat(Resources.StructuresImporter_GetCoefficientOfVariation_Converting_variation_StructureName_0_StructureId_1_ParameterId_2_on_Line_3_, structureName, structuresParameterRow.LocationId, structuresParameterRow.ParameterId, structuresParameterRow.LineNumber); return((RoundedDouble)(structuresParameterRow.VarianceValue / Math.Abs(structuresParameterRow.NumericalValue))); } return((RoundedDouble)structuresParameterRow.VarianceValue); }
public void Constructor_ExpectedValues() { // Call var parameter = new StructuresParameterRow(); // Assert Assert.IsNull(parameter.LocationId); Assert.IsNull(parameter.ParameterId); Assert.IsNull(parameter.AlphanumericValue); Assert.IsNaN(parameter.NumericalValue); Assert.IsNaN(parameter.VarianceValue); Assert.AreEqual(VarianceType.NotSpecified, parameter.VarianceType); Assert.AreEqual(-1, parameter.LineNumber); }
public void ReadLine_ValidFileWithNonEmptyAplhanumericValue_ReturnText() { // Setup string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("Structures", "StructuresCharacteristicsCsvFiles", "ValidFile_1Location_AllHeightStructureParameters_AlphanumericValueText.csv")); using (var reader = new StructuresCharacteristicsCsvReader(filePath)) { // Call StructuresParameterRow parameter = reader.ReadLine(); // Assert Assert.AreEqual("I'm the alphanumeric value in the file!", parameter.AlphanumericValue); } }
public void ReadLine_ValidFileWithEmptyVarianceType_ReturnNotSpecified() { // Setup string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("Structures", "StructuresCharacteristicsCsvFiles", "ValidFile_1Location_AllHeightStructureParameters_VarianceTypeEmpty.csv")); using (var reader = new StructuresCharacteristicsCsvReader(filePath)) { // Call StructuresParameterRow parameter = reader.ReadLine(); // Assert Assert.AreEqual(VarianceType.NotSpecified, parameter.VarianceType); } }
public void ReadLine_NoLocations_ReturnNull() { // Setup string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("Structures", "StructuresCharacteristicsCsvFiles", "ValidFile_0Locations.csv")); using (var reader = new StructuresCharacteristicsCsvReader(filePath)) { // Call StructuresParameterRow parameter = reader.ReadLine(); // Assert Assert.IsNull(parameter); } }
private ReadResult <StructuresParameterRow> ReadStructureParameterRowsData() { NotifyProgress(Resources.StructuresImporter_ReadStructureParameterRowsData_reading_structure_data, 1, 1); string csvFilePath = GetStructureDataCsvFilePath(); using (var rowsReader = new StructuresCharacteristicsCsvReader(csvFilePath)) { int totalNumberOfRows; try { totalNumberOfRows = rowsReader.GetLineCount(); } catch (CriticalFileReadException exception) { Log.Error(exception.Message); return(new ReadResult <StructuresParameterRow>(true)); } var rows = new List <StructuresParameterRow>(); for (var i = 0; i < totalNumberOfRows; i++) { if (Canceled) { return(new ReadResult <StructuresParameterRow>(false)); } NotifyProgress(Resources.StructuresImporter_ReadStructureParameterRowsData_reading_structuredata, i + 1, totalNumberOfRows); try { StructuresParameterRow row = rowsReader.ReadLine(); rows.Add(row); } catch (Exception exception) when(exception is CriticalFileReadException || exception is LineParseException) { Log.Error(exception.Message); return(new ReadResult <StructuresParameterRow>(true)); } } return(new ReadResult <StructuresParameterRow>(false) { Items = rows }); } }
public void GetCoefficientOfVariation_RowHasStandardDeviation_LogWarningReturnConvertedVarianceValue() { // Setup var messageProvider = mocks.Stub <IImporterMessageProvider>(); var updateStrategy = mocks.Stub <IStructureUpdateStrategy <TestStructure> >(); mocks.ReplayAll(); string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("Structures", "CorrectFiles", "Kunstwerken.shp")); var referenceLine = new ReferenceLine(); var importTarget = new StructureCollection <TestStructure>(); var importer = new TestStructuresImporter(importTarget, referenceLine, filePath, updateStrategy, messageProvider); var parameter = new StructuresParameterRow { AlphanumericValue = "", LineNumber = 3, LocationId = "A", NumericalValue = -3, ParameterId = "B", VarianceType = VarianceType.StandardDeviation, VarianceValue = 2.3 }; const string structureName = "<naam kunstwerk>"; // Call var coefficientOfVariation = (RoundedDouble)0.0; Action call = () => coefficientOfVariation = importer.GetCoefficientOfVariation(parameter, structureName); // Assert string expectedMessage = string.Format( "De variatie voor parameter '{2}' van kunstwerk '{0}' ({1}) wordt omgerekend in een variatiecoëfficiënt (regel {3}).", structureName, parameter.LocationId, parameter.ParameterId, parameter.LineNumber); TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(expectedMessage, LogLevelConstant.Warn), 1); double expectedStandardDeviation = parameter.VarianceValue / Math.Abs(parameter.NumericalValue); Assert.AreEqual(expectedStandardDeviation, coefficientOfVariation, coefficientOfVariation.GetAccuracy()); }
private static StabilityPointStructureInflowModelType GetStabilityPointStructureInflowModelType( StructuresParameterRow structureParameterRow) { string keywordValue = structureParameterRow.AlphanumericValue.ToLower(); switch (keywordValue) { case StructureFilesKeywords.InflowModelTypeLowSill: return(StabilityPointStructureInflowModelType.LowSill); case StructureFilesKeywords.InflowModelTypeFloodedCulvert: return(StabilityPointStructureInflowModelType.FloodedCulvert); default: throw new NotSupportedException(); } }
public void GetCoefficientOfVariation_RowHasCoefficientOfVariation_ReturnVarianceValue() { // Setup var messageProvider = mocks.Stub <IImporterMessageProvider>(); var updateStrategy = mocks.Stub <IStructureUpdateStrategy <TestStructure> >(); mocks.ReplayAll(); string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("Structures", "CorrectFiles", "Kunstwerken.shp")); var referenceLine = new ReferenceLine(); var importTarget = new StructureCollection <TestStructure>(); var importer = new TestStructuresImporter(importTarget, referenceLine, filePath, updateStrategy, messageProvider); var parameter = new StructuresParameterRow { AlphanumericValue = "", LineNumber = 3, LocationId = "A", NumericalValue = -3, ParameterId = "B", VarianceType = VarianceType.CoefficientOfVariation, VarianceValue = 2.3 }; // Call var coefficientOfVariation = (RoundedDouble)0.0; Action call = () => coefficientOfVariation = importer.GetCoefficientOfVariation(parameter, "<naam kunstwerk>"); // Assert TestHelper.AssertLogMessagesCount(call, 0); Assert.AreEqual(parameter.VarianceValue, coefficientOfVariation, coefficientOfVariation.GetAccuracy()); }
public void SimpleProperties_SetNewValues_GetNewlySetValues(string locationId, string id, string alphanumeric, double numerical, double variance, VarianceType type, int lineNumber) { // Setup var parameter = new StructuresParameterRow(); // Call parameter.LocationId = locationId; parameter.ParameterId = id; parameter.AlphanumericValue = alphanumeric; parameter.NumericalValue = numerical; parameter.VarianceValue = variance; parameter.VarianceType = type; parameter.LineNumber = lineNumber; // Assert Assert.AreEqual(locationId, parameter.LocationId); Assert.AreEqual(id, parameter.ParameterId); Assert.AreEqual(alphanumeric, parameter.AlphanumericValue); Assert.AreEqual(numerical, parameter.NumericalValue); Assert.AreEqual(variance, parameter.VarianceValue); Assert.AreEqual(type, parameter.VarianceType); Assert.AreEqual(lineNumber, parameter.LineNumber); }
public new RoundedDouble GetStandardDeviation(StructuresParameterRow parameter, string structureName) { return(base.GetStandardDeviation(parameter, structureName)); }
public new RoundedDouble GetCoefficientOfVariation(StructuresParameterRow parameter, string structureName) { return(base.GetCoefficientOfVariation(parameter, structureName)); }