From ca12ee19339972b56f071c201361fcfadcb0057f Mon Sep 17 00:00:00 2001 From: Markus Quaritsch <markus.quaritsch@tugraz.at> Date: Tue, 23 Feb 2016 18:33:53 +0100 Subject: [PATCH] split driver data into engineering and declaration, separate engineerign and declaration input data provider (top level) --- .../InputData/FileIO/JSON/JSONInputData.cs | 31 ++++++++++++++++--- .../FileIO/JSON/JSONInputDataFactory.cs | 2 +- VectoCore/InputData/IInputDataProvider.cs | 20 ++++++------ VectoCore/InputData/Impl/InputData.cs | 4 +-- VectoCore/InputData/InputData.cs | 27 ++++++++++++---- .../DeclarationDataAdapter.cs | 2 +- .../EngineeringDataAdapter.cs | 2 +- VectoCoreTest/FileIO/JsonTest.cs | 25 ++++++++------- .../FileIO/SimulationDataReaderTest.cs | 8 ++++- .../Simulation/PowerTrainBuilderTest.cs | 8 ++++- .../Utils/MockSimulationDataFactory.cs | 7 ++++- 11 files changed, 96 insertions(+), 40 deletions(-) diff --git a/VectoCore/InputData/FileIO/JSON/JSONInputData.cs b/VectoCore/InputData/FileIO/JSON/JSONInputData.cs index fbec2083e3..fe36741ec0 100644 --- a/VectoCore/InputData/FileIO/JSON/JSONInputData.cs +++ b/VectoCore/InputData/FileIO/JSON/JSONInputData.cs @@ -173,8 +173,8 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON /// } /// } /// </code> - public class JSONInputDataV2 : JSONFile, IEngineeringInputDataProvider, IEngineeringJobInputData, IDriverInputData, - IAuxiliariesEngineeringInputData + public class JSONInputDataV2 : JSONFile, IEngineeringInputDataProvider, IDeclarationInputDataProvider, + IEngineeringJobInputData, IDriverEngineeringInputData, IAuxiliariesEngineeringInputData { protected IGearboxEngineeringInputData Gearbox; @@ -304,6 +304,11 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON return this; } + IDriverEngineeringInputData IEngineeringInputDataProvider.DriverInputData + { + get { return this; } + } + IAuxiliariesDeclarationInputData IDeclarationInputDataProvider.AuxiliaryInputData() { return AuxiliaryInputData(); @@ -320,7 +325,7 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON } } - public virtual IDriverInputData DriverInputData + public virtual IDriverDeclarationInputData DriverInputData { get { return this; } } @@ -383,7 +388,7 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON #region DriverInputData - public virtual IStartStopInputData StartStop + public virtual IStartStopEngineeringInputData StartStop { get { @@ -397,6 +402,17 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON } } + IOverSpeedEcoRollDeclarationInputData IDriverDeclarationInputData.OverSpeedEcoRoll + { + get + { + var overspeed = Body.GetEx(JsonKeys.DriverData_OverspeedEcoRoll); + return new OverSpeedEcoRollInputData() { + Mode = DriverData.ParseDriverMode(overspeed.GetEx<string>(JsonKeys.DriverData_OverspeedEcoRoll_Mode)) + }; + } + } + public virtual ILookaheadCoastingInputData Lookahead { get @@ -410,7 +426,12 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON } } - public virtual IOverSpeedEcoRollInputData OverSpeedEcoRoll + IStartStopDeclarationInputData IDriverDeclarationInputData.StartStop + { + get { return StartStop; } + } + + public virtual IOverSpeedEcoRollEngineeringInputData OverSpeedEcoRoll { get { diff --git a/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs b/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs index 4084181d9c..7769d99591 100644 --- a/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs +++ b/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs @@ -35,7 +35,7 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON } } - public static IEngineeringInputDataProvider ReadJsonJob(string filename) + public static IInputDataProvider ReadJsonJob(string filename) { var json = ReadFile(filename); var version = ReadVersion(json); diff --git a/VectoCore/InputData/IInputDataProvider.cs b/VectoCore/InputData/IInputDataProvider.cs index 788082e59d..aa0ce19f26 100644 --- a/VectoCore/InputData/IInputDataProvider.cs +++ b/VectoCore/InputData/IInputDataProvider.cs @@ -39,26 +39,26 @@ namespace TUGraz.VectoCore.InputData IRetarderInputData RetarderInputData { get; } - IDriverInputData DriverInputData { get; } + IDriverDeclarationInputData DriverInputData { get; } } - public interface IEngineeringInputDataProvider : IDeclarationInputDataProvider + public interface IEngineeringInputDataProvider : IInputDataProvider { - new IEngineeringJobInputData JobInputData(); + IEngineeringJobInputData JobInputData(); - new IVehicleEngineeringInputData VehicleInputData { get; } + IVehicleEngineeringInputData VehicleInputData { get; } - new IGearboxEngineeringInputData GearboxInputData { get; } + IGearboxEngineeringInputData GearboxInputData { get; } - //IAxleGearInputData AxleGearInputData { get; } + IAxleGearInputData AxleGearInputData { get; } - new IEngineEngineeringInputData EngineInputData { get; } + IEngineEngineeringInputData EngineInputData { get; } - new IAuxiliariesEngineeringInputData AuxiliaryInputData(); + IAuxiliariesEngineeringInputData AuxiliaryInputData(); - //IRetarderInputData RetarderInputData { get; } + IRetarderInputData RetarderInputData { get; } - //IDriverInputData DriverInputData { get; } + IDriverEngineeringInputData DriverInputData { get; } } } \ No newline at end of file diff --git a/VectoCore/InputData/Impl/InputData.cs b/VectoCore/InputData/Impl/InputData.cs index 7ed9cee7c4..b6c4681ed9 100644 --- a/VectoCore/InputData/Impl/InputData.cs +++ b/VectoCore/InputData/Impl/InputData.cs @@ -32,7 +32,7 @@ namespace TUGraz.VectoCore.InputData.Impl public DataTable CycleData { get; internal set; } } - public class StartStopInputData : IStartStopInputData + public class StartStopInputData : IStartStopEngineeringInputData { public bool Enabled { get; internal set; } @@ -52,7 +52,7 @@ namespace TUGraz.VectoCore.InputData.Impl public MeterPerSecond MinSpeed { get; internal set; } } - public class OverSpeedEcoRollInputData : IOverSpeedEcoRollInputData + public class OverSpeedEcoRollInputData : IOverSpeedEcoRollEngineeringInputData { public DriverData.DriverMode Mode { get; internal set; } diff --git a/VectoCore/InputData/InputData.cs b/VectoCore/InputData/InputData.cs index dca192a577..f10c940f0d 100644 --- a/VectoCore/InputData/InputData.cs +++ b/VectoCore/InputData/InputData.cs @@ -472,29 +472,41 @@ namespace TUGraz.VectoCore.InputData DataTable CycleData { get; } } - public interface IDriverInputData + public interface IDriverDeclarationInputData { bool SavedInDeclarationMode { get; } - IStartStopInputData StartStop { get; } - ILookaheadCoastingInputData Lookahead { get; } - IOverSpeedEcoRollInputData OverSpeedEcoRoll { get; } + IStartStopDeclarationInputData StartStop { get; } + + IOverSpeedEcoRollDeclarationInputData OverSpeedEcoRoll { get; } + } + + public interface IDriverEngineeringInputData : IDriverDeclarationInputData + { + new IStartStopEngineeringInputData StartStop { get; } + + new IOverSpeedEcoRollEngineeringInputData OverSpeedEcoRoll { get; } /// <summary> /// P009; P033, P034, P035 /// cf. VECTO Input Parameters.xlsx /// </summary> DataTable AccelerationCurve { get; } + + ILookaheadCoastingInputData Lookahead { get; } } - public interface IOverSpeedEcoRollInputData + public interface IOverSpeedEcoRollDeclarationInputData { /// <summary> /// P015 /// cf. VECTO Input Parameters.xlsx /// </summary> DriverData.DriverMode Mode { get; } + } + public interface IOverSpeedEcoRollEngineeringInputData : IOverSpeedEcoRollDeclarationInputData + { /// <summary> /// P016 /// cf. VECTO Input Parameters.xlsx @@ -535,14 +547,17 @@ namespace TUGraz.VectoCore.InputData MeterPerSecond MinSpeed { get; } } - public interface IStartStopInputData + public interface IStartStopDeclarationInputData { /// <summary> /// P010 StartStop - enabled /// cf. VECTO Input Parameters.xlsx /// </summary> bool Enabled { get; } + } + public interface IStartStopEngineeringInputData : IStartStopDeclarationInputData + { /// <summary> /// P011 StartStop - Max speed /// cf. VECTO Input Parameters.xlsx diff --git a/VectoCore/InputData/Reader/DataObjectAdaper/DeclarationDataAdapter.cs b/VectoCore/InputData/Reader/DataObjectAdaper/DeclarationDataAdapter.cs index af7ce93c28..96bf97d7d6 100644 --- a/VectoCore/InputData/Reader/DataObjectAdaper/DeclarationDataAdapter.cs +++ b/VectoCore/InputData/Reader/DataObjectAdaper/DeclarationDataAdapter.cs @@ -33,7 +33,7 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdaper { public class DeclarationDataAdapter : AbstractSimulationDataAdapter { - public DriverData CreateDriverData(IDriverInputData data) + public DriverData CreateDriverData(IDriverDeclarationInputData data) { if (!data.SavedInDeclarationMode) { WarnDeclarationMode("DriverData"); diff --git a/VectoCore/InputData/Reader/DataObjectAdaper/EngineeringDataAdapter.cs b/VectoCore/InputData/Reader/DataObjectAdaper/EngineeringDataAdapter.cs index 8fabe6f85d..2f52ae3e26 100644 --- a/VectoCore/InputData/Reader/DataObjectAdaper/EngineeringDataAdapter.cs +++ b/VectoCore/InputData/Reader/DataObjectAdaper/EngineeringDataAdapter.cs @@ -159,7 +159,7 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdaper }).Concat(new VectoRunData.AuxData { ID = "", DemandType = AuxiliaryDemandType.Direct }.ToEnumerable()).ToList(); } - internal DriverData CreateDriverData(IDriverInputData driver) + internal DriverData CreateDriverData(IDriverEngineeringInputData driver) { if (driver.SavedInDeclarationMode) { WarnEngineeringMode("DriverData"); diff --git a/VectoCoreTest/FileIO/JsonTest.cs b/VectoCoreTest/FileIO/JsonTest.cs index da9fe1977e..9599df293f 100644 --- a/VectoCoreTest/FileIO/JsonTest.cs +++ b/VectoCoreTest/FileIO/JsonTest.cs @@ -77,9 +77,8 @@ namespace TUGraz.VectoCore.Tests.FileIO var json = (JObject)JToken.ReadFrom(new JsonTextReader(File.OpenText(TestJobFile))); ((JObject)json["Body"]).Property("Cycles").Remove(); - AssertHelper.Exception<InvalidFileFormatException>(() => { - var tmp = new JSONInputDataV2(json, TestJobFile).Cycles; - }, "Key Cycles not found"); + AssertHelper.Exception<InvalidFileFormatException>( + () => { var tmp = new JSONInputDataV2(json, TestJobFile).Cycles; }, "Key Cycles not found"); } [TestMethod] @@ -100,7 +99,8 @@ namespace TUGraz.VectoCore.Tests.FileIO ((JObject)json["Body"]).Property("VACC").Remove(); AssertHelper.Exception<VectoException>(() => { - var tmp = new JSONInputDataV2(json, TestJobFile).DriverInputData.AccelerationCurve; + IEngineeringInputDataProvider input = new JSONInputDataV2(json, TestJobFile); + var tmp = input.DriverInputData.AccelerationCurve; }, "AccelerationCurve (VACC) required"); } @@ -111,7 +111,8 @@ namespace TUGraz.VectoCore.Tests.FileIO var json = (JObject)JToken.ReadFrom(new JsonTextReader(File.OpenText(TestJobFile))); json["Body"]["VACC"] = "Truck"; - var tmp = new JSONInputDataV2(json, TestJobFile).DriverInputData.AccelerationCurve; + IEngineeringInputDataProvider input = new JSONInputDataV2(json, TestJobFile); + var tmp = input.DriverInputData.AccelerationCurve; Assert.IsNotNull(tmp); } @@ -121,9 +122,11 @@ namespace TUGraz.VectoCore.Tests.FileIO var json = (JObject)JToken.ReadFrom(new JsonTextReader(File.OpenText(TestJobFile))); ((JObject)json["Body"]).Property("LAC").Remove(); - AssertHelper.Exception<VectoException>(() => { - var tmp = new JSONInputDataV2(json, TestJobFile).DriverInputData.Lookahead; - }, "Key LAC not found"); + AssertHelper.Exception<VectoException>( + () => { + IEngineeringInputDataProvider input = new JSONInputDataV2(json, TestJobFile); + var tmp = input.DriverInputData.Lookahead; + }, "Key LAC not found"); } [TestMethod] @@ -132,9 +135,9 @@ namespace TUGraz.VectoCore.Tests.FileIO var json = (JObject)JToken.ReadFrom(new JsonTextReader(File.OpenText(TestJobFile))); ((JObject)json["Body"]).Property("OverSpeedEcoRoll").Remove(); - AssertHelper.Exception<VectoException>(() => { - var tmp = new JSONInputDataV2(json, TestJobFile).DriverInputData.OverSpeedEcoRoll; - }, "Key OverSpeedEcoRoll not found"); + AssertHelper.Exception<VectoException>( + () => { var tmp = new JSONInputDataV2(json, TestJobFile).DriverInputData.OverSpeedEcoRoll; }, + "Key OverSpeedEcoRoll not found"); } } diff --git a/VectoCoreTest/FileIO/SimulationDataReaderTest.cs b/VectoCoreTest/FileIO/SimulationDataReaderTest.cs index cc666e65bf..db0bf41398 100644 --- a/VectoCoreTest/FileIO/SimulationDataReaderTest.cs +++ b/VectoCoreTest/FileIO/SimulationDataReaderTest.cs @@ -19,6 +19,8 @@ using System.IO; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; +using TUGraz.VectoCore.Exceptions; +using TUGraz.VectoCore.InputData; using TUGraz.VectoCore.InputData.FileIO.JSON; using TUGraz.VectoCore.InputData.Reader.Impl; using TUGraz.VectoCore.Models.Declaration; @@ -37,7 +39,11 @@ namespace TUGraz.VectoCore.Tests.FileIO public void ReadDeclarationJobFile() { var dataProvider = JSONInputDataFactory.ReadJsonJob(DeclarationJob); - var reader = new DeclarationModeVectoRunDataFactory(dataProvider, null); + var declarationProvider = dataProvider as IDeclarationInputDataProvider; + if (declarationProvider == null) { + throw new VectoException("Failed to cas to Engineering InputDataProvider"); + } + var reader = new DeclarationModeVectoRunDataFactory(declarationProvider, null); //reader.SetJobFile(DeclarationJob); var runData = reader.NextRun().First(); diff --git a/VectoCoreTest/Models/Simulation/PowerTrainBuilderTest.cs b/VectoCoreTest/Models/Simulation/PowerTrainBuilderTest.cs index 426cf4eb88..b2f7c59b5b 100644 --- a/VectoCoreTest/Models/Simulation/PowerTrainBuilderTest.cs +++ b/VectoCoreTest/Models/Simulation/PowerTrainBuilderTest.cs @@ -18,6 +18,8 @@ using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; +using TUGraz.VectoCore.Exceptions; +using TUGraz.VectoCore.InputData; using TUGraz.VectoCore.InputData.FileIO.JSON; using TUGraz.VectoCore.InputData.Reader.Impl; using TUGraz.VectoCore.Models.Connector.Ports; @@ -37,7 +39,11 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation public void BuildFullPowerTrainTest() { var dataProvider = JSONInputDataFactory.ReadJsonJob(JobFile); - var reader = new EngineeringModeVectoRunDataFactory(dataProvider); + var engineeringProvider = dataProvider as IEngineeringInputDataProvider; + if (engineeringProvider == null) { + throw new VectoException("Failed to cas to Engineering InputDataProvider"); + } + var reader = new EngineeringModeVectoRunDataFactory(engineeringProvider); var runData = reader.NextRun().First(); var writer = new MockModalDataContainer(); diff --git a/VectoCoreTest/Utils/MockSimulationDataFactory.cs b/VectoCoreTest/Utils/MockSimulationDataFactory.cs index 9210f39639..e258cc2c5f 100644 --- a/VectoCoreTest/Utils/MockSimulationDataFactory.cs +++ b/VectoCoreTest/Utils/MockSimulationDataFactory.cs @@ -16,6 +16,7 @@ * limitations under the Licence. */ +using TUGraz.VectoCore.Exceptions; using TUGraz.VectoCore.InputData; using TUGraz.VectoCore.InputData.FileIO.JSON; using TUGraz.VectoCore.InputData.Reader.DataObjectAdaper; @@ -71,8 +72,12 @@ namespace TUGraz.VectoCore.Tests.Utils public static DriverData CreateDriverDataFromFile(string driverDataFile) { var jobInput = JSONInputDataFactory.ReadJsonJob(driverDataFile); + var engineeringJob = jobInput as IEngineeringInputDataProvider; + if (engineeringJob == null) { + throw new VectoException("Failed to cas to Engineering InputDataProvider"); + } var dao = new EngineeringDataAdapter(); - return dao.CreateDriverData(jobInput.DriverInputData); + return dao.CreateDriverData(engineeringJob.DriverInputData); } } } \ No newline at end of file -- GitLab