From 0b9bae1a309db317a391f46d2dbe885dda63518e Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <quaritsch@ivt.tugraz.at>
Date: Wed, 7 Dec 2022 17:43:58 +0100
Subject: [PATCH] introducing architecture type for binding results writer
 (conventional, HEV, PEV) adding empty classes for results writer, adding
 binding, extending testcase to check the correct results writers are created

---
 .../InputData/EngineeringInputData.cs         | 27 +++++++++++
 .../CIFNinjectModule.cs                       | 23 ++++++++-
 .../ResultWriter/IResultsWriter.cs            | 48 +++++++++++++++----
 .../ResultWriter/ResultWriterFactory.cs       |  2 +-
 .../VehicleTypeAndArchitectureStringHelper.cs | 20 ++++----
 .../Reports/TestXMLResultsWriting.cs          | 10 +++-
 6 files changed, 109 insertions(+), 21 deletions(-)

diff --git a/VectoCommon/VectoCommon/InputData/EngineeringInputData.cs b/VectoCommon/VectoCommon/InputData/EngineeringInputData.cs
index 42796d2030..8f05e2e8b1 100644
--- a/VectoCommon/VectoCommon/InputData/EngineeringInputData.cs
+++ b/VectoCommon/VectoCommon/InputData/EngineeringInputData.cs
@@ -29,6 +29,7 @@
 *   Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology
 */
 
+using System;
 using System.Collections.Generic;
 using TUGraz.VectoCommon.Models;
 using TUGraz.VectoCommon.Utils;
@@ -64,6 +65,32 @@ namespace TUGraz.VectoCommon.InputData
 		IHPC
 	}
 
+	public static class VectoSimulationJobTypeHelper
+	{
+		public const string Conventional = "Conventional";
+		public const string Hybrid = "Hybrid";
+		public const string PureElectric = "PureElectric";
+
+		public static string GetPowertrainArchitectureType(this VectoSimulationJobType jobType)
+		{
+			switch (jobType) {
+				case VectoSimulationJobType.EngineOnlySimulation:
+				case VectoSimulationJobType.ConventionalVehicle:
+					return Conventional;
+				case VectoSimulationJobType.ParallelHybridVehicle:
+				case VectoSimulationJobType.SerialHybridVehicle:
+				case VectoSimulationJobType.IHPC:
+				case VectoSimulationJobType.IEPC_S:
+					return Hybrid;
+				case VectoSimulationJobType.BatteryElectricVehicle:
+				case VectoSimulationJobType.IEPC_E:
+					return PureElectric;
+				default:
+					throw new ArgumentOutOfRangeException(nameof(jobType), jobType, null);
+			}
+		}
+	}
+
 	public interface IHybridStrategyParameters
 	{
 		double EquivalenceFactorDischarge { get; }
diff --git a/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/CustomerInformationFile_0_9/CIFNinjectModule.cs b/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/CustomerInformationFile_0_9/CIFNinjectModule.cs
index d23d55c35b..1d07831d85 100644
--- a/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/CustomerInformationFile_0_9/CIFNinjectModule.cs
+++ b/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/CustomerInformationFile_0_9/CIFNinjectModule.cs
@@ -420,8 +420,29 @@ namespace TUGraz.VectoCore.OutputData.XML.DeclarationReports.CustomerInformation
 					}
 				})).InSingletonScope();
 
-			Bind<IResultsWriter>().To<ExemptedResultsWriter>().Named(
+			Bind<IResultsWriter>().To<CIFResultsWriter.ConventionalLorry>().Named(
+				_namingHelper.GetName(VehicleCategoryHelper.Lorry, VectoSimulationJobTypeHelper.Conventional, false));
+			Bind<IResultsWriter>().To<CIFResultsWriter.HEVNonOVCLorry>().Named(
+				_namingHelper.GetName(VehicleCategoryHelper.Lorry, VectoSimulationJobTypeHelper.Hybrid, false));
+			Bind<IResultsWriter>().To<CIFResultsWriter.HEVOVCLorry>().Named(
+				_namingHelper.GetName(VehicleCategoryHelper.Lorry, VectoSimulationJobTypeHelper.Hybrid, true));
+			Bind<IResultsWriter>().To<CIFResultsWriter.PEVLorry>().Named(
+				_namingHelper.GetName(VehicleCategoryHelper.Lorry, VectoSimulationJobTypeHelper.PureElectric, true));
+			Bind<IResultsWriter>().To<CIFResultsWriter.ExemptedResultsWriter>().Named(
 				_namingHelper.GetName(VehicleCategoryHelper.Lorry, true));
+
+			Bind<IResultsWriter>().To<CIFResultsWriter.ConventionalBus>().Named(
+				_namingHelper.GetName(VehicleCategoryHelper.CompletedBus, VectoSimulationJobTypeHelper.Conventional, false));
+			Bind<IResultsWriter>().To<CIFResultsWriter.HEVNonOVCBus>().Named(
+				_namingHelper.GetName(VehicleCategoryHelper.CompletedBus, VectoSimulationJobTypeHelper.Hybrid, false));
+			Bind<IResultsWriter>().To<CIFResultsWriter.HEVOVCBus>().Named(
+				_namingHelper.GetName(VehicleCategoryHelper.CompletedBus, VectoSimulationJobTypeHelper.Hybrid, true));
+			Bind<IResultsWriter>().To<CIFResultsWriter.PEVBus>().Named(
+				_namingHelper.GetName(VehicleCategoryHelper.CompletedBus, VectoSimulationJobTypeHelper.PureElectric, true));
+			Bind<IResultsWriter>().To<CIFResultsWriter.ExemptedResultsWriter>().Named(
+				_namingHelper.GetName(VehicleCategoryHelper.CompletedBus, true));
+
+
 			
 		}
 	}
diff --git a/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/CustomerInformationFile_0_9/ResultWriter/IResultsWriter.cs b/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/CustomerInformationFile_0_9/ResultWriter/IResultsWriter.cs
index e60af7a75c..bc8cbf3be3 100644
--- a/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/CustomerInformationFile_0_9/ResultWriter/IResultsWriter.cs
+++ b/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/CustomerInformationFile_0_9/ResultWriter/IResultsWriter.cs
@@ -9,20 +9,52 @@ namespace TUGraz.VectoCore.OutputData.XML.DeclarationReports.CustomerInformation
 		XElement GenerateResults(List<IResultEntry> results);
 	}
 
-
-	public class ExemptedResultsWriter : IResultsWriter
+	public abstract class AbstractResultsWriter : IResultsWriter
 	{
-		protected XNamespace XmlNS => XNamespace.Get("urn:tugraz:ivt:VectoAPI:CustomerOutput:v0.9");
-
 		#region Implementation of IResultsWriter
 
-		public XElement GenerateResults(List<IResultEntry> results)
+		//public abstract XElement GenerateResults(List<IResultEntry> results);
+
+		public virtual XElement GenerateResults(List<IResultEntry> results)
 		{
-			return new XElement(XmlNS + "Results",
-				new XElement(XmlNS + "Status", "success"),
-				new XElement(XmlNS + "ExemptedVehicle"));
+			return null;
 		}
 
 		#endregion
 	}
+
+	public class CIFResultsWriter
+	{
+		public class ConventionalLorry : AbstractResultsWriter {}
+
+		public class HEVNonOVCLorry : AbstractResultsWriter {}
+
+		public class HEVOVCLorry : AbstractResultsWriter {}
+
+		public class PEVLorry : AbstractResultsWriter {}
+
+		public class ConventionalBus : AbstractResultsWriter {}
+
+		public class HEVNonOVCBus : AbstractResultsWriter {}
+
+		public class HEVOVCBus : AbstractResultsWriter {}
+
+		public class PEVBus : AbstractResultsWriter {}
+
+		public class ExemptedResultsWriter : IResultsWriter
+		{
+			protected XNamespace XmlNS => XNamespace.Get("urn:tugraz:ivt:VectoAPI:CustomerOutput:v0.9");
+
+			#region Implementation of IResultsWriter
+
+			public XElement GenerateResults(List<IResultEntry> results)
+			{
+				return new XElement(XmlNS + "Results",
+					new XElement(XmlNS + "Status", "success"),
+					new XElement(XmlNS + "ExemptedVehicle"));
+			}
+
+			#endregion
+		}
+	}
 }
\ No newline at end of file
diff --git a/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/CustomerInformationFile_0_9/ResultWriter/ResultWriterFactory.cs b/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/CustomerInformationFile_0_9/ResultWriter/ResultWriterFactory.cs
index c1f05540aa..a4fc4d4b11 100644
--- a/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/CustomerInformationFile_0_9/ResultWriter/ResultWriterFactory.cs
+++ b/VectoCore/VectoCore/OutputData/XML/DeclarationReports/CustomerInformationFile/CustomerInformationFile_0_9/ResultWriter/ResultWriterFactory.cs
@@ -20,7 +20,7 @@ namespace TUGraz.VectoCore.OutputData.XML.DeclarationReports.CustomerInformation
 			try {
 				return _internalFactory.GetCIFResultsWriter(
 					new VehicleTypeAndArchitectureStringHelperResults.ResultsVehicleClassification(vehicleCategory,
-						jobType, ovc, exempted));
+						jobType.GetPowertrainArchitectureType(), ovc, exempted));
 			} catch (Exception e) {
 				throw new Exception($"Could not create ResultsWriter for vehicle category {vehicleCategory}, {jobType}, ovc: {ovc}, exempted: {exempted}", e);
 			}
diff --git a/VectoCore/VectoCore/Utils/Ninject/VehicleTypeAndArchitectureStringHelper.cs b/VectoCore/VectoCore/Utils/Ninject/VehicleTypeAndArchitectureStringHelper.cs
index 916d79e655..8ad5051ad0 100644
--- a/VectoCore/VectoCore/Utils/Ninject/VehicleTypeAndArchitectureStringHelper.cs
+++ b/VectoCore/VectoCore/Utils/Ninject/VehicleTypeAndArchitectureStringHelper.cs
@@ -250,7 +250,7 @@ namespace TUGraz.VectoCore.Utils.Ninject
 			return classification.GetHashCode().ToString();
 		}
 
-		public string GetName(string vehicleCategory, VectoSimulationJobType jobType, bool ovc = false,
+		public string GetName(string vehicleCategory, string jobType, bool ovc,
 			bool exempted = false)
 		{
 			return GetName(new ResultsVehicleClassification(vehicleCategory, jobType, ovc, exempted));
@@ -258,27 +258,27 @@ namespace TUGraz.VectoCore.Utils.Ninject
 
 		public string GetName(string vehicleType, bool exempted)
 		{
-			return GetName(vehicleType, VectoSimulationJobType.ConventionalVehicle, exempted: exempted);
+			return GetName(vehicleType, VectoSimulationJobTypeHelper.Conventional, false, exempted: exempted);
 		}
 
 		public struct ResultsVehicleClassification
 		{
 			private readonly string _vehicleCategory;
-			private readonly VectoSimulationJobType _jobType;
+			private readonly string _powertrainCategory;
 			private readonly bool _ovc;
 			private readonly bool _exempted;
 
-			public ResultsVehicleClassification(string vehicleCategory, VectoSimulationJobType jobType, bool ovc, bool exempted)
+			public ResultsVehicleClassification(string vehicleCategory, string powertrainCategory, bool ovc, bool exempted)
 			{
 				_vehicleCategory = vehicleCategory;
-				_jobType = jobType;
+				_powertrainCategory = powertrainCategory;
 				_ovc = ovc;
 				_exempted = exempted;
 
 			}
 
 			public bool Exempted => _exempted;
-			public VectoSimulationJobType JobType => Exempted ? VectoSimulationJobType.ConventionalVehicle : _jobType;
+			public string JobType => Exempted ? VectoSimulationJobTypeHelper.Conventional : _powertrainCategory;
 
 			public string VehicleCategory => _vehicleCategory;
 			public bool OVC => _ovc;
@@ -301,10 +301,10 @@ namespace TUGraz.VectoCore.Utils.Ninject
 			public override int GetHashCode()
 			{
 				unchecked {
-					var hashCode = VehicleCategory != null ? VehicleCategory.GetHashCode() : 0;
-					hashCode = (hashCode * 397) ^ (int)JobType;
-					hashCode = (hashCode * 397) ^ OVC.GetHashCode();
-					hashCode = (hashCode * 397) ^ Exempted.GetHashCode();
+					var hashCode = (_vehicleCategory != null ? _vehicleCategory.GetHashCode() : 0);
+					hashCode = (hashCode * 397) ^ (_powertrainCategory != null ? _powertrainCategory.GetHashCode() : 0);
+					hashCode = (hashCode * 397) ^ _ovc.GetHashCode();
+					hashCode = (hashCode * 397) ^ _exempted.GetHashCode();
 					return hashCode;
 				}
 			}
diff --git a/VectoCore/VectoCoreTest/Reports/TestXMLResultsWriting.cs b/VectoCore/VectoCoreTest/Reports/TestXMLResultsWriting.cs
index 9ce696c8f3..10850fef5a 100644
--- a/VectoCore/VectoCoreTest/Reports/TestXMLResultsWriting.cs
+++ b/VectoCore/VectoCoreTest/Reports/TestXMLResultsWriting.cs
@@ -24,7 +24,15 @@ public class TestXMLResultsWriting
 		_reportResultsFactory = _kernel.Get<IResultsWriterFactory>();
 	}
 
-	[TestCase(VehicleCategory.RigidTruck, VectoSimulationJobType.ConventionalVehicle, false, true, typeof(ExemptedResultsWriter))]
+	[
+		TestCase(VehicleCategory.RigidTruck, VectoSimulationJobType.ConventionalVehicle, false, true, typeof(CIFResultsWriter.ExemptedResultsWriter)),
+		TestCase(VehicleCategory.RigidTruck, VectoSimulationJobType.ConventionalVehicle, false, false, typeof(CIFResultsWriter.ConventionalLorry)),
+		TestCase(VehicleCategory.Tractor, VectoSimulationJobType.ConventionalVehicle, false, false, typeof(CIFResultsWriter.ConventionalLorry)),
+		TestCase(VehicleCategory.RigidTruck, VectoSimulationJobType.ParallelHybridVehicle, false, false, typeof(CIFResultsWriter.HEVNonOVCLorry)),
+		TestCase(VehicleCategory.RigidTruck, VectoSimulationJobType.SerialHybridVehicle, true, false, typeof(CIFResultsWriter.HEVOVCLorry)),
+		TestCase(VehicleCategory.RigidTruck, VectoSimulationJobType.BatteryElectricVehicle, true, false, typeof(CIFResultsWriter.PEVLorry)),
+		//TestCase(VehicleCategory.RigidTruck, VectoSimulationJobType.BatteryElectricVehicle, false, false, typeof(CIFResultsWriter.PEVLorry)), // for PEV, OVC is always true!
+	]
 	public void TestReportResultInstance(VehicleCategory vehicleCategory, VectoSimulationJobType jobType, bool ovc,
 		bool exempted, Type expectedResultWriterType)
 	{
-- 
GitLab