From 8a51c928315535e5e15bd8e0788eccd5daa14b9a Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Tue, 27 Nov 2018 15:14:25 +0100
Subject: [PATCH] adding lookup table for tyre efficiency labels

---
 .../VectoCore/Models/Declaration/TyreClass.cs | 44 +++++++++++++++++++
 .../VectoCore/Models/Declaration/Wheels.cs    |  1 +
 .../Resources/Declaration/TyreLabeling.csv    |  7 +++
 VectoCore/VectoCore/VectoCore.csproj          |  2 +
 4 files changed, 54 insertions(+)
 create mode 100644 VectoCore/VectoCore/Models/Declaration/TyreClass.cs
 create mode 100644 VectoCore/VectoCore/Resources/Declaration/TyreLabeling.csv

diff --git a/VectoCore/VectoCore/Models/Declaration/TyreClass.cs b/VectoCore/VectoCore/Models/Declaration/TyreClass.cs
new file mode 100644
index 0000000000..35b92f1568
--- /dev/null
+++ b/VectoCore/VectoCore/Models/Declaration/TyreClass.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using TUGraz.VectoCore.Utils;
+
+namespace TUGraz.VectoCore.Models.Declaration
+{
+	public sealed class TyreClass : LookupData
+	{
+		private readonly List<Entry> _data = new List<Entry>();
+
+		public string Lookup(double rrc)
+		{
+			var rrcRounded = Math.Round(rrc * 1000, 1, MidpointRounding.AwayFromZero);
+			var entries = _data.FindAll(x => x.RRCMin <= rrcRounded && x.RRCMax >= rrcRounded);
+			return entries.Count == 0 ? "G" : entries.First().Label;
+		}
+
+		#region Overrides of LookupData
+
+		protected override string ResourceId { get { return DeclarationData.DeclarationDataResourcePrefix + ".TyreLabeling.csv"; } }
+		protected override string ErrorMessage { get { return "No Tyre class found for RRC {0}"; } }
+		protected override void ParseData(DataTable table)
+		{
+			foreach (DataRow row in table.Rows) {
+				_data.Add(new Entry {
+					RRCMin = row.ParseDouble("rrc_min"),
+					RRCMax = row.ParseDouble("rrc_max"),
+					Label = row.Field<string>("energyefficiencyclass")
+				});
+			}
+		}
+
+		#endregion
+
+		private class Entry
+		{
+			public double RRCMin;
+			public double RRCMax;
+			public string Label;
+		}
+	}
+}
diff --git a/VectoCore/VectoCore/Models/Declaration/Wheels.cs b/VectoCore/VectoCore/Models/Declaration/Wheels.cs
index eccd87c995..9edbf0ff5b 100644
--- a/VectoCore/VectoCore/Models/Declaration/Wheels.cs
+++ b/VectoCore/VectoCore/Models/Declaration/Wheels.cs
@@ -40,6 +40,7 @@ namespace TUGraz.VectoCore.Models.Declaration
 	public sealed class Wheels : LookupData<string, Wheels.Entry>
 	{
 		private string[] _dimensions;
+		public TyreClass TyreClass = new TyreClass();
 
 		protected override string ResourceId
 		{
diff --git a/VectoCore/VectoCore/Resources/Declaration/TyreLabeling.csv b/VectoCore/VectoCore/Resources/Declaration/TyreLabeling.csv
new file mode 100644
index 0000000000..3828150f9b
--- /dev/null
+++ b/VectoCore/VectoCore/Resources/Declaration/TyreLabeling.csv
@@ -0,0 +1,7 @@
+RRC_min [kg/t] , RRC_max [kg/t] , Energy Efficiency Class
+0              , 4.0            , A
+4.1            , 5.0            , B
+5.1            , 6.0            , C
+6.1            , 7.0            , D
+7.1            , 8.0            , E
+8.1            , 999            , F
\ No newline at end of file
diff --git a/VectoCore/VectoCore/VectoCore.csproj b/VectoCore/VectoCore/VectoCore.csproj
index 58cdf56ebe..ffa6ab0bd9 100644
--- a/VectoCore/VectoCore/VectoCore.csproj
+++ b/VectoCore/VectoCore/VectoCore.csproj
@@ -175,6 +175,7 @@
     <Compile Include="Models\Declaration\FuelData.cs" />
     <Compile Include="Models\Declaration\PTOTransmission.cs" />
     <Compile Include="Models\Declaration\IDeclarationAuxiliaryTable.cs" />
+    <Compile Include="Models\Declaration\TyreClass.cs" />
     <Compile Include="Models\Declaration\WeightingFactors.cs" />
     <Compile Include="Models\Declaration\WeightingGroups.cs" />
     <Compile Include="Models\SimulationComponent\Data\AngledriveData.cs" />
@@ -473,6 +474,7 @@
     <EmbeddedResource Include="Resources\Declaration\ADAS\ADAS_Combinations.csv" />
     <EmbeddedResource Include="Resources\Declaration\CO2Standards\MissionProfileWeights.csv" />
     <EmbeddedResource Include="Resources\Declaration\CO2Standards\WeightingGroups.csv" />
+    <EmbeddedResource Include="Resources\Declaration\TyreLabeling.csv" />
     <None Include="Utils\VectoVersionCore.tt">
       <Generator>TextTemplatingFileGenerator</Generator>
       <LastGenOutput>VectoVersionCore.cs</LastGenOutput>
-- 
GitLab