From d25070e305a59f16c4b4862c38e3d796cf179d26 Mon Sep 17 00:00:00 2001 From: Markus Quaritsch <markus.quaritsch@tugraz.at> Date: Tue, 14 Jan 2020 09:24:13 +0100 Subject: [PATCH] refactor: use vehicle class enum instead of string, formatting csv files --- VECTO/GUI/VectoJobForm.vb | 8 ++-- VECTO/GUI/VectoVTPJobForm.vb | 8 ++-- VECTO/GUI/VehicleForm.vb | 12 ++--- VECTO/MainModule.vb | 30 +++++++++--- .../DeclarationDataAdapter.cs | 4 +- .../Models/Connector/Ports/Impl/Response.cs | 3 -- .../VectoCore/Models/Declaration/Payloads.cs | 1 - .../VectoCore/Models/Declaration/Segments.cs | 27 ++++------- .../Models/Declaration/VehicleClass.cs | 3 +- .../CO2Standards/MissionProfileWeights.csv | 46 +++++++++---------- 10 files changed, 72 insertions(+), 70 deletions(-) diff --git a/VECTO/GUI/VectoJobForm.vb b/VECTO/GUI/VectoJobForm.vb index ca7ec99bc0..e388ca1d2e 100644 --- a/VECTO/GUI/VectoJobForm.vb +++ b/VECTO/GUI/VectoJobForm.vb @@ -1303,7 +1303,7 @@ lbDlog: End Sub Private Sub UpdateVehiclePic() - Dim HDVclass As String + Dim HDVclass As VehicleClass = VehicleClass.Unknown Dim vehicle As IVehicleEngineeringInputData = Nothing @@ -1328,10 +1328,8 @@ lbDlog: False) Catch End Try - If Not s0.Found Then - HDVclass = "-" - Else - HDVclass = s0.VehicleClass.GetClassNumber() + If s0.Found Then + HDVclass = s0.VehicleClass If Cfg.DeclMode Then LvCycles.Items.Clear() diff --git a/VECTO/GUI/VectoVTPJobForm.vb b/VECTO/GUI/VectoVTPJobForm.vb index 2cf8d8b58f..e71e6a328d 100644 --- a/VECTO/GUI/VectoVTPJobForm.vb +++ b/VECTO/GUI/VectoVTPJobForm.vb @@ -650,7 +650,7 @@ Public Class VectoVTPJobForm End Sub Private Sub UpdateVehiclePic() - Dim HDVclass As String + Dim HDVclass As VehicleClass = VehicleClass.Unknown Dim vehicle As IVehicleDeclarationInputData = Nothing @@ -679,10 +679,8 @@ Public Class VectoVTPJobForm False) Catch End Try - If Not s0.Found Then - HDVclass = "-" - Else - HDVclass = s0.VehicleClass.GetClassNumber() + If s0.Found Then + HDVclass = s0.VehicleClass End If PicVehicle.Image = ConvPicPath(HDVclass, False) _ diff --git a/VECTO/GUI/VehicleForm.vb b/VECTO/GUI/VehicleForm.vb index 1e2d2b424a..68c86191b2 100644 --- a/VECTO/GUI/VehicleForm.vb +++ b/VECTO/GUI/VehicleForm.vb @@ -42,7 +42,7 @@ Public Class VehicleForm End Enum Private _axlDlog As VehicleAxleDialog - Private _hdVclass As String + Private _hdVclass As VehicleClass Private _vehFile As String Private _changed As Boolean = False Private _cmFiles As String() @@ -147,7 +147,7 @@ Public Class VehicleForm Dim axlC As AxleConfiguration = CType(CbAxleConfig.SelectedValue, AxleConfiguration) Dim maxMass As Kilogram = (TbMassMass.Text.ToDouble() * 1000).SI(Of Kilogram)() - _hdVclass = "-" + _hdVclass = VehicleClass.Unknown Dim s0 As Segment = Nothing Try s0 = DeclarationData.Segments.Lookup(vehC, axlC, maxMass, 0.SI(Of Kilogram), False) @@ -156,11 +156,11 @@ Public Class VehicleForm ' no segment found - ignore End Try If s0.Found Then - _hdVclass = s0.VehicleClass.GetClassNumber() + _hdVclass = s0.VehicleClass End If - TbHDVclass.Text = _hdVclass + TbHDVclass.Text = _hdVclass.GetClassNumber() PicVehicle.Image = ConvPicPath(_hdVclass, False) End Sub @@ -184,7 +184,7 @@ Public Class VehicleForm ' no segment found - ignore End Try If s0.Found Then - _hdVclass = s0.VehicleClass.GetClassNumber() + _hdVclass = s0.VehicleClass Dim axleCount As Integer = s0.Missions(0).AxleWeightDistribution.Count() Dim i0 As Integer = LvRRC.Items.Count @@ -205,7 +205,7 @@ Public Class VehicleForm Else 'PnAll.Enabled = False - _hdVclass = "-" + _hdVclass = VehicleClass.Unknown End If TbMassExtra.Text = "-" diff --git a/VECTO/MainModule.vb b/VECTO/MainModule.vb index 19992aeb86..fd355a7a26 100644 --- a/VECTO/MainModule.vb +++ b/VECTO/MainModule.vb @@ -17,6 +17,7 @@ Imports TUGraz.VectoCommon.InputData Imports TUGraz.VectoCommon.OutputData Imports TUGraz.VectoCommon.Utils Imports TUGraz.VectoCore.InputData.Reader.DataObjectAdapter +Imports TUGraz.VectoCore.Models.Declaration Imports TUGraz.VectoCore.Models.SimulationComponent.Data Imports TUGraz.VectoCore.Models.SimulationComponent.Data.Engine Imports VectoAuxiliaries @@ -40,23 +41,38 @@ Module MainModule Return retVal End Function - Public Function ConvPicPath(hdVclass As String, isLongHaul As Boolean) As Bitmap + Public Function ConvPicPath(hdVclass As VehicleClass, isLongHaul As Boolean) As Bitmap Select Case hdVclass - Case "ML2r", "ML2van", "ML3r", "ML3van", "ML4r", "ML4van", "ML4van", "1s" + Case VehicleClass.ClassML2r, + VehicleClass.ClassML2van, + VehicleClass.ClassML3r, + VehicleClass.ClassML3van, + VehicleClass.ClassML4r, + VehicleClass.ClassML4van, + VehicleClass.Class1s Return My.Resources.Undef - Case "1", "2", "3", "6", "7" + Case VehicleClass.Class1, + VehicleClass.Class2, + VehicleClass.Class3, + VehicleClass.Class6, + VehicleClass.Class7 Return My.Resources._4x2r - Case "4" + Case VehicleClass.Class4 If isLongHaul Then Return My.Resources._4x2rt Return My.Resources._4x2r - Case "5", "8" + Case VehicleClass.Class5, + VehicleClass.Class8 Return My.Resources._4x2tt - Case "9", "11", "13" + Case VehicleClass.Class9, + VehicleClass.Class11, + VehicleClass.Class13 If isLongHaul Then Return My.Resources._6x2rt Return My.Resources._6x2r - Case "10", "12", "14" + Case VehicleClass.Class10, + VehicleClass.Class12, + VehicleClass.Class14 Return My.Resources._6x2tt Case Else Return My.Resources.Undef diff --git a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/DeclarationDataAdapter.cs b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/DeclarationDataAdapter.cs index 66566b17e5..5f2f5895bd 100644 --- a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/DeclarationDataAdapter.cs +++ b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/DeclarationDataAdapter.cs @@ -233,14 +233,14 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter retVal.FullLoadCurves = fullLoadCurves; - /*var whr = CreateWHRData(mode.WasteHeatRecoveryData); + var whr = CreateWHRData(mode.WasteHeatRecoveryData); if (whr != null) { whr.WHRCorrectionFactor = DeclarationData.WHTCCorrection.Lookup( mission.MissionType.GetNonEMSMissionType(), whr.CFRural, whr.CFUrban, whr.CFMotorway) * whr.CFColdHot * whr.CFRegPer; } retVal.WHRData = whr; - */ + return retVal; } diff --git a/VectoCore/VectoCore/Models/Connector/Ports/Impl/Response.cs b/VectoCore/VectoCore/Models/Connector/Ports/Impl/Response.cs index 8d08ae62e3..dd77e19ef9 100644 --- a/VectoCore/VectoCore/Models/Connector/Ports/Impl/Response.cs +++ b/VectoCore/VectoCore/Models/Connector/Ports/Impl/Response.cs @@ -112,9 +112,6 @@ namespace TUGraz.VectoCore.Models.Connector.Ports.Impl { public Second DeltaT { get; set; } - public ResponseFailTimeInterval() - { - } } public class ResponseDrivingCycleDistanceExceeded : AbstractResponse diff --git a/VectoCore/VectoCore/Models/Declaration/Payloads.cs b/VectoCore/VectoCore/Models/Declaration/Payloads.cs index ba8c408ab8..5c8ee7fa3b 100644 --- a/VectoCore/VectoCore/Models/Declaration/Payloads.cs +++ b/VectoCore/VectoCore/Models/Declaration/Payloads.cs @@ -52,7 +52,6 @@ namespace TUGraz.VectoCore.Models.Declaration public Kilogram Lookup10Percent(Kilogram grossVehicleWeight) { var section = Data.GetSection(d => d.Key < grossVehicleWeight); - //var section = Data.GetSection(grossVehicleWeight); return VectoMath.Interpolate(section.Item1.Key, section.Item2.Key, section.Item1.Value.Payload10Percent, section.Item2.Value.Payload10Percent, grossVehicleWeight); diff --git a/VectoCore/VectoCore/Models/Declaration/Segments.cs b/VectoCore/VectoCore/Models/Declaration/Segments.cs index 60c72e87f8..01acb85b96 100644 --- a/VectoCore/VectoCore/Models/Declaration/Segments.cs +++ b/VectoCore/VectoCore/Models/Declaration/Segments.cs @@ -98,15 +98,10 @@ namespace TUGraz.VectoCore.Models.Declaration VehicleCategory = vehicleCategory, AxleConfiguration = axleConfiguration, VehicleClass = VehicleClassHelper.Parse(row.Field<string>("hdvgroup")), - AccelerationFile = RessourceHelper.ReadStream(DeclarationData.DeclarationDataResourcePrefix + ".VACC." + row.Field<string>(".vaccfile")), Missions = CreateMissions(ref grossVehicleMassRating, curbWeight, row), - - - - VehicleHeight = LookupHeight(vehicleCategory, axleConfiguration, grossVehicleMassRating, vocational), DesignSpeed = row.ParseDouble("designspeed").KMPHtoMeterPerSecond(), GrossVehicleMassRating = grossVehicleMassRating, @@ -123,8 +118,7 @@ namespace TUGraz.VectoCore.Models.Declaration row = _segmentTable.AsEnumerable().First(r => { var isValid = r.Field<string>("valid"); var isVocational = r.Field<string>("vocational").ToBoolean(); - - var category = r.Field<string>("vehiclecategory"); + var category = r.Field<string>("vehiclecategory"); var axleConf = r.Field<string>("axleconf."); var massMin = r.ParseDouble("tpmlm_min").SI(Unit.SI.Ton); var massMax = r.ParseDouble("tpmlm_max").SI(Unit.SI.Ton); @@ -303,17 +297,16 @@ namespace TUGraz.VectoCore.Models.Declaration IEnumerable<MissionTrailer> trailers, bool lowLoading) { var refLoadValue = payloadStr.ToDouble(double.NaN); - if (double.IsNaN(refLoadValue)) { - //var testvehiclePayload = DeclarationData.GetPayloadForGrossVehicleWeight(grossVehicleWeight, payloadStr); - - var vehiclePayload = DeclarationData.GetPayloadForGrossVehicleWeight(grossVehicleWeight, payloadStr) - .LimitTo(0.SI<Kilogram>(), grossVehicleWeight - vehicleWeight); - var trailerPayload = trailers.Sum( - t => DeclarationData.GetPayloadForTrailerWeight(t.TrailerGrossVehicleWeight, t.TrailerCurbWeight, lowLoading)) - .DefaultIfNull(0); - return vehiclePayload + trailerPayload; + if (!double.IsNaN(refLoadValue)) { + return refLoadValue.SI<Kilogram>(); } - return refLoadValue.SI<Kilogram>(); + + var vehiclePayload = DeclarationData.GetPayloadForGrossVehicleWeight(grossVehicleWeight, payloadStr) + .LimitTo(0.SI<Kilogram>(), grossVehicleWeight - vehicleWeight); + var trailerPayload = trailers.Sum( + t => DeclarationData.GetPayloadForTrailerWeight(t.TrailerGrossVehicleWeight, t.TrailerCurbWeight, lowLoading)) + .DefaultIfNull(0); + return vehiclePayload + trailerPayload; } /// <summary> diff --git a/VectoCore/VectoCore/Models/Declaration/VehicleClass.cs b/VectoCore/VectoCore/Models/Declaration/VehicleClass.cs index 027e70f6f7..6b60458438 100644 --- a/VectoCore/VectoCore/Models/Declaration/VehicleClass.cs +++ b/VectoCore/VectoCore/Models/Declaration/VehicleClass.cs @@ -35,6 +35,7 @@ namespace TUGraz.VectoCore.Models.Declaration { public enum VehicleClass { + Unknown, ClassML2r, ClassML2van, ClassML3r, @@ -79,7 +80,7 @@ namespace TUGraz.VectoCore.Models.Declaration public static string GetClassNumber(this VehicleClass hdvClass) { - return hdvClass.ToString().Substring(Prefix.Length); + return hdvClass == VehicleClass.Unknown ? "-" : hdvClass.ToString().Substring(Prefix.Length); } public static bool IsMediumLorry(VehicleClass vehicleClass) diff --git a/VectoCore/VectoCore/Resources/Declaration/CO2Standards/MissionProfileWeights.csv b/VectoCore/VectoCore/Resources/Declaration/CO2Standards/MissionProfileWeights.csv index 018c9fed94..52a498d162 100644 --- a/VectoCore/VectoCore/Resources/Declaration/CO2Standards/MissionProfileWeights.csv +++ b/VectoCore/VectoCore/Resources/Declaration/CO2Standards/MissionProfileWeights.csv @@ -1,23 +1,23 @@ -Weighting Group , LongHaul , LongHaul EMS , Regional Delivery , Regional Delivery EMS , Urban Delivery , Municipal Utility , Construction -ML2r , 0/0 , 0/0 , 0.25/0.25 , 0/0 , 0.25/0.25 , 0/0 , 0/0 -ML2van , 0/0 , 0/0 , 0.25/0.25 , 0/0 , 0.25/0.25 , 0/0 , 0/0 -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/0 , 0/0 , 0.11/0.27 -16 , 0/0 , 0/0 , 0/0 , 0/0 , 0/0 , 0/0 , 0.30/0.70 +Weighting Group , LongHaul , LongHaul EMS , Regional Delivery , Regional Delivery EMS , Urban Delivery , Municipal Utility , Construction +ML2r , 0/0 , 0/0 , 0.25/0.25 , 0/0 , 0.25/0.25 , 0/0 , 0/0 +ML2van , 0/0 , 0/0 , 0.25/0.25 , 0/0 , 0.25/0.25 , 0/0 , 0/0 +ML3r , 0/0 , 0/0 , 0.25/0.25 , 0/0 , 0.25/0.25 , 0/0 , 0/0 +ML3van , 0/0 , 0/0 , 0.25/0.25 , 0/0 , 0.25/0.25 , 0/0 , 0/0 +ML4r , 0/0 , 0/0 , 0.25/0.25 , 0/0 , 0.25/0.25 , 0/0 , 0/0 +ML4van , 0/0 , 0/0 , 0.25/0.25 , 0/0 , 0.25/0.25 , 0/0 , 0/0 +1s , 0/0 , 0/0 , 0.1/0.4 , 0/0 , 0.15/0.35 , 0/0 , 0/0 +1 , 0/0 , 0/0 , 0.1/0.4 , 0/0 , 0.15/0.35 , 0/0 , 0/0 +2 , 0.06/0.14 , 0/0 , 0.06/0.24 , 0/0 , 0.15/0.35 , 0/0 , 0/0 +3 , 0/0 , 0/0 , 0.1/0.4 , 0/0 , 0.15/0.35 , 0/0 , 0/0 +4-UD , 0/0 , 0/0 , 0/0 , 0/0 , 0.5/0.5 , 0/0 , 0/0 +4-RD , 0.05/0.05 , 0/0 , 0.45/0.45 , 0/0 , 0/0 , 0/0 , 0/0 +4-LH , 0.45/0.45 , 0/0 , 0.05/0.05 , 0/0 , 0/0 , 0/0 , 0/0 +5-RD , 0.03/0.07 , 0/0 , 0.27/0.63 , 0/0 , 0/0 , 0/0 , 0/0 +5-LH , 0.27/0.63 , 0/0 , 0.03/0.07 , 0/0 , 0/0 , 0/0 , 0/0 +9-RD , 0.03/0.07 , 0/0 , 0.27/0.63 , 0/0 , 0/0 , 0/0 , 0/0 +9-LH , 0.27/0.63 , 0/0 , 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