From 4ce7271e9e1f15c1bcd1ae92b327ca69d9941b84 Mon Sep 17 00:00:00 2001 From: Markus Quaritsch <markus.quaritsch@tugraz.at> Date: Wed, 5 Oct 2016 09:04:18 +0200 Subject: [PATCH] separate writing json files --- VECTO/GUI/EngineForm.vb | 5 +- VECTO/GUI/GearboxForm.vb | 14 ++-- VECTO/Input Files/Gearbox.vb | 2 +- VECTO/Input Files/VectoJob.vb | 2 +- .../{JSONWriter.vb => JSONFileWriter.vb} | 71 +++++++++++-------- VECTO/VECTO.vbproj | 1 + 6 files changed, 55 insertions(+), 40 deletions(-) rename VECTO/OutputData/{JSONWriter.vb => JSONFileWriter.vb} (83%) diff --git a/VECTO/GUI/EngineForm.vb b/VECTO/GUI/EngineForm.vb index 9c4e3c590f..489b2c8100 100644 --- a/VECTO/GUI/EngineForm.vb +++ b/VECTO/GUI/EngineForm.vb @@ -78,7 +78,6 @@ Public Class EngineForm Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error loading Engine File") End Try - End If End Sub @@ -376,14 +375,14 @@ Public Class EngineForm Try Dim fldFile As String = If(Not String.IsNullOrWhiteSpace(_engFile), Path.Combine(Path.GetDirectoryName(_engFile), TbFLD.Text), TbFLD.Text) - fullLoadCurve = FullLoadCurveReader.Create(VectoCSVFile.Read(fldFile), engineFld:=True) + If File.Exists(fldFile) Then fullLoadCurve = FullLoadCurveReader.Create(VectoCSVFile.Read(fldFile), engineFld:=True) Catch ex As Exception End Try Try Dim fcFile As String = If(Not String.IsNullOrWhiteSpace(_engFile), Path.Combine(Path.GetDirectoryName(_engFile), TbMAP.Text), TbMAP.Text) - fcMap = FuelConsumptionMapReader.Create(VectoCSVFile.Read(fcFile)) + if File.Exists(fcfile) then fcMap = FuelConsumptionMapReader.Create(VectoCSVFile.Read(fcFile)) Catch ex As Exception End Try diff --git a/VECTO/GUI/GearboxForm.vb b/VECTO/GUI/GearboxForm.vb index e9b6148383..2db8c6c5a6 100644 --- a/VECTO/GUI/GearboxForm.vb +++ b/VECTO/GUI/GearboxForm.vb @@ -100,8 +100,8 @@ Public Class GearboxForm TbTracInt.Text = gbxType.TractionInterruption().ToGUIFormat() TbShiftTime.Text = DeclarationData.Gearbox.MinTimeBetweenGearshifts.ToGUIFormat() 'cDeclaration.ShiftTime(GStype) - TbTqResv.Text = DeclarationData.Gearbox.TorqueReserve.ToGUIFormat() ' cDeclaration.TqResv - TbTqResvStart.Text = DeclarationData.Gearbox.TorqueReserveStart.ToGUIFormat() 'cDeclaration.TqResvStart + TbTqResv.Text = (DeclarationData.Gearbox.TorqueReserve * 100).ToGUIFormat() ' cDeclaration.TqResv + TbTqResvStart.Text = (DeclarationData.Gearbox.TorqueReserveStart * 100).ToGUIFormat() 'cDeclaration.TqResvStart TbStartSpeed.Text = DeclarationData.Gearbox.StartSpeed.ToGUIFormat() 'cDeclaration.StartSpeed TbStartAcc.Text = DeclarationData.Gearbox.StartAcceleration.ToGUIFormat() ' cDeclaration.StartAcc @@ -196,9 +196,9 @@ Public Class GearboxForm 'Me.ChSkipGears.Checked = False 'set by CbGStype.SelectedIndexChanged 'Me.ChShiftInside.Checked = False 'set by CbGStype.SelectedIndexChanged - TbTqResv.Text = DeclarationData.Gearbox.TorqueReserve.ToGUIFormat() + TbTqResv.Text = (DeclarationData.Gearbox.TorqueReserve * 100).ToGUIFormat() TbShiftTime.Text = DeclarationData.Gearbox.MinTimeBetweenGearshifts.ToGUIFormat() - TbTqResvStart.Text = DeclarationData.Gearbox.TorqueReserveStart.ToGUIFormat() + TbTqResvStart.Text = (DeclarationData.Gearbox.TorqueReserveStart * 100).ToGUIFormat() TbStartSpeed.Text = DeclarationData.Gearbox.StartSpeed.ToGUIFormat() ' in m/s! TbStartAcc.Text = DeclarationData.Gearbox.StartAcceleration.ToGUIFormat() @@ -272,9 +272,9 @@ Public Class GearboxForm If(gear.MaxTorque Is Nothing, "", gear.MaxTorque.ToGUIFormat()))) Next - TbTqResv.Text = gearbox.TorqueReserve.ToGUIFormat() + TbTqResv.Text = (gearbox.TorqueReserve * 100).ToGUIFormat() TbShiftTime.Text = gearbox.ShiftTime.ToGUIFormat() - TbTqResvStart.Text = gearbox.StartTorqueReserve.ToGUIFormat() + TbTqResvStart.Text = (gearbox.StartTorqueReserve * 100).ToGUIFormat() TbStartSpeed.Text = gearbox.StartSpeed.ToGUIFormat() TbStartAcc.Text = gearbox.StartAcceleration.ToGUIFormat() @@ -712,7 +712,7 @@ Public Class GearboxForm gear = 1 End If - shiftPolygon = ShiftPolygonReader.ReadFromFile(path) + If File.Exists(path) Then shiftPolygon = ShiftPolygonReader.ReadFromFile(path) Catch ex As Exception diff --git a/VECTO/Input Files/Gearbox.vb b/VECTO/Input Files/Gearbox.vb index 55c1eabc19..f9aaf778a1 100644 --- a/VECTO/Input Files/Gearbox.vb +++ b/VECTO/Input Files/Gearbox.vb @@ -377,7 +377,7 @@ Public Class Gearbox Public ReadOnly Property TorqueReserve As Double Implements IGearboxEngineeringInputData.TorqueReserve Get - Return TorqueResv + Return TorqueResv / 100 End Get End Property diff --git a/VECTO/Input Files/VectoJob.vb b/VECTO/Input Files/VectoJob.vb index 38931b6bb0..e2f4d82bc1 100644 --- a/VECTO/Input Files/VectoJob.vb +++ b/VECTO/Input Files/VectoJob.vb @@ -597,7 +597,7 @@ Public Class VectoJob Public ReadOnly Property Cycles As IList(Of ICycleData) Implements IEngineeringJobInputData.Cycles Get - Dim retVal As ICycleData() = New ICycleData(CycleFiles.Count) {} + Dim retVal As ICycleData() = New ICycleData(CycleFiles.Count - 1) {} Dim i As Integer = 0 For Each cycleFile As SubPath In CycleFiles Dim cycleData As TableData diff --git a/VECTO/OutputData/JSONWriter.vb b/VECTO/OutputData/JSONFileWriter.vb similarity index 83% rename from VECTO/OutputData/JSONWriter.vb rename to VECTO/OutputData/JSONFileWriter.vb index de47c9e94e..e39037ace9 100644 --- a/VECTO/OutputData/JSONWriter.vb +++ b/VECTO/OutputData/JSONFileWriter.vb @@ -4,9 +4,7 @@ Imports System.Linq Imports Newtonsoft.Json.Linq Imports TUGraz.VectoCommon.InputData Imports TUGraz.VectoCommon.Models -Imports TUGraz.VectoCore.InputData.Impl Imports TUGraz.VectoCore.Models.Declaration -Imports TUGraz.VectoCore.Models.SimulationComponent.Data Public Class JSONFileWriter Public Const EngineFormatVersion As Short = 3 @@ -111,16 +109,16 @@ Public Class JSONFileWriter Next body.Add("Gears", ls) - body.Add("TqReserve", gbx.TorqueReserve) + body.Add("TqReserve", gbx.TorqueReserve * 100) 'body.Add("SkipGears", gbx.sk) body.Add("ShiftTime", gbx.ShiftTime.Value()) 'body.Add("EaryShiftUp", gbx.ShiftInside) - body.Add("StartTqReserve", gbx.StartTorqueReserve) + body.Add("StartTqReserve", gbx.StartTorqueReserve * 100) body.Add("StartSpeed", gbx.StartSpeed.Value()) body.Add("StartAcc", gbx.StartAcceleration.Value()) - body.Add("GearboxType", gbx.Type) + body.Add("GearboxType", gbx.Type.ToString()) Dim torqueConverter As ITorqueConverterEngineeringInputData = gbx.TorqueConverter Dim torqueConverterDict As New Dictionary(Of String, Object) @@ -148,6 +146,7 @@ Public Class JSONFileWriter Public Function SaveVehicle(vehicle As IVehicleEngineeringInputData, retarder As IRetarderInputData, pto As IPTOTransmissionInputData, angledrive As IAngledriveInputData, filename As String) As Boolean + Dim basePath As String = Path.GetDirectoryName(filename) Dim json As New JSONWriter 'Header Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From { @@ -166,7 +165,9 @@ Public Class JSONFileWriter retarderOut.Add("Type", retarder.Type.GetName()) retarderOut.Add("Ratio", retarder.Ratio) retarderOut.Add("File", - If(retarder.Type.IsDedicatedComponent AndAlso Not retarder.LossMap Is Nothing, retarder.LossMap.Source, "")) + If _ + (retarder.Type.IsDedicatedComponent AndAlso Not retarder.LossMap Is Nothing, + GetRelativePath(retarder.LossMap.Source, basePath), "")) End If Dim ptoOut As Dictionary(Of String, Object) = New Dictionary(Of String, Object) @@ -175,9 +176,13 @@ Public Class JSONFileWriter Else ptoOut.Add("Type", pto.PTOTransmissionType) ptoOut.Add("LossMap", - If(pto.PTOTransmissionType <> "None" AndAlso Not pto.PTOLossMap Is Nothing, pto.PTOLossMap.Source, "")) + If _ + (pto.PTOTransmissionType <> "None" AndAlso Not pto.PTOLossMap Is Nothing, + GetRelativePath(pto.PTOLossMap.Source, basePath), "")) ptoOut.Add("Cycle", - If(pto.PTOTransmissionType <> "None" AndAlso Not pto.PTOCycle Is Nothing, pto.PTOCycle.Source, "")) + If _ + (pto.PTOTransmissionType <> "None" AndAlso Not pto.PTOCycle Is Nothing, + GetRelativePath(pto.PTOCycle.Source, basePath), "")) End If Dim angledriveOut As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From { @@ -186,7 +191,7 @@ Public Class JSONFileWriter {"LossMap", If _ (angledrive.Type = AngledriveType.SeparateAngledrive AndAlso Not angledrive.LossMap Is Nothing, - angledrive.LossMap.Source, "")}} + GetRelativePath(angledrive.LossMap.Source, basePath), "")}} Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From { {"SavedInDeclMode", Cfg.DeclMode}, @@ -203,7 +208,8 @@ Public Class JSONFileWriter ( (vehicle.CrossWindCorrectionMode = CrossWindCorrectionMode.SpeedDependentCorrectionFactor OrElse vehicle.CrossWindCorrectionMode = CrossWindCorrectionMode.VAirBetaLookupTable) AndAlso - Not vehicle.CrosswindCorrectionMap Is Nothing, vehicle.CrosswindCorrectionMap.Source, "")}, + Not vehicle.CrosswindCorrectionMap Is Nothing, GetRelativePath(vehicle.CrosswindCorrectionMap.Source, basePath), "") + }, {"Retarder", retarderOut}, {"Angledrive", angledriveOut}, {"PTO", ptoOut}, @@ -228,7 +234,7 @@ Public Class JSONFileWriter Public Function SaveJob(input As IEngineeringInputDataProvider, filename As String) As Boolean Dim json As New JSONWriter - + Dim basePath As String = Path.GetDirectoryName(filename) 'Header Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From { {"CreatedBy", Lic.LicString & " (" & Lic.GUID & ")"}, @@ -250,21 +256,20 @@ Public Class JSONFileWriter body.Add("EngineOnlyMode", job.EngineOnlyMode) If job.EngineOnlyMode Then - body.Add("EngineFile", input.EngineInputData.Source) - For Each cycle As ICycleData In job.Cycles - body.Add("Cycles", cycle.CycleData.Source) - Next + body.Add("EngineFile", GetRelativePath(input.EngineInputData.Source, basePath)) + body.Add("Cycles", + job.Cycles.Select(Function(x) GetRelativePath(x.CycleData.Source, Path.GetDirectoryName(filename))).ToArray()) Return True End If 'Main Files - body.Add("VehicleFile", GetRelativePath(job.Vehicle.Source, Path.GetDirectoryName(filename))) - body.Add("EngineFile", GetRelativePath(input.EngineInputData.Source, Path.GetDirectoryName(filename))) - body.Add("GearboxFile", GetRelativePath(input.GearboxInputData.Source, Path.GetDirectoryName(filename))) + body.Add("VehicleFile", GetRelativePath(job.Vehicle.Source, basePath)) + body.Add("EngineFile", GetRelativePath(input.EngineInputData.Source, basePath)) + body.Add("GearboxFile", GetRelativePath(input.GearboxInputData.Source, basePath)) 'AA-TB 'ADVANCED AUXILIARIES - body.Add("AuxiliaryAssembly", aux.AuxiliaryAssembly) + body.Add("AuxiliaryAssembly", aux.AuxiliaryAssembly.ToString()) body.Add("AuxiliaryVersion", aux.AuxiliaryVersion) body.Add("AdvancedAuxiliaryFilePath", aux.AdvancedAuxiliaryFilePath) @@ -279,12 +284,12 @@ Public Class JSONFileWriter Dim engineeringAuxEntry As IAuxiliaryDeclarationInputData = TryCast(auxEntry, IAuxiliaryDeclarationInputData) If engineeringAuxEntry Is Nothing Then auxOut.Add("Type", auxEntry.AuxiliaryType.ToString()) - auxOut.Add("Path", auxEntry.DemandMap.Source) + auxOut.Add("Path", GetRelativePath(auxEntry.DemandMap.Source, basePath)) auxOut.Add("Technology", New String() {}) Else auxOut.Add("ID", auxEntry.ID) - auxOut.Add("Technology", engineeringAuxEntry.Technology) auxOut.Add("Type", AuxiliaryTypeHelper.ParseKey(auxEntry.ID).Name()) + auxOut.Add("Technology", engineeringAuxEntry.Technology) End If auxList.Add(auxOut) Next @@ -295,21 +300,31 @@ Public Class JSONFileWriter body.Add("Padd", pAdd) End If If Not job.SavedInDeclarationMode Then - body.Add("VACC", driver.AccelerationCurve.Source) + body.Add("VACC", GetRelativePath(driver.AccelerationCurve.Source, basePath)) End If body.Add("StartStop", New Dictionary(Of String, Object) From { {"Enabled", driver.StartStop.Enabled}, - {"MaxSpeed", driver.StartStop.MaxSpeed.Value()}, + {"MaxSpeed", driver.StartStop.MaxSpeed.AsKmph}, {"MinTime", driver.StartStop.MinTime.Value()}, {"Delay", driver.StartStop.Delay.Value()}}) If Not job.SavedInDeclarationMode Then + Dim dfTargetSpeed As String = If _ + ( + Not driver.Lookahead.CoastingDecisionFactorTargetSpeedLookup Is Nothing AndAlso + File.Exists(driver.Lookahead.CoastingDecisionFactorTargetSpeedLookup.Source), + GetRelativePath(driver.Lookahead.CoastingDecisionFactorTargetSpeedLookup.Source, basePath), "") + Dim dfVelocityDrop As String = If _ + ( + Not driver.Lookahead.CoastingDecisionFactorVelocityDropLookup Is Nothing AndAlso + File.Exists(driver.Lookahead.CoastingDecisionFactorVelocityDropLookup.Source), + GetRelativePath(driver.Lookahead.CoastingDecisionFactorVelocityDropLookup.Source, basePath), "") body.Add("LAC", New Dictionary(Of String, Object) From { {"Enabled", driver.Lookahead.Enabled}, {"PreviewDistanceFactor", driver.Lookahead.LookaheadDistanceFactor}, {"DF_offset", driver.Lookahead.CoastingDecisionFactorOffset}, {"DF_scaling", driver.Lookahead.CoastingDecisionFactorScaling}, - {"DF_targetSpeedLookup", driver.Lookahead.CoastingDecisionFactorTargetSpeedLookup.Source}, - {"Df_velocityDropLookup", driver.Lookahead.CoastingDecisionFactorVelocityDropLookup.Source}}) + {"DF_targetSpeedLookup", dfTargetSpeed}, + {"Df_velocityDropLookup", dfVelocityDrop}}) End If 'Overspeed / EcoRoll @@ -317,9 +332,9 @@ Public Class JSONFileWriter overspeedDic.Add("Mode", driver.OverSpeedEcoRoll.Mode.ToString()) - overspeedDic.Add("MinSpeed", driver.OverSpeedEcoRoll.MinSpeed.Value()) - overspeedDic.Add("OverSpeed", driver.OverSpeedEcoRoll.OverSpeed.Value()) - overspeedDic.Add("UnderSpeed", driver.OverSpeedEcoRoll.UnderSpeed.Value()) + overspeedDic.Add("MinSpeed", driver.OverSpeedEcoRoll.MinSpeed.AsKmph) + overspeedDic.Add("OverSpeed", driver.OverSpeedEcoRoll.OverSpeed.AsKmph) + overspeedDic.Add("UnderSpeed", driver.OverSpeedEcoRoll.UnderSpeed.AsKmph) body.Add("OverSpeedEcoRoll", overspeedDic) 'Cycles diff --git a/VECTO/VECTO.vbproj b/VECTO/VECTO.vbproj index 7343c3210e..04df2b627f 100644 --- a/VECTO/VECTO.vbproj +++ b/VECTO/VECTO.vbproj @@ -256,6 +256,7 @@ <Compile Include="GUI\VectoJobForm.vb"> <SubType>Form</SubType> </Compile> + <Compile Include="OutputData\JSONWriter.vb" /> <Compile Include="VECTO_Global.vb" /> <Compile Include="VECTO_Types.vb" /> <Compile Include="GUI\GUI_Subs.vb" /> -- GitLab