From 4b4ff50b6407c465d1c43738ca9f00d9cdd2841e Mon Sep 17 00:00:00 2001
From: Michael Krisper <michael.krisper@tugraz.at>
Date: Wed, 3 Aug 2016 15:09:50 +0200
Subject: [PATCH] upgrade job file to version 3

---
 .../InputData/FileIO/JSON/JSONInputData.cs    | 98 ++++++++++++++++++-
 .../FileIO/JSON/JSONInputDataFactory.cs       |  2 +
 .../DeclarationDataAdapter.cs                 |  2 +-
 3 files changed, 96 insertions(+), 6 deletions(-)

diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs
index 56584e0c30..8f5072f196 100644
--- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs
+++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs
@@ -462,18 +462,73 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON
 			get { return AuxData().Cast<IAuxiliaryDeclarationInputData>().ToList(); }
 		}
 
-		private IList<AuxiliaryDataInputData> AuxData()
+		protected virtual IList<AuxiliaryDataInputData> AuxData()
 		{
 			var retVal = new List<AuxiliaryDataInputData>();
 			foreach (var aux in Body["Aux"] ?? Enumerable.Empty<JToken>()) {
 				var auxData = new AuxiliaryDataInputData {
 					ID = aux.GetEx<string>("ID"),
 					Type = AuxiliaryTypeHelper.Parse(aux.GetEx<string>("Type")),
-					Technology = new List<string>() { aux.GetEx<string>("Technology") },
+					Technology = new List<string>(),
 				};
-				//if (aux["TechList"] != null) {
-				//	auxData.TechList = aux["TechList"].Select(x => x.ToString()).ToList(); //  .Select(x => x.ToString).ToArray();
-				//}
+				var tech = aux.GetEx<string>("Technology");
+
+				// Convert old Electric System to new format
+				if (auxData.Type == AuxiliaryType.ElectricSystem) {
+					if (aux["TechList"] == null || aux["TechList"].Any()) {
+						auxData.Technology.Add("Standard technology");
+						Log.Warn("Aux: Upgraded Electric System to new format: 'Standard technology'");
+					} else {
+						auxData.Technology.Add("Standard technology - LED headlights, all");
+						Log.Warn("Aux: Upgraded Electric System to new format: 'Standard technology - LED headlights, all'");
+					}
+				}
+
+				// Convert old Steering Pump to new format
+				if (auxData.Type == AuxiliaryType.SteeringPump) {
+					switch (tech) {
+						case "Variable displacement":
+							Log.Warn(
+								"Aux: Upgraded Steering Pump Technology from 'Variable displacement' to 'Variable displacement elec. controlled'");
+							auxData.Technology.Add("Variable displacement elec. controlled");
+							break;
+						case "Hydraulic supported by electric":
+							Log.Warn("Aux: Upgraded Steering Pump Technology from 'Hydraulic supported by electric' to 'Dual displacement'");
+							auxData.Technology.Add("Dual displacement");
+							break;
+						default:
+							auxData.Technology.Add(tech);
+							break;
+					}
+				}
+
+				// Convert old Pneumatic System to new format
+				if (auxData.Type == AuxiliaryType.PneumaticSystem) {
+					Log.Warn("Aux: Upgraded Pneumatic System Technology to 'Medium Supply 1-stage'");
+					auxData.Technology.Add("Medium Supply 1-stage");
+				}
+
+				// Convert old HVAC to new format
+				if (auxData.Type == AuxiliaryType.HVAC) {
+					if (tech == "") {
+						auxData.Technology.Add("");
+					} else if (tech == "") {
+						Log.Warn(
+							"Aux: Upgraded HVAC Technology from '' to ''");
+						auxData.Technology.Add("");
+					}
+				}
+
+				if (auxData.Type == AuxiliaryType.Fan) {
+					if (tech == "") {
+						auxData.Technology.Add("");
+					} else if (tech == "") {
+						Log.Warn(
+							"Aux: Upgraded Fan Technology from '' to ''");
+						auxData.Technology.Add("");
+					}
+				}
+
 				var auxFile = aux["Path"];
 				retVal.Add(auxData);
 
@@ -519,4 +574,37 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON
 
 		#endregion
 	}
+
+	public class JSONInputDataV3 : JSONInputDataV2
+	{
+		public JSONInputDataV3(JObject data, string filename) : base(data, filename) {}
+
+		protected override IList<AuxiliaryDataInputData> AuxData()
+		{
+			var retVal = new List<AuxiliaryDataInputData>();
+			foreach (var aux in Body["Aux"] ?? Enumerable.Empty<JToken>()) {
+				var auxData = new AuxiliaryDataInputData {
+					ID = aux.GetEx<string>("ID"),
+					Type = AuxiliaryTypeHelper.Parse(aux.GetEx<string>("Type")),
+					Technology = aux.GetEx<List<string>>("Technology"),
+				};
+
+				var auxFile = aux["Path"];
+				retVal.Add(auxData);
+
+				if (auxFile == null || EmptyOrInvalidFileName(auxFile.Value<string>())) {
+					continue;
+				}
+				var stream = new StreamReader(Path.Combine(BasePath, auxFile.Value<string>()));
+				stream.ReadLine(); // skip header "Transmission ration to engine rpm [-]"
+				auxData.TransmissionRatio = stream.ReadLine().IndulgentParse();
+				stream.ReadLine(); // skip header "Efficiency to engine [-]"
+				auxData.EfficiencyToEngine = stream.ReadLine().IndulgentParse();
+				stream.ReadLine(); // skip header "Efficiency auxiliary to supply [-]"
+				auxData.EfficiencyToSupply = stream.ReadLine().IndulgentParse();
+				auxData.DemandMap = VectoCSVFile.ReadStream(new MemoryStream(Encoding.UTF8.GetBytes(stream.ReadToEnd())));
+			}
+			return retVal;
+		}
+	}
 }
\ No newline at end of file
diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs
index 13b6c41830..2a344f699a 100644
--- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs
+++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs
@@ -57,6 +57,8 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON
 			switch (version) {
 				case 2:
 					return new JSONInputDataV2(json, filename);
+				case 3:
+					return new JSONInputDataV3(json, filename);
 				default:
 					throw new VectoException("Job-File: Unsupported FileVersion. Got: {0} ", version);
 			}
diff --git a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/DeclarationDataAdapter.cs b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/DeclarationDataAdapter.cs
index 7d39af74e0..c3a91d08f2 100644
--- a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/DeclarationDataAdapter.cs
+++ b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/DeclarationDataAdapter.cs
@@ -254,7 +254,7 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter
 						aux.ID = Constants.Auxiliaries.IDs.Fan;
 						break;
 					case AuxiliaryType.SteeringPump:
-						aux.PowerDemand = DeclarationData.SteeringPump.Lookup(mission, hvdClass, auxData.Technology);
+						aux.PowerDemand = SteeringPump.Lookup(mission, hvdClass, auxData.Technology);
 						aux.ID = Constants.Auxiliaries.IDs.SteeringPump;
 						break;
 					case AuxiliaryType.HVAC:
-- 
GitLab