Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1949 data importer parsing unit should be case insensitive #1952

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions SolutionInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Runtime.CompilerServices;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyCompany("Open Systems Pharmacology Community")]
[assembly: AssemblyProduct("OSPSuite.Core")]
[assembly: AssemblyCopyright("Copyright � 2017 - present - Open Systems Pharmacology Community")]
Expand All @@ -9,4 +10,4 @@
[assembly: InternalsVisibleTo("OSPSuite.UI.Tests")]
[assembly: InternalsVisibleTo("OSPSuite.Presentation.Tests")]
[assembly: InternalsVisibleTo("OSPSuite.R.Tests")]
[assembly: InternalsVisibleTo("OSPSuite.Core.IntegrationTests")]
[assembly: InternalsVisibleTo("OSPSuite.Core.IntegrationTests")]
13 changes: 9 additions & 4 deletions src/OSPSuite.Core/Import/ImporterConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using OSPSuite.Core.Domain;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using OSPSuite.Core.Domain;

namespace OSPSuite.Core.Import
{
Expand All @@ -15,7 +15,12 @@ public void CloneParametersFrom(IReadOnlyList<DataFormatParameter> parameters)
{
_parameters = new List<DataFormatParameter>(parameters);
}
public void AddParameter(DataFormatParameter parameter) { _parameters.Add(parameter); }

public void AddParameter(DataFormatParameter parameter)
{
_parameters.Add(parameter);
}

public IReadOnlyList<string> LoadedSheets => _loadedSheets.ToList();
public string FileName { get; set; }
public string NamingConventions { get; set; }
Expand All @@ -31,4 +36,4 @@ public void RemoveParameter(DataFormatParameter element)
_parameters.Remove(element);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public BaseGridColumnNotFoundException(string columnName) : base(Error.BaseGridC
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public ColumnNotFoundException(string columnName) : base(Error.ColumnNotFound(co
{
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.UnitSystem;
Expand Down Expand Up @@ -76,7 +75,7 @@ private void setDimensionsForMappings(ColumnInfoCache columnInfos)
else
{
var supportedDimensions = concreteColumnInfo.SupportedDimensions;
var dimensionForUnit = supportedDimensions.FirstOrDefault(x => x.HasUnit(mappedColumn.Unit.SelectedUnit));
var dimensionForUnit = supportedDimensions.FirstOrDefault(x => x.SupportsUnit(mappedColumn.Unit.SelectedUnit, ignoreCase: true));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the one change that did not impact my failing test but should be done I believe?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed


if (dimensionForUnit == null)
mappedColumn.Unit = new UnitDescription(UnitDescription.InvalidUnit);
Expand Down Expand Up @@ -159,7 +158,12 @@ protected virtual void ExtractQualifiedHeadings(List<string> keys, List<string>

protected string ValidateUnit(string unit, IReadOnlyList<IDimension> supportedDimensions)
{
return supportedDimensions.Any(x => x.HasUnit(unit)) ? unit : UnitDescription.InvalidUnit;
var dimensionForUnit = supportedDimensions.FirstOrDefault(x => x.SupportsUnit(unit, ignoreCase: true));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was the one change that was required

if (dimensionForUnit == null)
return UnitDescription.InvalidUnit;

//We know it exists here as it was found previously
return dimensionForUnit.FindUnit(unit, ignoreCase: true).Name;
}

protected virtual void ExtractNonQualifiedHeadings(List<string> keys, List<string> missingKeys, Cache<string, ColumnInfo> columnInfos,
Expand Down Expand Up @@ -277,7 +281,7 @@ private Dictionary<ExtendedColumn, IList<SimulationPoint>> parseMappings(IEnumer
if (currentParameter == null) continue;
Func<MappingDataFormatParameter, DataSheet, UnformattedRow, SimulationPoint> mappingsParser =
currentParameter.MappedColumn.LloqColumn == null
? (Func<MappingDataFormatParameter, DataSheet, UnformattedRow, SimulationPoint>)parseMappingOnSameColumn
? (Func<MappingDataFormatParameter, DataSheet, UnformattedRow, SimulationPoint>) parseMappingOnSameColumn
: parseMappingOnSameGivenColumn;

dictionary.Add
Expand Down
15 changes: 10 additions & 5 deletions src/OSPSuite.Infrastructure.Import/Core/DataSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class UnformattedRow
{
public int Index { get; private set; }
public IEnumerable<string> Data { get; private set; }

public UnformattedRow(int index, IEnumerable<string> data)
{
Index = index;
Expand All @@ -21,7 +22,7 @@ public UnformattedRow(int index, IEnumerable<string> data)
public class DataSheet
{
private readonly List<List<string>> _rawDataTable = new List<List<string>>();
private List<string> _emptyColumns = new List<string>();
private readonly List<string> _emptyColumns = new List<string>();

protected Cache<string, ColumnDescription> _headers =
new Cache<string, ColumnDescription>(); //we have to ensure headers and RawSheetData sizes match
Expand All @@ -33,6 +34,7 @@ public DataSheet(DataSheet reference)
{
_headers.Add(header, reference.GetColumnDescription(header));
}

_rawDataTable = new List<List<string>>();
SheetName = reference.SheetName;
}
Expand All @@ -57,6 +59,7 @@ public void AddColumn(string columnName, int columnIndex) //it seems to me there
columnName = Guid.NewGuid().ToString();
_emptyColumns.Add(columnName);
}

_headers.Add(columnName, new ColumnDescription(columnIndex));
}

Expand All @@ -69,15 +72,16 @@ public void CalculateColumnDescription(List<ColumnDescription.MeasurementLevel>
});
}

public void AddRow( IEnumerable<string> row)
public void AddRow(IEnumerable<string> row)
{
var rowList = row.ToList();

if (_headers.Count > rowList.Count)
{
for ( var i = rowList.Count; i < _headers.Count; i++ )
for (var i = rowList.Count; i < _headers.Count; i++)
rowList.Add("");
}

if (rowList.Count > _headers.Count)
{
rowList = rowList.GetRange(0, _headers.Count);
Expand Down Expand Up @@ -105,7 +109,7 @@ public virtual IEnumerable<UnformattedRow> GetRows(Func<IEnumerable<string>, boo
public DataTable ToDataTable()
{
var resultTable = new DataTable();
var indexList = _headers.Select( h => h.Index);
var indexList = _headers.Select(h => h.Index);

// Add columns.
foreach (var header in _headers.Keys)
Expand Down Expand Up @@ -163,14 +167,15 @@ public void RemoveEmptyColumns()
{
header.DecrementIndex();
}

_headers.Remove(headerName);
_rawDataTable.ForEach(row => row.RemoveAt(index));
}
}

public void RemoveEmptyRows()
{
for (var i = _rawDataTable.Count -1; i >= 0; i--)
for (var i = _rawDataTable.Count - 1; i >= 0; i--)
{
if (_rawDataTable[i].All(x => x.IsNullOrEmpty()))
_rawDataTable.RemoveAt(i);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
Expand Down Expand Up @@ -68,17 +67,19 @@ public DataSheetCollection Filter(string filter)
{
ds.AddRow(drv.Row.ItemArray.Select(c => c.ToString()));
}

filteredDataSheets.AddSheet(ds);
}

return filteredDataSheets;
}

public void CopySheetsFrom (DataSheetCollection dataSheetsToCopy)
public void CopySheetsFrom(DataSheetCollection dataSheetsToCopy)
{
Clear();
_dataSheets.AddRange(dataSheetsToCopy._dataSheets);
}

public Cache<string, IDataSet> GetDataSets(IDataFormat format, ColumnInfoCache columnInfos)
{
var dataSets = new Cache<string, IDataSet>();
Expand Down
Loading