From 9427f9c692ea9668e54d7d7e0e1c7248e1460ded Mon Sep 17 00:00:00 2001 From: Markus Quaritsch <markus.quaritsch@tugraz.at> Date: Wed, 30 May 2018 14:24:04 +0200 Subject: [PATCH] DrivingCycle Reader: add stop time for first entry if stop-time is 0, duplicate entries with stop-time = 0 --- .../Reader/DrivingCycleDataReader.cs | 5 +- .../Impl/DrivingCycleEnumerator.cs | 130 +++++++++--------- .../OutputData/ModalDataContainer.cs | 4 +- 3 files changed, 71 insertions(+), 68 deletions(-) diff --git a/VectoCore/VectoCore/InputData/Reader/DrivingCycleDataReader.cs b/VectoCore/VectoCore/InputData/Reader/DrivingCycleDataReader.cs index ffda4dffa6..b1f78cf7c1 100644 --- a/VectoCore/VectoCore/InputData/Reader/DrivingCycleDataReader.cs +++ b/VectoCore/VectoCore/InputData/Reader/DrivingCycleDataReader.cs @@ -213,6 +213,9 @@ namespace TUGraz.VectoCore.InputData.Reader var altitude = current.Altitude; for (var i = 0; i < entries.Count; i++) { var entry = entries[i]; + if (i == 0 && entry.VehicleTargetSpeed.IsEqual(0) && entry.StoppingTime.IsEqual(0)) { + entry.StoppingTime = 1.SI<Second>(); + } if (!entry.StoppingTime.IsEqual(0) && !entry.VehicleTargetSpeed.IsEqual(0)) { throw new VectoException( "Error in DrivingCycle: stop time specified but target-speed > 0! Distance: {0}, stop-time: {1}, target speed: {2}", @@ -233,7 +236,7 @@ namespace TUGraz.VectoCore.InputData.Reader filtered.Add(entry); current = entry; } - if (!entry.StoppingTime.IsEqual(0) && entry.VehicleTargetSpeed.IsEqual(0)) { + if (entry.VehicleTargetSpeed.IsEqual(0)) { // vehicle stops. duplicate current distance entry with 0 waiting time var tmp = new DrivingCycleData.DrivingCycleEntry(entry) { StoppingTime = 0.SI<Second>(), diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DrivingCycleEnumerator.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DrivingCycleEnumerator.cs index 74f8018540..559b4896d8 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DrivingCycleEnumerator.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DrivingCycleEnumerator.cs @@ -30,16 +30,16 @@ */ using System; -using System.Collections.Generic; -using TUGraz.VectoCore.Models.SimulationComponent.Data; - -namespace TUGraz.VectoCore.Models.SimulationComponent.Impl -{ - public sealed class DrivingCycleEnumerator : IEnumerator<DrivingCycleData.DrivingCycleEntry> - { - private int _currentCycleIndex; - private readonly IDrivingCycleData _data; - +using System.Collections.Generic; +using TUGraz.VectoCore.Models.SimulationComponent.Data; + +namespace TUGraz.VectoCore.Models.SimulationComponent.Impl +{ + public sealed class DrivingCycleEnumerator : IEnumerator<DrivingCycleData.DrivingCycleEntry> + { + private int _currentCycleIndex; + private readonly IDrivingCycleData _data; + public DrivingCycleEnumerator(IDrivingCycleData data) { _currentCycleIndex = 0; @@ -52,59 +52,59 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var retVal = new DrivingCycleEnumerator(_data); retVal._currentCycleIndex = Math.Max(0, _currentCycleIndex - 1); return retVal; - } - - public DrivingCycleEnumerator Clone() - { - return new DrivingCycleEnumerator(_data) { - _currentCycleIndex = _currentCycleIndex, - LastEntry = LastEntry - }; - } - - public DrivingCycleData.DrivingCycleEntry Current - { - get { return LeftSample; } - } - - public DrivingCycleData.DrivingCycleEntry LeftSample - { - get { return _data.Entries[_currentCycleIndex]; } - } - - public DrivingCycleData.DrivingCycleEntry RightSample - { - get { return _currentCycleIndex + 1 >= _data.Entries.Count ? null : _data.Entries[_currentCycleIndex + 1]; } - } - - public bool LastEntry { get; private set; } - - object System.Collections.IEnumerator.Current - { - get { return LeftSample; } - } - - public bool MoveNext() - { - // cycleIndex has to be max. next to last (so that rightSample is still valid. - if (_currentCycleIndex >= _data.Entries.Count - 2) { - LastEntry = true; - return false; - } - _currentCycleIndex++; - if (_currentCycleIndex == _data.Entries.Count - 2) { - LastEntry = true; - } - - return true; - } - - public void Reset() - { - _currentCycleIndex = 0; - LastEntry = false; - } - - public void Dispose() {} - } + } + + public DrivingCycleEnumerator Clone() + { + return new DrivingCycleEnumerator(_data) { + _currentCycleIndex = _currentCycleIndex, + LastEntry = LastEntry + }; + } + + public DrivingCycleData.DrivingCycleEntry Current + { + get { return LeftSample; } + } + + public DrivingCycleData.DrivingCycleEntry LeftSample + { + get { return _data.Entries[_currentCycleIndex]; } + } + + public DrivingCycleData.DrivingCycleEntry RightSample + { + get { return _currentCycleIndex + 1 >= _data.Entries.Count ? null : _data.Entries[_currentCycleIndex + 1]; } + } + + public bool LastEntry { get; private set; } + + object System.Collections.IEnumerator.Current + { + get { return LeftSample; } + } + + public bool MoveNext() + { + // cycleIndex has to be max. next to last (so that rightSample is still valid. + if (_currentCycleIndex >= _data.Entries.Count - 2) { + LastEntry = true; + return false; + } + _currentCycleIndex++; + if (_currentCycleIndex == _data.Entries.Count - 2) { + LastEntry = true; + } + + return true; + } + + public void Reset() + { + _currentCycleIndex = 0; + LastEntry = false; + } + + public void Dispose() {} + } } \ No newline at end of file diff --git a/VectoCore/VectoCore/OutputData/ModalDataContainer.cs b/VectoCore/VectoCore/OutputData/ModalDataContainer.cs index 6e235c4402..d089ff8e19 100644 --- a/VectoCore/VectoCore/OutputData/ModalDataContainer.cs +++ b/VectoCore/VectoCore/OutputData/ModalDataContainer.cs @@ -79,8 +79,8 @@ namespace TUGraz.VectoCore.OutputData public bool WriteAdvancedAux { get; set; } - public ModalDataContainer(string runName, FuelType fuel, IModalDataWriter writer, bool writeEngineOnly = false) - : this(0, runName, "", fuel, "", writer, _ => { }, writeEngineOnly) {} + public ModalDataContainer(string runName, FuelType fuel, IModalDataWriter writer, bool writeEngineOnly = false, params IModalDataFilter[] filters) + : this(0, runName, "", fuel, "", writer, _ => { }, writeEngineOnly, filters) {} public ModalDataContainer(VectoRunData runData, IModalDataWriter writer, Action<ModalDataContainer> addReportResult, bool writeEngineOnly, params IModalDataFilter[] filter) -- GitLab