Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 43dec6f5 authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

adding weighting groups and weighting factors (declaration data and lookup classes)

parent 86093c59
No related branches found
No related tags found
No related merge requests found
......@@ -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.
......
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
}
}
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;
}
}
}
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
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
......@@ -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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment