From ef48ec4061c5505062e674cf03c62d41e6bafccb Mon Sep 17 00:00:00 2001
From: Michael Krisper <michael.krisper@tugraz.at>
Date: Mon, 4 Jul 2016 14:26:37 +0200
Subject: [PATCH] added payloads

---
 .../VectoCore/Models/Declaration/Payloads.cs  | 63 +++++++++++++++++++
 .../Resources/Declaration/Payloads.csv        |  3 +
 2 files changed, 66 insertions(+)
 create mode 100644 VectoCore/VectoCore/Models/Declaration/Payloads.cs
 create mode 100644 VectoCore/VectoCore/Resources/Declaration/Payloads.csv

diff --git a/VectoCore/VectoCore/Models/Declaration/Payloads.cs b/VectoCore/VectoCore/Models/Declaration/Payloads.cs
new file mode 100644
index 0000000000..e78819a712
--- /dev/null
+++ b/VectoCore/VectoCore/Models/Declaration/Payloads.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Data;
+using System.Linq;
+using TUGraz.VectoCommon.Utils;
+using TUGraz.VectoCore.Utils;
+
+namespace TUGraz.VectoCore.Models.Declaration
+{
+	internal sealed class Payloads : LookupData<Kilogram, Payloads.PayloadEntry>
+	{
+		internal sealed class PayloadEntry
+		{
+			public Kilogram Payload50Percent;
+			public Kilogram Payload75Percent;
+		}
+
+		private const string ResourceId = "TUGraz.VectoCore.Resources.Declaration.Payloads.csv";
+
+		public Payloads()
+		{
+			ParseData(ReadCsvResource(ResourceId));
+		}
+
+		[Obsolete("Call Lookup50Percent, Lookup75Percent or LookupTrailer!", true)]
+		private new PayloadEntry Lookup(Kilogram grossVehicleWeight)
+		{
+			throw new NotImplementedException("Call Lookup50Percent, Lookup75Percent or LookupTrailer!");
+		}
+
+		public Kilogram Lookup50Percent(Kilogram grossVehicleWeight)
+		{
+			var section = Data.GetSection(d => d.Key > grossVehicleWeight);
+			return VectoMath.Interpolate(section.Item1.Key, section.Item2.Key,
+				section.Item1.Value.Payload50Percent, section.Item2.Value.Payload50Percent,
+				grossVehicleWeight);
+		}
+
+		public Kilogram Lookup75Percent(Kilogram grossVehicleWeight)
+		{
+			var section = Data.GetSection(d => d.Key > grossVehicleWeight);
+			return VectoMath.Interpolate(section.Item1.Key, section.Item2.Key,
+				section.Item1.Value.Payload75Percent, section.Item2.Value.Payload75Percent,
+				grossVehicleWeight);
+		}
+
+		public Kilogram LookupTrailer(Kilogram grossVehicleWeight, Kilogram curbWeight)
+		{
+			return 0.75 * (grossVehicleWeight - curbWeight);
+		}
+
+		protected override void ParseData(DataTable table)
+		{
+			NormalizeTable(table);
+			Data = table.Rows.Cast<DataRow>()
+				.ToDictionary(
+					kv => kv.ParseDouble("grossvehicleweight").SI<Kilogram>(),
+					kv => new PayloadEntry {
+						Payload50Percent = kv.ParseDouble("payload50%").SI<Kilogram>(),
+						Payload75Percent = kv.ParseDouble("payload75%").SI<Kilogram>()
+					});
+		}
+	}
+}
\ No newline at end of file
diff --git a/VectoCore/VectoCore/Resources/Declaration/Payloads.csv b/VectoCore/VectoCore/Resources/Declaration/Payloads.csv
new file mode 100644
index 0000000000..fe7c5c6c52
--- /dev/null
+++ b/VectoCore/VectoCore/Resources/Declaration/Payloads.csv
@@ -0,0 +1,3 @@
+Gross Vehicle Weight,Payload 50%,Payload 75%
+7500,1250,1900
+16000,4600,6900
-- 
GitLab