From bb38d6619e36ecdc1b743bdc9259642ba52242d7 Mon Sep 17 00:00:00 2001 From: Michael Krisper <michael.krisper@tugraz.at> Date: Wed, 24 Aug 2016 11:51:52 +0200 Subject: [PATCH] DrivingCycleDataReader: Aux Column check corrected --- .../Reader/DrivingCycleDataReader.cs | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/VectoCore/VectoCore/InputData/Reader/DrivingCycleDataReader.cs b/VectoCore/VectoCore/InputData/Reader/DrivingCycleDataReader.cs index 7f00b97f95..f4fc790a21 100644 --- a/VectoCore/VectoCore/InputData/Reader/DrivingCycleDataReader.cs +++ b/VectoCore/VectoCore/InputData/Reader/DrivingCycleDataReader.cs @@ -43,7 +43,7 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.InputData.Reader { - public class DrivingCycleDataReader : LoggingObject + public static class DrivingCycleDataReader { /// <summary> /// Detects the appropriate cycle type for a cycle in a DataTable. @@ -136,7 +136,8 @@ namespace TUGraz.VectoCore.InputData.Reader public static DrivingCycleData ReadFromDataTable(DataTable data, string name, bool crossWindRequired) { if (data == null) { - Logger<DistanceBasedCycleDataParser>().Warn("Invalid data for DrivingCycle -- dataTable is null"); + LogManager.GetLogger(typeof(DrivingCycleDataReader).FullName) + .Warn("Invalid data for DrivingCycle -- dataTable is null"); throw new VectoException("Invalid data for DrivingCycle -- dataTable is null"); } return ReadFromDataTable(data, DetectCycleType(data), name, crossWindRequired); @@ -153,7 +154,8 @@ namespace TUGraz.VectoCore.InputData.Reader public static DrivingCycleData ReadFromDataTable(DataTable data, CycleType type, string name, bool crossWindRequired) { if (data == null) { - Logger<DistanceBasedCycleDataParser>().Warn("Invalid data for DrivingCycle -- dataTable is null"); + LogManager.GetLogger(typeof(DrivingCycleDataReader).FullName) + .Warn("Invalid data for DrivingCycle -- dataTable is null"); throw new VectoException("Invalid data for DrivingCycle -- dataTable is null"); } var entries = GetDataParser(type).Parse(data, crossWindRequired).ToList(); @@ -232,7 +234,7 @@ namespace TUGraz.VectoCore.InputData.Reader distance = entry.Distance; } - Logger<DrivingCycleDataReader>() + LogManager.GetLogger(typeof(DrivingCycleDataReader).FullName) .Info("Data loaded. Number of Entries: {0}, filtered Entries: {1}", entries.Count, filtered.Count); entries = filtered; @@ -243,13 +245,14 @@ namespace TUGraz.VectoCore.InputData.Reader private static void AdjustDistanceAfterStop(List<DrivingCycleData.DrivingCycleEntry> entries) { - var currentIt = entries.GetEnumerator(); - var nextIt = entries.GetEnumerator(); - nextIt.MoveNext(); - while (currentIt.MoveNext() && nextIt.MoveNext()) { - if (currentIt.Current != null && !currentIt.Current.StoppingTime.IsEqual(0)) { - if (nextIt.Current != null) { - nextIt.Current.Distance = currentIt.Current.Distance; + using (var currentIt = entries.GetEnumerator()) + using (var nextIt = entries.GetEnumerator()) { + nextIt.MoveNext(); + while (currentIt.MoveNext() && nextIt.MoveNext()) { + if (currentIt.Current != null && !currentIt.Current.StoppingTime.IsEqual(0)) { + if (nextIt.Current != null) { + nextIt.Current.Distance = currentIt.Current.Distance; + } } } } @@ -297,7 +300,6 @@ namespace TUGraz.VectoCore.InputData.Reader public const string VehicleSpeed = "v"; public const string RoadGradient = "grad"; public const string StoppingTime = "stop"; - public const string AuxiliarySupplyPower = "Aux_"; public const string EngineSpeed = "n"; public const string Gear = "gear"; public const string AdditionalAuxPowerDemand = "Padd"; @@ -320,7 +322,7 @@ namespace TUGraz.VectoCore.InputData.Reader IEnumerable<DrivingCycleData.DrivingCycleEntry> Parse(DataTable table, bool crossWindRequired); } - private abstract class AbstractCycleDataParser : ICycleDataParser + private abstract class AbstractCycleDataParser : LoggingObject, ICycleDataParser { protected static bool CheckColumns(string[] header, IEnumerable<string> allowedCols, IEnumerable<string> requiredCols, bool throwExceptions, bool allowAux) @@ -334,7 +336,7 @@ namespace TUGraz.VectoCore.InputData.Reader } if (allowAux) { - header = header.Where(c => !c.StartsWith(Fields.AuxiliarySupplyPower)).ToArray(); + header = header.Where(c => !c.ToUpper().StartsWith(Constants.Auxiliaries.Prefix)).ToArray(); } diff = header.Except(allowedCols).ToList(); @@ -488,8 +490,9 @@ namespace TUGraz.VectoCore.InputData.Reader var containsBoth = header.Contains(Fields.EngineTorque) && header.Contains(Fields.EnginePower); if (containsBoth) { - Logger<DrivingCycleDataReader>().Warn("Found column '{0}' and column '{1}': Only column '{0}' will be used.", - Fields.EngineTorque, Fields.EnginePower); + LogManager.GetLogger(typeof(EngineOnlyCycleDataParser).FullName) + .Warn("Found column '{0}' and column '{1}': Only column '{0}' will be used.", + Fields.EngineTorque, Fields.EnginePower); } return true; } -- GitLab