diff --git a/VectoCore/VectoCore/Models/Declaration/DeclarationData.cs b/VectoCore/VectoCore/Models/Declaration/DeclarationData.cs index 62da44429eec6deaa2194f2d09b06823e9b4460f..61ce2871c161fe1a2a783fc2519bfb2a09e8143a 100644 --- a/VectoCore/VectoCore/Models/Declaration/DeclarationData.cs +++ b/VectoCore/VectoCore/Models/Declaration/DeclarationData.cs @@ -80,6 +80,8 @@ namespace TUGraz.VectoCore.Models.Declaration public static readonly ADASCombinations ADASCombinations = new ADASCombinations(); public static readonly ADASBenefits ADASBenefits = new ADASBenefits(); + public static readonly WeightingGroups WeightingGroup = new WeightingGroups(); + public static readonly WeightingFactors WeightingFactors = new WeightingFactors(); /// <summary> /// Formula for calculating the payload for a given gross vehicle weight. diff --git a/VectoCore/VectoCore/Models/Declaration/WeightingFactors.cs b/VectoCore/VectoCore/Models/Declaration/WeightingFactors.cs new file mode 100644 index 0000000000000000000000000000000000000000..3856a7eda5f0740eafeda7c0a766bc59bad73f81 --- /dev/null +++ b/VectoCore/VectoCore/Models/Declaration/WeightingFactors.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Data; +using System.Linq; +using TUGraz.VectoCommon.Exceptions; +using TUGraz.VectoCommon.Utils; + +namespace TUGraz.VectoCore.Models.Declaration +{ + public sealed class WeightingFactors : LookupData + { + private readonly Dictionary<WeightingGroup, Dictionary<Tuple<MissionType, LoadingType>, double>> Data = new Dictionary<WeightingGroup, Dictionary<Tuple<MissionType, LoadingType>, double>>(); + + public IDictionary<Tuple<MissionType, LoadingType>, double> Lookup(WeightingGroup group) + { + return new ReadOnlyDictionary<Tuple<MissionType, LoadingType>, double>(Data[group]); + } + + #region Overrides of LookupData + + protected override string ResourceId { get { return DeclarationData.DeclarationDataResourcePrefix + ".CO2Standards.MissionProfileWeights.csv"; } } + protected override string ErrorMessage { get { return "No Weighting Factors found for Weighting Group {0}"; } } + protected override void ParseData(DataTable table) + { + var loadingTypes = new[] { LoadingType.LowLoading, LoadingType.ReferenceLoad }; + var missions = new[] { + MissionType.LongHaul, MissionType.LongHaulEMS, MissionType.RegionalDelivery, MissionType.RegionalDeliveryEMS, + MissionType.UrbanDelivery, MissionType.MunicipalUtility, MissionType.Construction + }; + foreach (DataRow row in table.Rows) { + var weightingGroup = WeightingGroupHelper.Parse(row.Field<string>("weightinggroup")); + if (!Data.ContainsKey(weightingGroup)) { + Data[weightingGroup] = new Dictionary<Tuple<MissionType, LoadingType>, double>(); + } + foreach (var missionType in missions) { + var factors = row.Field<string>(missionType.GetName()); + if (string.IsNullOrWhiteSpace(factors)) { + continue; + } + + var factorsPerLoading = factors.Split('/'); + if (factorsPerLoading.Length != loadingTypes.Length) { + throw new VectoException("Number of entries in MissionProfileWeights does not match expected payloads"); + } + for (var i = 0; i < loadingTypes.Length; i++) { + var cycleAndPayload = Tuple.Create(missionType, loadingTypes[i]); + Data[weightingGroup][cycleAndPayload] = factorsPerLoading[i].ToDouble(0); + } + } + } + + foreach (var entry in Data) { + var sum = entry.Value.Sum(item => item.Value); + if (!sum.IsEqual(1.0, 1e-12)) { + throw new VectoException("Weighting Factors for {0} do not sum up to 1.0! sum: {1}", entry.Key, sum); + } + } + } + + #endregion + } +} diff --git a/VectoCore/VectoCore/Models/Declaration/WeightingGroups.cs b/VectoCore/VectoCore/Models/Declaration/WeightingGroups.cs new file mode 100644 index 0000000000000000000000000000000000000000..be71310a1134783df05f3dbf8392b6e29f366d27 --- /dev/null +++ b/VectoCore/VectoCore/Models/Declaration/WeightingGroups.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Net.NetworkInformation; +using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Utils; + +namespace TUGraz.VectoCore.Models.Declaration +{ + public enum WeightingGroup + { + Group4UD = 1, + Group4RD, + Group4LH, + Group5RD, + Group5LH, + Group9RD, + Group9LH, + Group10RD, + Group10LH, + Unknonw + } + + public class WeightingGroupHelper + { + public const string Prefix = "Group"; + public static WeightingGroup Parse(string groupStr) + { + return (Prefix + groupStr.Replace("-", "")).ParseEnum<WeightingGroup>(); + } + } + + public class WeightingGroups : LookupData<VehicleClass, bool, Watt, WeightingGroup> + { + protected readonly List<Entry> Entries = new List<Entry>(); + + #region Overrides of LookupData + + protected override string ResourceId { get { return DeclarationData.DeclarationDataResourcePrefix + ".CO2Standards.WeightingGroups.csv"; } } + protected override string ErrorMessage { get { + return "WeightingGroup Lookup Error: no entry found for group {0}, sleeper cab: {1}, engine rated power {2}"; + } } + protected override void ParseData(DataTable table) + { + foreach (DataRow row in table.Rows) { + Entries.Add(new Entry() { + VehicleGroup = VehicleClassHelper.Parse(row.Field<string>("vehiclegroup")), + SleeperCab = "SleeperCab".Equals(row.Field<string>("cabintype"), StringComparison.InvariantCultureIgnoreCase), + RatedPowerMin = row.ParseDouble("engineratedpowermin").SI(Unit.SI.Kilo.Watt).Cast<Watt>(), + RatedPowerMax = row.ParseDouble("engineratedpowermax").SI(Unit.SI.Kilo.Watt).Cast<Watt>(), + WeightingGroup = WeightingGroupHelper.Parse(row.Field<string>("weightinggroup")) + }); + } + } + + + public override WeightingGroup Lookup(VehicleClass group, bool sleeperCab, Watt engineRatedPower) + { + var rows = Entries.FindAll( + x => x.VehicleGroup == group && x.SleeperCab == sleeperCab && engineRatedPower >= x.RatedPowerMin && + engineRatedPower < x.RatedPowerMax); + return rows.Count == 0 ? WeightingGroup.Unknonw : rows.First().WeightingGroup; + } + #endregion + + protected class Entry + { + public VehicleClass VehicleGroup; + public bool SleeperCab; + public Watt RatedPowerMin; + public Watt RatedPowerMax; + public WeightingGroup WeightingGroup; + } + } +} diff --git a/VectoCore/VectoCore/Resources/Declaration/CO2Standards/MissionProfileWeights.csv b/VectoCore/VectoCore/Resources/Declaration/CO2Standards/MissionProfileWeights.csv new file mode 100644 index 0000000000000000000000000000000000000000..bf79586e496ff429f2346c7a85ec1a409a0804fc --- /dev/null +++ b/VectoCore/VectoCore/Resources/Declaration/CO2Standards/MissionProfileWeights.csv @@ -0,0 +1,10 @@ +Weighting Group , LongHaul , LongHaul EMS , Regional Delivery , Regional Delivery EMS , Urban Delivery , Municipal Utility , Construction +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 , 0.03/0.07 , 0/0 , 0/0 , 0/0 , 0/0 +10-RD , 0.03/0.07 , 0/0 , 0.27/0.63 , 0/0 , 0/0 , 0/0 , 0/0 +10-LH , 0.27/0.63 , 0/0 , 0.03/0.07 , 0/0 , 0/0 , 0/0 , 0/0 \ No newline at end of file diff --git a/VectoCore/VectoCore/Resources/Declaration/CO2Standards/WeightingGroups.csv b/VectoCore/VectoCore/Resources/Declaration/CO2Standards/WeightingGroups.csv new file mode 100644 index 0000000000000000000000000000000000000000..475eba6838738aa6715340789122bc540cc4dce9 --- /dev/null +++ b/VectoCore/VectoCore/Resources/Declaration/CO2Standards/WeightingGroups.csv @@ -0,0 +1,13 @@ +Vehicle Group , Cabin Type , Engine Rated Power Min [kw] , Engine Rated Power Max [kW] , Weighting Group +4 , DayCab , 0 , 170 , 4-UD +4 , SleeperCab , 0 , 170 , 4-UD +4 , DayCab , 170 , 999999 , 4-RD +4 , SleeperCab , 170 , 265 , 4-RD +4 , SleeperCab , 265 , 999999 , 4-LH +5 , DayCab , 0 , 999999 , 5-RD +5 , SleeperCab , 0 , 265 , 5-RD +5 , SleeperCab , 265 , 999999 , 5-LH +9 , DayCab , 0 , 999999 , 9-RD +9 , SleeperCab , 0 , 999999 , 9-LH +10 , DayCab , 0 , 999999 , 10-RD +10 , SleeperCab , 0 , 999999 , 10-LH \ No newline at end of file diff --git a/VectoCore/VectoCore/VectoCore.csproj b/VectoCore/VectoCore/VectoCore.csproj index 4006e371f4dd16bd7c4305c1b42c5097b22d4d92..58cdf56ebef3601556537b97b85ed3eba76dae69 100644 --- a/VectoCore/VectoCore/VectoCore.csproj +++ b/VectoCore/VectoCore/VectoCore.csproj @@ -175,6 +175,8 @@ <Compile Include="Models\Declaration\FuelData.cs" /> <Compile Include="Models\Declaration\PTOTransmission.cs" /> <Compile Include="Models\Declaration\IDeclarationAuxiliaryTable.cs" /> + <Compile Include="Models\Declaration\WeightingFactors.cs" /> + <Compile Include="Models\Declaration\WeightingGroups.cs" /> <Compile Include="Models\SimulationComponent\Data\AngledriveData.cs" /> <Compile Include="Models\SimulationComponent\Data\Engine\FuelConsumptionMapReader.cs" /> <Compile Include="Models\SimulationComponent\Data\PTOData.cs" /> @@ -469,6 +471,8 @@ </EmbeddedResource> <EmbeddedResource Include="Resources\Declaration\ADAS\ADAS_Benefits.csv" /> <EmbeddedResource Include="Resources\Declaration\ADAS\ADAS_Combinations.csv" /> + <EmbeddedResource Include="Resources\Declaration\CO2Standards\MissionProfileWeights.csv" /> + <EmbeddedResource Include="Resources\Declaration\CO2Standards\WeightingGroups.csv" /> <None Include="Utils\VectoVersionCore.tt"> <Generator>TextTemplatingFileGenerator</Generator> <LastGenOutput>VectoVersionCore.cs</LastGenOutput>