diff --git a/VectoCore/VectoCore/Models/Declaration/HEVStrategyParameters.cs b/VectoCore/VectoCore/Models/Declaration/HEVStrategyParameters.cs index 9648a734046f6758b2dd20ebe140a8911d71941b..438a5b586176a754fa8d82e2a805897f2fc72aa3 100644 --- a/VectoCore/VectoCore/Models/Declaration/HEVStrategyParameters.cs +++ b/VectoCore/VectoCore/Models/Declaration/HEVStrategyParameters.cs @@ -13,68 +13,85 @@ namespace TUGraz.VectoCore.Models.Declaration { protected override string ResourceId => DeclarationData.DeclarationDataResourcePrefix + ".HEV_Strategy_Parameters_fequiv_40soc_Lorries.csv"; // todo rename csv file... - public override Entry Lookup(string key) - { - return base.Lookup(key.RemoveWhitespace()); - } - protected override void ParseData(DataTable table) + public double LookupEquivalenceFactor(MissionType mission, VehicleClass hdvClass, LoadingType loading) { - var vehicleClasses = table.Rows.Cast<DataRow>().Select(row => row.Field<string>("vehiclegroup")); - - - var cycleEntries = table.Rows.Cast<DataRow>().Select(row => new CycleEntry - { - VehicleGroup = row.Field<string>("vehiclegroup").RemoveWhitespace(), - LongHaul = SplitStringToDoubleTuple(row.Field<string>("longhaul")), - RegionalDelivery = SplitStringToDoubleTuple(row.Field<string>("regionaldelivery")), - UrbanDelivery = SplitStringToDoubleTuple(row.Field<string>("urbandelivery")), - MunicipalUtility = SplitStringToDoubleTuple(row.Field<string>("municipalutility")), - Construction = SplitStringToDoubleTuple(row.Field<string>("construction")) - }); - - - foreach (var cycleEntry in cycleEntries) - { - foreach (string vehClass in cycleEntry.VehicleGroup.Split('/')) { - var newEntry = new Entry { - VehicleGroup = vehClass, - cycleDict = new Dictionary<MissionType, Tuple<double, double>>() - }; - - newEntry.cycleDict.Add(MissionType.LongHaul, cycleEntry.LongHaul); - newEntry.cycleDict.Add(MissionType.RegionalDelivery, cycleEntry.RegionalDelivery); - newEntry.cycleDict.Add(MissionType.UrbanDelivery, cycleEntry.UrbanDelivery); - newEntry.cycleDict.Add(MissionType.MunicipalUtility, cycleEntry.MunicipalUtility); - newEntry.cycleDict.Add(MissionType.Construction, cycleEntry.Construction); - - Data.Add(newEntry.VehicleGroup, newEntry); - } + var entry = Lookup(hdvClass.GetClassNumber()).cycleDict[mission]; + + switch (loading) { + case LoadingType.LowLoading: + return entry.Item1; + case LoadingType.ReferenceLoad: + return entry.Item2; + default: + throw new ArgumentOutOfRangeException(nameof(loading), loading, null); } } - - public struct CycleEntry - { - public string VehicleGroup; - public Tuple<double, double> LongHaul; - public Tuple<double, double> RegionalDelivery; - public Tuple<double, double> UrbanDelivery; - public Tuple<double, double> MunicipalUtility; - public Tuple<double, double> Construction; - } + public override Entry Lookup(string key) + { + return base.Lookup(key.RemoveWhitespace()); + } - public struct Entry - { - public string VehicleGroup; - public Dictionary<MissionType, Tuple<double, double>> cycleDict; - } - + protected override void ParseData(DataTable table) + { + var vehicleClasses = table.Rows.Cast<DataRow>().Select(row => row.Field<string>("vehiclegroup")); - private Tuple<double, double> SplitStringToDoubleTuple(string input) - { - var arr = input.Split('/'); - return input.IsNullOrEmpty() ? Tuple.Create(0.0,0.0) : Tuple.Create(Convert.ToDouble(arr[0]), Convert.ToDouble(arr[1])); - } - } + + var cycleEntries = table.Rows.Cast<DataRow>().Select(row => new CycleEntry + { + VehicleGroup = row.Field<string>("vehiclegroup").RemoveWhitespace(), + LongHaul = SplitStringToDoubleTuple(row.Field<string>("longhaul")), + RegionalDelivery = SplitStringToDoubleTuple(row.Field<string>("regionaldelivery")), + UrbanDelivery = SplitStringToDoubleTuple(row.Field<string>("urbandelivery")), + MunicipalUtility = SplitStringToDoubleTuple(row.Field<string>("municipalutility")), + Construction = SplitStringToDoubleTuple(row.Field<string>("construction")) + }); + + + foreach (var cycleEntry in cycleEntries) + { + foreach (string vehClass in cycleEntry.VehicleGroup.Split('/')) + { + var newEntry = new Entry + { + VehicleGroup = vehClass, + cycleDict = new Dictionary<MissionType, Tuple<double, double>>() + }; + + newEntry.cycleDict.Add(MissionType.LongHaul, cycleEntry.LongHaul); + newEntry.cycleDict.Add(MissionType.RegionalDelivery, cycleEntry.RegionalDelivery); + newEntry.cycleDict.Add(MissionType.UrbanDelivery, cycleEntry.UrbanDelivery); + newEntry.cycleDict.Add(MissionType.MunicipalUtility, cycleEntry.MunicipalUtility); + newEntry.cycleDict.Add(MissionType.Construction, cycleEntry.Construction); + + Data.Add(newEntry.VehicleGroup, newEntry); + } + } + } + + public struct CycleEntry + { + public string VehicleGroup; + public Tuple<double, double> LongHaul; + public Tuple<double, double> RegionalDelivery; + public Tuple<double, double> UrbanDelivery; + public Tuple<double, double> MunicipalUtility; + public Tuple<double, double> Construction; + + } + + public struct Entry + { + public string VehicleGroup; + public Dictionary<MissionType, Tuple<double, double>> cycleDict; + } + + + private Tuple<double, double> SplitStringToDoubleTuple(string input) + { + var arr = input.Split('/'); + return input.IsNullOrEmpty() ? Tuple.Create(0.0, 0.0) : Tuple.Create(Convert.ToDouble(arr[0]), Convert.ToDouble(arr[1])); + } + } } diff --git a/VectoCore/VectoCoreTest/Models/Declaration/HevStrategyParametersTest.cs b/VectoCore/VectoCoreTest/Models/Declaration/HevStrategyParametersTest.cs index 9e7d1c5a296a568a95fe94d1b36f84cab645150f..8120573d5992ec1c70a343a82d15338e4e5eca54 100644 --- a/VectoCore/VectoCoreTest/Models/Declaration/HevStrategyParametersTest.cs +++ b/VectoCore/VectoCoreTest/Models/Declaration/HevStrategyParametersTest.cs @@ -5,6 +5,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using NUnit.Framework; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.InputData.FileIO.JSON; using TUGraz.VectoCore.Models.Declaration; @@ -26,5 +28,26 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration var lookup = new HEVStrategyParameters(); Assert.IsTrue(lookup.Entries.Count > 0); } + + [TestCase] + public void TestHevStrategyLookup() + { + LookupAndAssert(MissionType.LongHaul, VehicleClass.Class2, LoadingType.LowLoading, 2.0); + + LookupAndAssert(MissionType.UrbanDelivery, VehicleClass.Class4, LoadingType.ReferenceLoad, 2.50); + LookupAndAssert(MissionType.UrbanDelivery, VehicleClass.Class4, LoadingType.LowLoading, 2.10); + + LookupAndAssert(MissionType.LongHaul, VehicleClass.Class3, LoadingType.LowLoading, 0); + + + } + + private void LookupAndAssert(MissionType mission, VehicleClass hdvClass, LoadingType loading, double expected) + { + var feq = DeclarationData.HevStrategyParameters.LookupEquivalenceFactor(mission, hdvClass, + loading); + + Assert.IsTrue(feq.IsEqual(expected)); + } } }