Change excel reading process
This commit is contained in:
@@ -24,6 +24,7 @@ namespace StructureHelperCommon.Models.Forces
|
||||
public double GlobalFactor { get; set; } = 1d;
|
||||
/// <inheritdoc/>
|
||||
public List<IColumnFileProperty> ColumnProperties { get; } = new();
|
||||
public bool SkipWrongRows { get; set; } = false;
|
||||
|
||||
public ColumnedFileProperty(Guid id)
|
||||
{
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace StructureHelperCommon.Models.Forces
|
||||
public IPoint2D ForcePoint { get; set; } = new Point2D();
|
||||
|
||||
public IFactoredCombinationProperty CombinationProperty { get; set; } = new FactoredCombinationProperty(Guid.NewGuid());
|
||||
public bool SkipWrongRows { get; set; } = false;
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
@@ -46,7 +47,11 @@ namespace StructureHelperCommon.Models.Forces
|
||||
|
||||
public List<IForceCombinationList> GetCombinations()
|
||||
{
|
||||
getTupleFromFileLogic ??= new GetTuplesFromFileLogic() { TraceLogger = new ShiftTraceLogger()};
|
||||
getTupleFromFileLogic = new GetTuplesFromFileLogic()
|
||||
{
|
||||
TraceLogger = new ShiftTraceLogger(),
|
||||
SkipWrongRows = SkipWrongRows,
|
||||
};
|
||||
factoredCombination = new ForceFactoredList();
|
||||
factoredCombination.ForceTuples.Clear();
|
||||
propertyUpdateStrategy ??= new FactoredCombinationPropertyUpdateStrategy();
|
||||
|
||||
@@ -15,5 +15,6 @@ namespace StructureHelperCommon.Models.Forces
|
||||
/// List of file properties for import combination
|
||||
/// </summary>
|
||||
List<IColumnedFileProperty> ForceFiles { get; set; }
|
||||
bool SkipWrongRows { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace StructureHelperCommon.Models.Forces
|
||||
if (ReferenceEquals(targetObject, sourceObject)) { return; }
|
||||
InitializeLogics();
|
||||
baseUpdateStrategy.Update(targetObject, sourceObject);
|
||||
targetObject.SkipWrongRows = sourceObject.SkipWrongRows;
|
||||
CheckObject.IsNull(targetObject.CombinationProperty, "Target object combination property");
|
||||
CheckObject.IsNull(sourceObject.CombinationProperty, "Source object combination property");
|
||||
combinationPropertyUpdateStrategy.Update(targetObject.CombinationProperty, sourceObject.CombinationProperty);
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace StructureHelperCommon.Models.Forces
|
||||
|
||||
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||
public IColumnedFileProperty ForceFileProperty { get; set; }
|
||||
public bool SkipWrongRows { get; internal set; }
|
||||
|
||||
public IForceTuple GetForceTuple(IExcelDataReader? reader)
|
||||
{
|
||||
@@ -38,10 +39,24 @@ namespace StructureHelperCommon.Models.Forces
|
||||
throw new StructureHelperException(ErrorStrings.NullReference + $": reader value for column {item.Name} in file {ForceFileProperty.FilePath}");
|
||||
}
|
||||
var readerValue = reader.GetValue(item.Index);
|
||||
if (readerValue is null)
|
||||
{
|
||||
if (SkipWrongRows == true)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.NullReference + $": wrong row in file {ForceFileProperty.FilePath}, total row number n = {reader.RowCount}");
|
||||
}
|
||||
}
|
||||
var strValue = readerValue.ToString();
|
||||
double factor = ForceFileProperty.GlobalFactor * item.Factor * 1000d;
|
||||
var doubleValue = Convert.ToDouble(strValue) * factor;
|
||||
fillArrayLogic ??= new FillTupleArrayByColumnNameLogic() { TraceLogger = TraceLogger };
|
||||
fillArrayLogic ??= new FillTupleArrayByColumnNameLogic()
|
||||
{
|
||||
TraceLogger = TraceLogger
|
||||
};
|
||||
fillArrayLogic.ProceeForceTupleArray(nDouble, doubleValue, item.Name, ForceFileProperty.FilePath);
|
||||
}
|
||||
TraceLogger?.AddMessage($"String values: Nz = {nDouble[0]}, Mx = {nDouble[1]}, My = {nDouble[2]} were gained", TraceLogStatuses.Debug);
|
||||
|
||||
@@ -4,6 +4,7 @@ using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
|
||||
@@ -35,6 +36,7 @@ namespace StructureHelperCommon.Models.Forces
|
||||
|
||||
public IColumnedFileProperty ForceFileProperty { get; set; }
|
||||
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||
public bool SkipWrongRows { get; set; } = false;
|
||||
|
||||
public List<IForceTuple> GetTuples()
|
||||
{
|
||||
@@ -56,7 +58,7 @@ namespace StructureHelperCommon.Models.Forces
|
||||
// Create an Excel reader
|
||||
using (var reader = ExcelReaderFactory.CreateReader(stream))
|
||||
{
|
||||
// Skip the first two header rows if necessary (adjust based on structure)
|
||||
// Skip the first header rows if necessary (adjust based on structure)
|
||||
for (int i = 0; i < skipRows; i++)
|
||||
{
|
||||
reader.Read(); // Skip row
|
||||
@@ -65,7 +67,8 @@ namespace StructureHelperCommon.Models.Forces
|
||||
excelReaderLogic ??= new GetTupleByExcelReaderLogic()
|
||||
{
|
||||
ForceFileProperty = ForceFileProperty,
|
||||
TraceLogger = TraceLogger
|
||||
TraceLogger = TraceLogger,
|
||||
SkipWrongRows = SkipWrongRows
|
||||
};
|
||||
|
||||
// Loop through the rows
|
||||
@@ -74,11 +77,13 @@ namespace StructureHelperCommon.Models.Forces
|
||||
try
|
||||
{
|
||||
IForceTuple newTuple = excelReaderLogic.GetForceTuple(reader);
|
||||
result.Add(newTuple);
|
||||
if (! result.Any(x => x.Mx == newTuple.Mx && x.My == newTuple.My && x.Nz == newTuple.Nz))
|
||||
{
|
||||
result.Add(newTuple);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//to do implement case when file has a data in the row, but thus date is not correct
|
||||
string errorString = ErrorStrings.DataIsInCorrect + $": incorrect data in file {ForceFileProperty.FilePath}, " + ex.Message;
|
||||
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
|
||||
throw new StructureHelperException(errorString);
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace StructureHelperCommon.Models.Forces
|
||||
{
|
||||
public interface IGetTuplesFromFileLogic : ILogic
|
||||
{
|
||||
bool SkipWrongRows { get; set; }
|
||||
IColumnedFileProperty ForceFileProperty { get; set; }
|
||||
|
||||
List<IForceTuple> GetTuples();
|
||||
|
||||
Reference in New Issue
Block a user