diff --git a/VectoCommon/VectoCommon/InputData/DeclarationInputData.cs b/VectoCommon/VectoCommon/InputData/DeclarationInputData.cs index 3fd317471c300f7c8c74c859c7ce85262f4f9a2d..292639d551dda097addf4bc13b5868caa58f40ca 100644 --- a/VectoCommon/VectoCommon/InputData/DeclarationInputData.cs +++ b/VectoCommon/VectoCommon/InputData/DeclarationInputData.cs @@ -277,7 +277,7 @@ namespace TUGraz.VectoCommon.InputData public static string ToXMLFormat(this PredictiveCruiseControlType pcc) { - return pcc.ToString().ToLowerInvariant().Replace(Prefix, "").Replace(SeparatorEnum, SeparatorXML); + return pcc.ToString().ToLowerInvariant().Replace(Prefix.ToLowerInvariant(), "").Replace(SeparatorEnum, SeparatorXML); } public static string GetName(this PredictiveCruiseControlType pcc) diff --git a/VectoCommon/VectoCommon/InputData/IInputDataProvider.cs b/VectoCommon/VectoCommon/InputData/IInputDataProvider.cs index e5d0b2d7d46fd023f91a6267bbec2a49dd71d8fd..176ec2e93ba6fba19938ca48a577bc2bf46c9d18 100644 --- a/VectoCommon/VectoCommon/InputData/IInputDataProvider.cs +++ b/VectoCommon/VectoCommon/InputData/IInputDataProvider.cs @@ -115,7 +115,7 @@ namespace TUGraz.VectoCommon.InputData public interface IMultistageVIFInputData : IInputDataProvider { IVehicleDeclarationInputData VehicleInputData { get; } - IMultistageBusInputDataProvider MultistageInputData { get; } + IMultistageBusInputDataProvider MultistageJobInputData { get; } } } diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationAxlesDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationAxlesDataProvider.cs index 8e5d7ef6efa3798d6e34d691642db336387c51c8..33ffb96b7436e7ee84f2386224de3be02a65e9d8 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationAxlesDataProvider.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationAxlesDataProvider.cs @@ -107,4 +107,26 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider get { return NAMESPACE_URI; } } } + + + // --------------------------------------------------------------------------------------- + + public class XMLDeclarationAxlesDataProviderV01 : XMLDeclarationAxlesDataProviderV10 + { + public new static XNamespace NAMESPACE_URI = XMLDefinitions.DECLARATION_MULTISTAGE_BUS_VEHICLE_NAMESPACE_VO1; + + public new const string XSD_TYPE = "AxleWheelsDataPIFType"; + + public new static readonly string QUALIFIED_XSD_TYPE = + XMLHelper.CombineNamespace(NAMESPACE_URI.NamespaceName, XSD_TYPE); + + public XMLDeclarationAxlesDataProviderV01( + IXMLDeclarationVehicleData vehicle, XmlNode componentNode, string sourceFile) : base( + vehicle, componentNode, sourceFile) { } + + protected override XNamespace SchemaNamespace + { + get { return NAMESPACE_URI; } + } + } } diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationBusAuxiliariesDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationBusAuxiliariesDataProvider.cs index fdf65e99c486dcc36fc6a3857588c4ae133ea08f..073d3f207bded67aee406c388ab42cbb4c9eafd5 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationBusAuxiliariesDataProvider.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationBusAuxiliariesDataProvider.cs @@ -242,6 +242,24 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider #endregion } + public class XMLDeclarationPrimaryBusAuxiliariesDataProviderV01 : XMLDeclarationPrimaryBusAuxiliariesDataProviderV26 + { + public new static XNamespace NAMESPACE_URI = XMLDefinitions.DECLARATION_MULTISTAGE_BUS_VEHICLE_NAMESPACE_VO1; + + public new const string XSD_TYPE = "AuxiliaryDataPIFType"; + + public new static readonly string QUALIFIED_XSD_TYPE = XMLHelper.CombineNamespace(NAMESPACE_URI.NamespaceName, XSD_TYPE); + + public XMLDeclarationPrimaryBusAuxiliariesDataProviderV01(IXMLDeclarationVehicleData vehicle, XmlNode componentNode, string sourceFile) + : base(vehicle, componentNode, sourceFile) { } + + + public override XmlNode XMLSource + { + get { return BaseNode; } + } + } + public class XMLDeclarationCompleteBusAuxiliariesDataProviderV26 : XMLDeclarationPrimaryBusAuxiliariesDataProviderV26, IElectricConsumersDeclarationData { public new static XNamespace NAMESPACE_URI = XMLDefinitions.DECLARATION_DEFINITIONS_NAMESPACE_URI_V26; diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationMultistageInputData.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationMultistageInputData.cs index ab4f253c758f708a2f434a3567de81fd1dca9d3c..51aecfe1e599f63084a73edfb8fb1d655d74b84a 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationMultistageInputData.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationMultistageInputData.cs @@ -291,33 +291,26 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider public class XMLDeclarationVIFInputData : IMultistageVIFInputData { + private readonly IMultistageBusInputDataProvider _multistageJobInputData; + private readonly IVehicleDeclarationInputData _vehicleInput; - private readonly IXMLInputDataReader _xmlInputReader; - - public XMLDeclarationVIFInputData(string vifFileName, IVehicleDeclarationInputData vehicleInput) + public XMLDeclarationVIFInputData(IMultistageBusInputDataProvider multistageJobInputData, + IVehicleDeclarationInputData vehicleInput) { - - var kernel = new StandardKernel(new VectoNinjectModule()); - _xmlInputReader = kernel.Get<IXMLInputDataReader>(); - - VehicleInputData = vehicleInput; - MultistageInputData = CreateMultistageReader(vifFileName); + _multistageJobInputData = multistageJobInputData; + _vehicleInput = vehicleInput; } - - private IMultistageBusInputDataProvider CreateMultistageReader(string vifFileName) + public IVehicleDeclarationInputData VehicleInputData { - var reader = XmlReader.Create(vifFileName); - return _xmlInputReader.Create(reader) as IMultistageBusInputDataProvider; + get { return _vehicleInput; } } - - - public DataSource DataSource + public IMultistageBusInputDataProvider MultistageJobInputData { - get { return null; } + get { return _multistageJobInputData; } } - public IVehicleDeclarationInputData VehicleInputData { get; } - public IMultistageBusInputDataProvider MultistageInputData { get; } + + public DataSource DataSource { get; } } } \ No newline at end of file diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationPrimaryVehicleBusResultsInputDataProviderV01.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationPrimaryVehicleBusResultsInputDataProviderV01.cs index e2d0b0065b4362cc106bd34ce79a2cdab37090ff..0e03640e378cbb660e2edf463da99ccbce3ea471 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationPrimaryVehicleBusResultsInputDataProviderV01.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationPrimaryVehicleBusResultsInputDataProviderV01.cs @@ -70,6 +70,17 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider string.Format(".//*[local-name()='{0}' and @unit='MJ/km']", XMLNames.Report_Result_EnergyConsumption))?.InnerText .ToDouble().SI(Unit.SI.Mega.Joule.Per.Kilo.Meter).Cast<JoulePerMeter>())).ToDictionary(x => x.Key, x => x.Value); + + var co2Nodes = GetNodes(XMLNames.Report_Results_CO2, xmlNode); + var resultCO2 = new Dictionary<string, double>(); + foreach (XmlNode co2Node in co2Nodes) { + var attribute = GetAttribute(co2Node, XMLNames.Report_Results_Unit_Attr); + var value = co2Node?.InnerText; + if(value != null) + resultCO2.Add(attribute, value.ToDouble()); + } + + return new Result { ResultStatus = resultStatus, @@ -77,7 +88,7 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider VehicleGroup = VehicleClassHelper.Parse(vehicleGroup), SimulationParameter = simulationParams, EnergyConsumption = energyConsumption, - CO2 = new Dictionary<string, double>() + CO2 = resultCO2 }; } diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/NinjectModules/XMLDeclarationInputDataMultistageV01InjectModule.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/NinjectModules/XMLDeclarationInputDataMultistageV01InjectModule.cs index 2f3206e012a8f72464ed95d5f8894d0c2e654c4d..1f50d3e2cf3f36e5ae92825eaa0da7f33a38fcf7 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/NinjectModules/XMLDeclarationInputDataMultistageV01InjectModule.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/NinjectModules/XMLDeclarationInputDataMultistageV01InjectModule.cs @@ -30,10 +30,11 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration.NinjectModules Bind<IXMLPrimaryVehicleBusInputData>().To<XMLDeclarationMultistagePrimaryVehicleInputDataV01>() .Named(XMLDeclarationMultistagePrimaryVehicleInputDataV01.QUALIFIED_XSD_TYPE); + Bind<IXMLBusAuxiliariesDeclarationData>().To<XMLDeclarationPrimaryBusAuxiliariesDataProviderV01>() + .Named(XMLDeclarationPrimaryBusAuxiliariesDataProviderV01.QUALIFIED_XSD_TYPE); Bind<IXMLDeclarationPrimaryVehicleBusInputDataReader>().To<XMLMultistagePrimaryVehicleReaderV01>() .Named(XMLMultistagePrimaryVehicleReaderV01.QUALIFIED_XSD_TYPE); - Bind<IXMLPrimaryVehicleBusJobInputData>().To<XMLDeclarationMultistagePrimaryVehicleBusJobInputDataProviderV01>() .Named(XMLDeclarationMultistagePrimaryVehicleBusJobInputDataProviderV01.QUALIFIED_XSD_TYPE); @@ -54,6 +55,9 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration.NinjectModules Bind<IXMLGearboxReader>().To<XMLMultistagePrimaryVehicleBusComponentReaderV01>() .Named(XMLMultistagePrimaryVehicleBusComponentReaderV01.GEARBOX_READER_QUALIFIED_XSD_TYPE); + Bind<IXMLAxlesReader>().To<XMLMultistagePrimaryVehicleBusComponentReaderV01>() + .Named(XMLMultistagePrimaryVehicleBusComponentReaderV01.AXLES_READER_QUALIFIED_XSD_TYPE); + Bind<IXMLVehicleComponentsDeclaration>() .To<XMLDeclarationComponentsMultistagePrimaryVehicleBusDataProviderV01>() .Named(XMLDeclarationComponentsMultistagePrimaryVehicleBusDataProviderV01.QUALIFIED_XSD_TYPE); @@ -79,6 +83,9 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration.NinjectModules Bind<IXMLAxleGearInputData>().To<XMLDeclarationMultistagePrimaryVehicleBusAxlegearDataProviderV01>().Named( XMLDeclarationMultistagePrimaryVehicleBusAxlegearDataProviderV01.QUALIFIED_XSD_TYPE); + Bind<IXMLAxlesDeclarationInputData>().To<XMLDeclarationAxlesDataProviderV01>().Named( + XMLDeclarationAxlesDataProviderV01.QUALIFIED_XSD_TYPE); + Bind<IXMLApplicationInformationData>().To<XMLDeclarationMultistagePrimaryVehicleBusApplicationInformationDataProviderV01>() .Named(XMLDeclarationMultistagePrimaryVehicleBusApplicationInformationDataProviderV01.QUALIFIED_XSD_TYPE); diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/Reader/Impl/XMLComponentReader.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/Reader/Impl/XMLComponentReader.cs index 04878c76668e60e46a080be0339bfa50f4d714d1..a041ad0ec5eb6c0b5b8c8f937cf55a783a699144 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/Reader/Impl/XMLComponentReader.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/Reader/Impl/XMLComponentReader.cs @@ -369,12 +369,14 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration.Reader.Impl public new const string XSD_TYPE = "VehicleComponentsPIFType"; public new const string GEARBOX_READER_TYPE = "TransmissionDataPIFType"; - + public new const string AXLES_READER_TYPE = "AxleWheelsDataPIFType"; + public new static readonly string QUALIFIED_XSD_TYPE = XMLHelper.CombineNamespace(NAMESPACE_URI.NamespaceName, XSD_TYPE); public new static readonly string GEARBOX_READER_QUALIFIED_XSD_TYPE = XMLHelper.CombineNamespace(NAMESPACE_URI, GEARBOX_READER_TYPE); + public new static readonly string AXLES_READER_QUALIFIED_XSD_TYPE = XMLHelper.CombineNamespace(NAMESPACE_URI, AXLES_READER_TYPE); protected IBusAuxiliariesDeclarationData _busAuxInputData; - + public XMLMultistagePrimaryVehicleBusComponentReaderV01(IXMLDeclarationVehicleData vehicle, XmlNode componentsNode) : base(vehicle, componentsNode) { } diff --git a/VectoCore/VectoCore/InputData/Reader/Impl/AbstractDeclarationMultistageBusVectoRunDataFactory.cs b/VectoCore/VectoCore/InputData/Reader/Impl/AbstractDeclarationMultistageBusVectoRunDataFactory.cs new file mode 100644 index 0000000000000000000000000000000000000000..94a915835788f1149da57c3e58b77f1e470eaacf --- /dev/null +++ b/VectoCore/VectoCore/InputData/Reader/Impl/AbstractDeclarationMultistageBusVectoRunDataFactory.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using TUGraz.VectoCommon.InputData; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Models.Declaration; +using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.OutputData; + +namespace TUGraz.VectoCore.InputData.Reader.Impl +{ + public abstract class AbstractDeclarationMultistageBusVectoRunDataFactory : LoggingObject, IVectoRunDataFactory + { + protected readonly IMultistageVIFInputData InputDataProvider; + + protected IDeclarationReport Report; + + + protected AbstractDeclarationMultistageBusVectoRunDataFactory(IMultistageVIFInputData dataProvider, IDeclarationReport report) + { + InputDataProvider = dataProvider; + Report = report; + } + + public IEnumerable<VectoRunData> NextRun() + { + if(Report != null) + InitializeReport(); + + return GetNextRun(); + } + + protected abstract IEnumerable<VectoRunData> GetNextRun(); + + protected abstract VectoRunData CreateVectoRunData(IVehicleDeclarationInputData vehicle, int modeIdx, Mission mission, KeyValuePair<LoadingType, Tuple<Kilogram, double?>> loading); + + protected virtual void InitializeReport() + { + var vehicle = InputDataProvider.MultistageJobInputData.JobInputData.PrimaryVehicle.Vehicle; + var powertrainConfig = CreateVectoRunData(vehicle, 0, null, new KeyValuePair<LoadingType, Tuple<Kilogram, double?>>()); + var fuels = new List<List<FuelData.Entry>>(); + Report.InitializeReport(powertrainConfig, fuels); + } + } +} diff --git a/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationModeMultistageBusVectoRunDataFactory.cs b/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationModeMultistageBusVectoRunDataFactory.cs new file mode 100644 index 0000000000000000000000000000000000000000..708b3efa8969ae980b3a742b842b5bcba4ee9cea --- /dev/null +++ b/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationModeMultistageBusVectoRunDataFactory.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using TUGraz.VectoCommon.InputData; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Models.Declaration; +using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.Models.SimulationComponent.Data; +using TUGraz.VectoCore.OutputData; +using TUGraz.VectoCore.Utils; + +namespace TUGraz.VectoCore.InputData.Reader.Impl +{ + public class DeclarationModeMultistageBusVectoRunDataFactory : AbstractDeclarationMultistageBusVectoRunDataFactory + { + public DeclarationModeMultistageBusVectoRunDataFactory(IMultistageVIFInputData dataProvider, IDeclarationReport report) + : base(dataProvider, report) { } + + protected override IEnumerable<VectoRunData> GetNextRun() + { + yield return CreateVectoRunData(null, 0, null, new KeyValuePair<LoadingType, Tuple<Kilogram, double?>>()); + } + + protected override VectoRunData CreateVectoRunData(IVehicleDeclarationInputData vehicle, int modeIdx, Mission mission, + KeyValuePair<LoadingType, Tuple<Kilogram, double?>> loading) + { + return new VectoRunData + { + Exempted = true, + Report = Report, + Mission = new Mission { MissionType = MissionType.ExemptedMission }, + VehicleData = CreateExemptedVehicleData(InputDataProvider.MultistageJobInputData.JobInputData.PrimaryVehicle.Vehicle), + MultistageVIFInputData = InputDataProvider + }; + } + + private VehicleData CreateExemptedVehicleData(IVehicleDeclarationInputData data) + { + var exempted = SetCommonVehicleData(data); + exempted.VIN = data.VIN; + exempted.ManufacturerAddress = data.ManufacturerAddress; + exempted.LegislativeClass = data.LegislativeClass; + exempted.ZeroEmissionVehicle = data.ZeroEmissionVehicle; + exempted.HybridElectricHDV = data.HybridElectricHDV; + exempted.DualFuelVehicle = true; + exempted.MaxNetPower1 = data.MaxNetPower1; + exempted.MaxNetPower2 = data.MaxNetPower2; + + return exempted; + } + + private VehicleData SetCommonVehicleData(IVehicleDeclarationInputData data) + { + var retVal = new VehicleData + { + InputData = data, + SavedInDeclarationMode = data.SavedInDeclarationMode, + Manufacturer = data.Manufacturer, + ModelName = data.Model, + Date = data.Date, + //CertificationNumber = data.CertificationNumber, + DigestValueInput = data.DigestValue != null ? data.DigestValue.DigestValue : "", + VehicleCategory = data.VehicleCategory, + CurbMass = data.CurbMassChassis, + GrossVehicleMass = data.GrossVehicleMassRating, + AirDensity = Physics.AirDensity, + }; + + return retVal; + } + } +} diff --git a/VectoCore/VectoCore/Models/Simulation/Data/VectoRunData.cs b/VectoCore/VectoCore/Models/Simulation/Data/VectoRunData.cs index 90f7ae3d019d3189859f4c85f720912690f2538e..0ff7c3c47b4cc5ba75a8c8ca603ccb067589c0eb 100644 --- a/VectoCore/VectoCore/Models/Simulation/Data/VectoRunData.cs +++ b/VectoCore/VectoCore/Models/Simulation/Data/VectoRunData.cs @@ -148,6 +148,9 @@ namespace TUGraz.VectoCore.Models.Simulation.Data public Watt ElectricAuxDemand { get; internal set; } + [JsonIgnore] + public IMultistageVIFInputData MultistageVIFInputData { get; internal set; } + public class AuxData { // ReSharper disable once InconsistentNaming diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs b/VectoCore/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs index fe21d5fc97e99fda657a2d07b571db7081b4566b..ec326745e87d4ff6fd56940d910ab013a3e8d153 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs @@ -134,6 +134,15 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl return; } } + + if (dataProvider is IMultistageVIFInputData) { + var declDataProvider = dataProvider as IMultistageVIFInputData; + var report = declarationReport ?? new XMLDeclarationReportMultistageBusVehicle(ModWriter); + DataReader = new DeclarationModeMultistageBusVectoRunDataFactory(declDataProvider, report); + return; + } + + throw new VectoException("Unknown InputData for Declaration Mode!"); } diff --git a/VectoCore/VectoCore/OutputData/FileIO/FileOutputWriter.cs b/VectoCore/VectoCore/OutputData/FileIO/FileOutputWriter.cs index b9bb4f344c80aa4cd42eb76c3927206c2dbd4f85..7a4fd849c4637db662cea699e79451340ec5bdcb 100644 --- a/VectoCore/VectoCore/OutputData/FileIO/FileOutputWriter.cs +++ b/VectoCore/VectoCore/OutputData/FileIO/FileOutputWriter.cs @@ -85,6 +85,12 @@ namespace TUGraz.VectoCore.OutputData.FileIO get { return Path.ChangeExtension(_jobFile, Constants.FileExtensions.SumFile); } } + public string XMLMultistageReportFileName + { + get { return Path.ChangeExtension(_jobFile, "VIF_Report.xml"); } + } + + /// <summary> /// /// </summary> @@ -135,6 +141,9 @@ namespace TUGraz.VectoCore.OutputData.FileIO case ReportType.DeclarationVTPReportXML: fileName = XMLVTPReportName; break; + case ReportType.DeclarationReportMultistageVehicleXML: + fileName = XMLMultistageReportFileName; + break; default: throw new ArgumentOutOfRangeException("ReportType"); } diff --git a/VectoCore/VectoCore/OutputData/IDataWriter.cs b/VectoCore/VectoCore/OutputData/IDataWriter.cs index 10eb1a634ec450749dfa01452d0c60c0902bbf3b..408e432732b35b07f48b1d481b33ff98e5a3bfa9 100644 --- a/VectoCore/VectoCore/OutputData/IDataWriter.cs +++ b/VectoCore/VectoCore/OutputData/IDataWriter.cs @@ -61,6 +61,7 @@ namespace TUGraz.VectoCore.OutputData DeclarationReportCustomerXML, DeclarationVTPReportXML, DeclarationReportMonitoringXML, - DeclarationReportPrimaryVehicleXML + DeclarationReportPrimaryVehicleXML, + DeclarationReportMultistageVehicleXML } } \ No newline at end of file diff --git a/VectoCore/VectoCore/OutputData/XML/XMLDeclarationReportMultistageBusVehicle.cs b/VectoCore/VectoCore/OutputData/XML/XMLDeclarationReportMultistageBusVehicle.cs new file mode 100644 index 0000000000000000000000000000000000000000..b26cbb222e3baf40aac3ad94d5c32aad7dd04f69 --- /dev/null +++ b/VectoCore/VectoCore/OutputData/XML/XMLDeclarationReportMultistageBusVehicle.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TUGraz.VectoCore.Models.Declaration; +using TUGraz.VectoCore.Models.Simulation.Data; + +namespace TUGraz.VectoCore.OutputData.XML +{ + public class XMLDeclarationReportMultistageBusVehicle : XMLDeclarationReport + { + private readonly XMLMultistageBusReport _multistageBusReport; + + public XMLDeclarationReportMultistageBusVehicle(IReportWriter writer) + : base(writer) + { + _multistageBusReport = new XMLMultistageBusReport(); + } + + public override void InitializeReport(VectoRunData modelData, List<List<FuelData.Entry>> fuelModes) + { + _multistageBusReport.Initialize(modelData); + } + + protected override void GenerateReports() + { + _multistageBusReport.GenerateReport(); + } + + protected override void OutputReports() + { + Writer.WriteReport(ReportType.DeclarationReportMultistageVehicleXML, _multistageBusReport.Report); + } + + protected override void DoStoreResult(XMLDeclarationReport.ResultEntry entry, VectoRunData runData, IModalDataContainer modData) + { + throw new NotSupportedException(); + } + protected override void WriteResult(XMLDeclarationReport.ResultEntry result) + { + throw new NotSupportedException(); + } + } +} diff --git a/VectoCore/VectoCore/OutputData/XML/XMLMultistageBusReport.cs b/VectoCore/VectoCore/OutputData/XML/XMLMultistageBusReport.cs new file mode 100644 index 0000000000000000000000000000000000000000..03cc921bda8cc7fbb47e758a0fb118fa0fab83ec --- /dev/null +++ b/VectoCore/VectoCore/OutputData/XML/XMLMultistageBusReport.cs @@ -0,0 +1,512 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; +using System.Xml; +using System.Xml.Linq; +using TUGraz.VectoCommon.InputData; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Resources; +using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.InputData.Reader.ComponentData; +using TUGraz.VectoCore.Models.Declaration; +using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.Utils; + +namespace TUGraz.VectoCore.OutputData.XML +{ + public interface IXMLMultistageReport + { + void Initialize(VectoRunData modelData); + XDocument Report { get; } + void GenerateReport(); + } + + public class XMLMultistageBusReport: IXMLMultistageReport + { + protected XNamespace tns = "urn:tugraz:ivt:VectoAPI:DeclarationOutput:VehicleInterimFile:v0.1"; + protected XNamespace di = "http://www.w3.org/2000/09/xmldsig#"; + protected XNamespace xsi = XNamespace.Get("http://www.w3.org/2001/XMLSchema-instance"); + + protected XNamespace v20 = "urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v2.0"; + protected XNamespace v21 = "urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v2.1"; + protected XNamespace v23 = "urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:DEV:v2.3"; + protected XNamespace v26 = "urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:DEV:v2.6"; + protected XNamespace v28 = "urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:DEV:v2.8"; + + protected XElement PrimaryVehicle; + protected XElement InputDataSignature; + protected XElement ManufacturerRecordSignature; + protected XElement Results; + protected XElement ApplicationInformation; + protected XElement PrimarySignature; + + + private IPrimaryVehicleInformationInputDataProvider primaryVehicleInputData; + private IList<IManufacturingStageInputData> manufacturingStageInputData; + private IVehicleDeclarationInputData vehicleInputData; + + public XDocument Report { get; protected set; } + + public XMLMultistageBusReport() + { + PrimaryVehicle = new XElement(tns + XMLNames.Component_Vehicle); + InputDataSignature = new XElement(tns + XMLNames.Report_InputDataSignature); + ManufacturerRecordSignature = new XElement(tns + "ManufacturerRecordSignature"); + Results = new XElement(tns + XMLNames.Report_Results); + PrimarySignature = new XElement(tns + XMLNames.DI_Signature); + ApplicationInformation = new XElement(tns + XMLNames.Report_ApplicationInfo_ApplicationInformation); + } + + + + public void Initialize(VectoRunData modelData) + { + primaryVehicleInputData = modelData.MultistageVIFInputData.MultistageJobInputData.JobInputData.PrimaryVehicle; + manufacturingStageInputData = modelData.MultistageVIFInputData.MultistageJobInputData.JobInputData.ManufacturingStages; + vehicleInputData = modelData.MultistageVIFInputData.VehicleInputData; + + SetPrimaryVehicle(primaryVehicleInputData); + SetInputDataSignature(primaryVehicleInputData); + SetManufacturerRecordSignature(primaryVehicleInputData); + SetResults(primaryVehicleInputData); + SetApplicationInformation(primaryVehicleInputData); + SetPrimarySignature(primaryVehicleInputData); + } + + + + public void GenerateReport() + { + var retVal = new XDocument(); + + retVal.Add( + + new XElement(tns + "VectoOutputMultistage", + new XAttribute("xmlns" , tns), + new XAttribute(XNamespace.Xmlns + "xsi", xsi.NamespaceName), + new XAttribute(XNamespace.Xmlns + "di", di), + new XAttribute(XNamespace.Xmlns + "v2.0", v20), + new XAttribute(XNamespace.Xmlns + "v2.1", v21), + new XAttribute(XNamespace.Xmlns + "v2.3", v23), + new XAttribute(XNamespace.Xmlns + "v2.6", v26), + new XAttribute(XNamespace.Xmlns + "v2.8", v28), + new XAttribute( + xsi + "schemaLocation", + string.Format("{0} {1}", tns, @"E:\VECTO_DEV\fk_vecto-dev\VectoCore\VectoCore\Resources\XSD/VectoOutputMultistage.0.1.xsd")), + + new XElement(tns + "PrimaryVehicle", + + new XElement(tns + XMLNames.Report_DataWrap, + new XAttribute("id", "text"), + new XAttribute(xsi + "type", "PrimaryVehicleDataType"), + + PrimaryVehicle, + InputDataSignature, + ManufacturerRecordSignature, + Results, + ApplicationInformation + ), + PrimarySignature + ) + ) + ); + Report = retVal; + + } + + private void SetApplicationInformation(IPrimaryVehicleInformationInputDataProvider primaryData) + { + ApplicationInformation = new XElement( + tns + XMLNames.Report_ApplicationInfo_ApplicationInformation, + new XElement(tns + XMLNames.Report_ApplicationInfo_SimulationToolVersion, primaryData.ApplicationInformation.SimulationToolVersion), + new XElement( + tns + XMLNames.Report_ApplicationInfo_Date, + XmlConvert.ToString(primaryData.ApplicationInformation.Date, XmlDateTimeSerializationMode.Utc))); + } + + private void SetPrimarySignature(IPrimaryVehicleInformationInputDataProvider primaryData) + { + PrimarySignature.Add(primaryData.VehicleSignatureHash.ToXML(di)); + } + + private void SetResults(IPrimaryVehicleInformationInputDataProvider primaryData) + { + Results.Add(new XElement(tns+ XMLNames.Report_Result_Status, primaryData.ResultsInputData.Status)); + + foreach (var resultEntry in primaryData.ResultsInputData.Results) { + SetResult(resultEntry); + } + } + + private void SetResult(IResult result) + { + Results.Add(new XElement( + tns + XMLNames.Report_Result_Result, + new XAttribute(XMLNames.Report_Result_Status_Attr, result.ResultStatus), + new XElement(tns + XMLNames.Report_Vehicle_VehicleGroup, result.VehicleGroup.GetClassNumber()), + new XElement(tns + XMLNames.Report_Result_Mission, result.Mission.ToXMLFormat()), + new XElement(tns + XMLNames.Report_ResultEntry_SimulationParameters, + new XElement( + tns + XMLNames.Report_ResultEntry_TotalVehicleMass, + XMLHelper.ValueAsUnit(result.SimulationParameter.TotalVehicleMass, XMLNames.Unit_kg, 2)), + new XElement( + tns + XMLNames.Report_Result_Payload, + XMLHelper.ValueAsUnit(result.SimulationParameter.Payload, XMLNames.Unit_kg, 2)), + new XElement( + tns + XMLNames.Report_ResultEntry_PassengerCount, + result.SimulationParameter.PassengerCount.ToXMLFormat(2)), + new XElement( + tns + XMLNames.Report_Result_FuelMode, result.SimulationParameter.FuelMode) + ), + GetResultFuel(result.EnergyConsumption), + GetResultCo2(result.CO2) + ) + ); + } + + private List<XElement> GetResultFuel(Dictionary<FuelType, JoulePerMeter> fuels) + { + var resultFuels = new List<XElement>(); + + foreach (var fuel in fuels) { + resultFuels.Add( + new XElement(tns + XMLNames.Report_Results_Fuel, + new XAttribute(XMLNames.Report_Results_Fuel_Type_Attr, fuel.Key.ToXMLFormat()), + new XElement(tns + XMLNames.Report_Result_EnergyConsumption, + XMLHelper.ValueAsUnit(fuel.Value.ConvertToMegaJouleperKilometer(), "MJ/km", 5)) + ) + ); + } + + return resultFuels; + } + + private List<XElement> GetResultCo2(Dictionary<string, double> co2s) + { + var resultCo2 = new List<XElement>(); + + foreach (var co2 in co2s) { + resultCo2.Add( + new XElement(tns + XMLNames.Report_Results_CO2, + XMLHelper.ValueAsUnit(co2.Value, "g/km", 2))); + } + + return resultCo2; + } + + + private void SetManufacturerRecordSignature(IPrimaryVehicleInformationInputDataProvider primaryData) + { + ManufacturerRecordSignature.Add(primaryData.ManufacturerRecordHash.ToXML(di)); + } + + private void SetInputDataSignature(IPrimaryVehicleInformationInputDataProvider primaryData) + { + InputDataSignature.Add(primaryData.PrimaryVehicleInputDataHash.ToXML(di)); + } + + private void SetPrimaryVehicle(IPrimaryVehicleInformationInputDataProvider primaryData) + { + var primaryVehicle = primaryData.Vehicle; + + PrimaryVehicle.Add( + new XAttribute(xsi + "type", "VehiclePIFType"), + new XElement(tns + XMLNames.ManufacturerPrimaryVehicle, primaryVehicle.Manufacturer), + new XElement(tns + XMLNames.ManufacturerAddressPrimaryVehicle, primaryVehicle.ManufacturerAddress), + new XElement(tns + XMLNames.Component_Model, primaryVehicle.Model), + new XElement(tns + XMLNames.Vehicle_VIN, primaryVehicle.VIN), + new XElement(tns + XMLNames.Component_Date, XmlConvert.ToString(primaryVehicle.Date, XmlDateTimeSerializationMode.Utc)), + new XElement(tns + XMLNames.Vehicle_VehicleCategory, primaryVehicle.VehicleCategory.ToXMLFormat()), + new XElement(tns + XMLNames.Vehicle_AxleConfiguration, primaryVehicle.AxleConfiguration.GetName()), + new XElement(tns + XMLNames.Vehicle_Articulated, primaryVehicle.Articulated), + new XElement(tns + XMLNames.TPMLM, primaryVehicle.GrossVehicleMassRating.ToXMLFormat(0)), + new XElement(tns + XMLNames.Vehicle_IdlingSpeed, primaryVehicle.EngineIdleSpeed.AsRPM.ToXMLFormat(0)), + new XElement(tns + XMLNames.Vehicle_RetarderType, primaryVehicle.Components.RetarderInputData.Type.ToXMLFormat()), + primaryVehicle.Components.RetarderInputData.Type.IsDedicatedComponent() + ? new XElement(tns + XMLNames.Vehicle_RetarderRatio, primaryVehicle.Components.RetarderInputData.Ratio.ToXMLFormat(3)) + : null, + new XElement( + tns + XMLNames.Vehicle_AngledriveType, (primaryVehicle.Components?.AngledriveInputData?.Type ?? AngledriveType.None).ToXMLFormat()), + new XElement(tns + XMLNames.Vehicle_ZeroEmissionVehicle, primaryVehicle.ZeroEmissionVehicle), + GetADAS(primaryVehicle.ADAS), + GetTorqueLimits(primaryVehicleInputData), + GetVehicleComponents(primaryVehicle.Components)); + } + + private XElement GetADAS(IAdvancedDriverAssistantSystemDeclarationInputData adasData) + { + var ns = XNamespace.Get(adasData.XMLSource.SchemaInfo.SchemaType.QualifiedName.Namespace); + var versionNumber = GetNamespaceVersionNumber(ns); + return new XElement( + tns + XMLNames.Vehicle_ADAS, + + new XAttribute( + xsi + "type", + $"{versionNumber}:{adasData.XMLSource.SchemaInfo.SchemaType.QualifiedName.Name}"), + new XElement(ns + XMLNames.Vehicle_ADAS_EngineStopStart, adasData.EngineStopStart), + new XElement(ns + XMLNames.Vehicle_ADAS_EcoRollWithoutEngineStop, adasData.EcoRoll.WithoutEngineStop()), + new XElement(ns + XMLNames.Vehicle_ADAS_EcoRollWithEngineStopStart, adasData.EcoRoll.WithEngineStop()), + new XElement(ns + XMLNames.Vehicle_ADAS_PCC, adasData.PredictiveCruiseControl.ToXMLFormat()), + adasData.ATEcoRollReleaseLockupClutch != null + ? new XElement(ns + XMLNames.Bus_ADAS_APTEcoRollReleaseLockupClutch, adasData.ATEcoRollReleaseLockupClutch) + : null + ); + } + + private XElement GetTorqueLimits(IPrimaryVehicleInformationInputDataProvider vehicleInputData) + { + var inputData = vehicleInputData.Vehicle.XMLSource; + var tcLimits = inputData.SelectSingleNode(XMLHelper.QueryLocalName(XMLNames.Vehicle_TorqueLimits)); + if (tcLimits == null) + { + return null; + } + + var ns = XNamespace.Get(tcLimits.SchemaInfo.SchemaType.QualifiedName.Namespace); + const string tclPrefix = "tcl"; + return new XElement( + tns + XMLNames.Vehicle_TorqueLimits, + new XAttribute(XNamespace.Xmlns + tclPrefix, ns.NamespaceName), + new XAttribute(xsi + "type", string.Format("{0}:{1}", tclPrefix, tcLimits.SchemaInfo.SchemaType.QualifiedName.Name)), + XElement.Parse(tcLimits.OuterXml).Elements() + ); + } + + + protected XElement GetVehicleComponents(IVehicleComponentsDeclaration vehicleComponents) + { + return new XElement( + tns + XMLNames.Vehicle_Components, + new XAttribute(xsi + "type", "VehicleComponentsPIFType"), + + GetEngineDescription(vehicleComponents.EngineInputData), + GetGearboxDescription(vehicleComponents.GearboxInputData), + GetTorqueConverterDescription(vehicleComponents.TorqueConverterInputData), + GetAngledriveDescription(vehicleComponents.AngledriveInputData), + GetAxelgearData(vehicleComponents.AxleGearInputData), + GetAxleWheelDescription(vehicleComponents.AxleWheels), + GetAuxiliariesDescription(vehicleComponents.BusAuxiliaries) + ); + } + + + + #region Engine Data + + private XElement GetEngineDescription(IEngineDeclarationInputData engineData) + { + return new XElement(tns + XMLNames.Component_Engine, + new XElement(tns + XMLNames.ComponentDataWrapper, + new XAttribute(xsi + "type", "EngineDataPIFType"), + GetCommonDescription(engineData), + new XElement(tns + XMLNames.Engine_Displacement, engineData.Displacement.ConvertToCubicCentiMeter().ToXMLFormat(0)), + new XElement(tns + XMLNames.Engine_RatedSpeed, engineData.RatedSpeedDeclared.AsRPM.ToXMLFormat(0)), + new XElement(tns + XMLNames.Engine_RatedPower, engineData.RatedPowerDeclared.ToXMLFormat(0)), + new XElement(tns + XMLNames.Engine_MaxTorque, engineData.MaxTorqueDeclared.ToXMLFormat(0)), + new XElement( + tns + XMLNames.Engine_WHRType, + new XElement( + v23 + XMLNames.Engine_WHR_MechanicalOutputICE, (engineData.WHRType & WHRType.MechanicalOutputICE) != 0), + new XElement( + v23 + XMLNames.Engine_WHR_MechanicalOutputIDrivetrain, + (engineData.WHRType & WHRType.MechanicalOutputDrivetrain) != 0), + new XElement(v23 + XMLNames.Engine_WHR_ElectricalOutput, (engineData.WHRType & WHRType.ElectricalOutput) != 0) + ), + GetEngineModes(engineData) + )); + } + + private List<XElement> GetEngineModes(IEngineDeclarationInputData engineData) + { + var fuels = new List<XElement>(); + var engineModes = engineData.EngineModes; + + foreach (var mode in engineModes) { + fuels.Add( + new XElement( + tns + XMLNames.Engine_FuelModes, + new XElement(tns + XMLNames.Engine_IdlingSpeed, mode.IdleSpeed.AsRPM.ToXMLFormat(0)), + new XElement( + tns + XMLNames.Engine_FullLoadAndDragCurve, + FullLoadCurveReader.Create(mode.FullLoadCurve, true).FullLoadEntries.Select( + x => new XElement( + tns + XMLNames.Engine_FullLoadCurve_Entry, + new XAttribute(XMLNames.Engine_EngineFullLoadCurve_EngineSpeed_Attr, + x.EngineSpeed.AsRPM.ToXMLFormat(2)), + new XAttribute(XMLNames.Engine_FullLoadCurve_MaxTorque_Attr, + x.TorqueFullLoad.ToXMLFormat(2)), + new XAttribute(XMLNames.Engine_FullLoadCurve_DragTorque_Attr, + x.TorqueDrag.ToXMLFormat(2))) + )), + new XElement( + tns + "Fuels", + mode.Fuels.Select(x => new XElement(tns + "FuelType", x.FuelType.ToXMLFormat()))) + )); + } + return fuels; + } + + #endregion + + #region Gearbox/Transmission Data + + private XElement GetGearboxDescription(IGearboxDeclarationInputData transmissionData) + { + return new XElement(tns + XMLNames.Component_Transmission, + new XElement(tns + XMLNames.ComponentDataWrapper, + new XAttribute(xsi + "type", "TransmissionDataPIFType"), + GetCommonDescription(transmissionData, true), + new XElement(tns + XMLNames.Gearbox_TransmissionType, transmissionData.Type.ToXMLFormat()), + new XElement( + tns + XMLNames.Gearbox_Gears, + new XAttribute(xsi + "type", "TransmissionGearsPIFType"), + transmissionData.Gears.Select( + x => + new XElement( + tns + XMLNames.Gearbox_Gears_Gear, + new XAttribute(XMLNames.Gearbox_Gear_GearNumber_Attr, x.Gear), + new XElement(tns + XMLNames.Gearbox_Gear_Ratio, x.Ratio.ToXMLFormat(3)), + x.MaxTorque != null + ? new XElement(tns + XMLNames.Gearbox_Gears_MaxTorque, x.MaxTorque.ToXMLFormat(0)) + : null, + x.MaxInputSpeed != null + ? new XElement(tns + XMLNames.Gearbox_Gear_MaxSpeed, x.MaxInputSpeed.AsRPM.ToXMLFormat(0)) + : null))) + )); + } + + #endregion + + #region Torque Converter Data + + private XElement GetTorqueConverterDescription(ITorqueConverterDeclarationInputData tcData) + { + return new XElement(tns + XMLNames.Component_TorqueConverter, + new XElement(tns + XMLNames.ComponentDataWrapper, + new XAttribute(xsi + "type", "TorqueConverterDataPIFType"), + GetCommonDescription(tcData), + GetTorqueConverterCharacteristics(tcData.TCData)) + ); + } + + private XElement GetTorqueConverterCharacteristics(TableData tcData) + { + if (tcData == null) + return null; + + var characteristics = new List<XElement>(); + for (int i = 0; i < tcData.Rows.Count; i++) { + var speedRatio = tcData.Rows[i][TorqueConverterDataReader.Fields.SpeedRatio].ToString(); + var torqueRatio = tcData.Rows[i][TorqueConverterDataReader.Fields.TorqueRatio].ToString(); + var torqueRef = tcData.Rows[i][TorqueConverterDataReader.Fields.CharacteristicTorque].ToString(); + + characteristics.Add( + new XElement(tns + XMLNames.TorqueConverter_Characteristics_Entry, + new XAttribute(XMLNames.TorqueConverterData_SpeedRatio_Attr, speedRatio), + new XAttribute(XMLNames.TorqueConverterData_TorqueRatio_Attr, torqueRatio), + new XAttribute(XMLNames.TorqueConverterDataMapping_InputTorqueRef_Attr, torqueRef) + )); + } + + return characteristics.Count == 0 + ? null : new XElement(tns + XMLNames.TorqueConverter_Characteristics, characteristics); + } + + #endregion + + #region Angledrive Data + + private XElement GetAngledriveDescription(IAngledriveInputData angledriveData) + { + return new XElement(tns + XMLNames.Component_Angledrive, + new XElement(tns + XMLNames.ComponentDataWrapper, + new XAttribute(xsi + "type", "AngledriveDataPIFType"), + GetCommonDescription(angledriveData), + new XElement(tns + XMLNames.AngleDrive_Ratio, angledriveData.Ratio + ))); + } + + #endregion + + + #region Axelgear Data + + private XElement GetAxelgearData(IAxleGearInputData axleGearData) + { + return new XElement(tns + XMLNames.Component_Axlegear, + new XElement(tns + XMLNames.ComponentDataWrapper, + new XAttribute(xsi + "type", "AxlegearDataPIFType"), + GetCommonDescription(axleGearData), + new XElement(tns + XMLNames.Axlegear_LineType, axleGearData.LineType.ToXMLFormat()), + new XElement(tns + XMLNames.Axlegear_Ratio, axleGearData.Ratio.ToXMLFormat(3)))); + } + + #endregion + + #region AxleWheels Data + + private XElement GetAxleWheelDescription(IAxlesDeclarationInputData axleWheelsData) + { + return new XElement( + tns + XMLNames.Component_AxleWheels, + new XElement(tns + XMLNames.ComponentDataWrapper, + new XAttribute(xsi + "type", "AxleWheelsDataPIFType"), + XElement.Parse(axleWheelsData.XMLSource.InnerXml).Elements()) + ); + } + + + #endregion + + + #region Auxiliary Data + + private XElement GetAuxiliariesDescription(IBusAuxiliariesDeclarationData busAux) + { + var busAuxXML = busAux.XMLSource; + + return new XElement( + tns + XMLNames.Component_Auxiliaries, + new XElement( + tns + XMLNames.ComponentDataWrapper, + new XAttribute(xsi + "type", "AuxiliaryDataPIFType"), + XElement.Parse(busAuxXML.InnerXml).Elements() + )); + } + + + #endregion + + + + protected virtual object[] GetCommonDescription(IComponentInputData componentInput, bool isTransmissionData = false) + { + var certificationMethod = componentInput.CertificationMethod != CertificationMethod.Measured ? + componentInput.CertificationMethod.ToXMLFormat() : null; + + var certificationMethodTag = isTransmissionData + ? XMLNames.Component_Gearbox_CertificationMethod + : XMLNames.Component_CertificationMethod; + + return new object[] { + new XElement(tns + XMLNames.Component_Manufacturer, componentInput.Manufacturer), + new XElement(tns + XMLNames.Component_Model, componentInput.Model), + certificationMethod != null ? new XElement(tns + certificationMethodTag, certificationMethod) : null, + new XElement(tns + XMLNames.Component_CertificationNumber, componentInput.CertificationNumber), + new XElement(tns + XMLNames.Component_Date, XmlConvert.ToString(componentInput.Date, XmlDateTimeSerializationMode.Utc)), + new XElement(tns + XMLNames.Component_AppVersion, componentInput.AppVersion) + }; + } + + private string GetNamespaceVersionNumber(XNamespace ns) + { + if (ns == null) + return null; + + var pattern = @"(?<=:v)\d+\.\d+"; + var versionNumber = Regex.Match(ns.NamespaceName, pattern); + return $"v{versionNumber}"; + } + } +} diff --git a/VectoCore/VectoCore/VectoCore.csproj b/VectoCore/VectoCore/VectoCore.csproj index 4562aedbc4f3ad4894e6320a3193f0c7d75f2e33..2b3fec268366af0379017f518d0276650c52fc5b 100644 --- a/VectoCore/VectoCore/VectoCore.csproj +++ b/VectoCore/VectoCore/VectoCore.csproj @@ -288,6 +288,8 @@ <Compile Include="InputData\Reader\ComponentData\ElectricMotorMapReader.cs" /> <Compile Include="InputData\Reader\DataObjectAdapter\DeclarationDataAdapterPrimaryBus.cs" /> <Compile Include="InputData\Reader\ComponentData\ElectricFullLoadCurveReader.cs" /> + <Compile Include="InputData\Reader\Impl\AbstractDeclarationMultistageBusVectoRunDataFactory.cs" /> + <Compile Include="InputData\Reader\Impl\DeclarationModeMultistageBusVectoRunDataFactory.cs" /> <Compile Include="Models\Connector\Ports\Impl\BatteryResponse.cs" /> <Compile Include="Models\Connector\Ports\IElectricEnergyStoragePort.cs" /> <Compile Include="Models\SimulationComponent\Data\Battery\BatteryData.cs" /> @@ -472,10 +474,12 @@ <Compile Include="OutputData\XML\Engineering\XMLWriterMapping.cs" /> <Compile Include="OutputData\XML\XMLCustomerReportCompletedBus.cs" /> <Compile Include="OutputData\XML\XMLDeclarationReportCompletedVehicle.cs" /> + <Compile Include="OutputData\XML\XMLDeclarationReportMultistageBusVehicle.cs" /> <Compile Include="OutputData\XML\XMLDeclarationReportPrimaryVehicle.cs" /> <Compile Include="OutputData\XML\XMLManufacturerReportCompletedBus.cs" /> <Compile Include="OutputData\XML\XMLManufacturerReportExemptedTruck.cs" /> <Compile Include="OutputData\XML\XMLManufacturerReportPrimaryBus.cs" /> + <Compile Include="OutputData\XML\XMLMultistageBusReport.cs" /> <Compile Include="OutputData\XML\XMLPrimaryVehicleReport.cs" /> <Compile Include="Utils\Ninject\UseFirstArgumentAsInstanceProvider.cs" /> <Compile Include="InputData\FileIO\XML\Declaration\NinjectModules\XMLDeclarationReaderInjectModule.cs" /> diff --git a/VectoCore/VectoCoreTest/Integration/Multistage/MultistageVehicleTest.cs b/VectoCore/VectoCoreTest/Integration/Multistage/MultistageVehicleTest.cs new file mode 100644 index 0000000000000000000000000000000000000000..6b073424cfb152a96b8784342b0c74142ee520f4 --- /dev/null +++ b/VectoCore/VectoCoreTest/Integration/Multistage/MultistageVehicleTest.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml; +using Ninject; +using NUnit.Framework; +using TUGraz.VectoCommon.InputData; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCore.Configuration; +using TUGraz.VectoCore.InputData.FileIO.XML; +using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider; +using TUGraz.VectoCore.Models.Simulation.Impl; +using TUGraz.VectoCore.OutputData.FileIO; +using TUGraz.VectoCore.Tests.Models.Simulation; +using TUGraz.VectoCore.Utils; +using XmlDocumentType = System.Xml.XmlDocumentType; + +namespace TUGraz.VectoCore.Tests.Integration.Multistage +{ + [TestFixture] + [Parallelizable(ParallelScope.All)] + public class MultistageVehicleTest + { + const string VIFDirPath = @"TestData\XML\XMLReaderDeclaration\SchemaVersionMultistage.0.1\"; + const string InputDirPath = @"TestData\XML\XMLReaderDeclaration\SchemaVersion2.8\"; + + const string InputFilePath = InputDirPath + "vecto_vehicle-stage_vif_input.xml"; + const string VIFInputFile = VIFDirPath + "vecto_multistage_primary_vehicle_stage_2_3.xml"; + + private const string vifResult = VIFDirPath + "vif_vehicle-sample.xml"; + + protected IXMLInputDataReader xmlInputReader; + protected IXMLInputDataReader xmlVIFInputReader; + + private IKernel _kernel; + + + [OneTimeSetUp] + public void RunBeforeAnyTests() + { + Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); + + _kernel = new StandardKernel(new VectoNinjectModule()); + xmlInputReader = _kernel.Get<IXMLInputDataReader>(); + xmlVIFInputReader = _kernel.Get<IXMLInputDataReader>(); + } + + [TestCase(VIFInputFile, InputFilePath, 1)] + public void TestSimulationMultistageVehicle(string vifFilename, string inputFilename, int numRuns) + { + //Input files + var inputReader = XmlReader.Create(inputFilename); + var inputDataProvider = xmlInputReader.CreateDeclaration(inputReader); + var vehicle = inputDataProvider.JobInputData.Vehicle; + + var vifReader = XmlReader.Create(vifFilename); + var vifDataProvider = xmlInputReader.Create(vifReader) as IMultistageBusInputDataProvider; + + var writer = new FileOutputWriter(vifResult); + var inputData = new XMLDeclarationVIFInputData(vifDataProvider, vehicle); + + var factory = new SimulatorFactory(ExecutionMode.Declaration, inputData, writer); + + var jobContainer = new JobContainer(new MockSumWriter()); + + var runs = factory.SimulationRuns().ToList(); + Assert.AreEqual(numRuns, runs.Count); + foreach (var run in runs) + { + jobContainer.AddRun(run); + } + + jobContainer.Execute(); + jobContainer.WaitFinished(); + var progress = jobContainer.GetProgress(); + Assert.IsTrue(progress.All(r => r.Value.Success), string.Concat<Exception>(progress.Select(r => r.Value.Error))); + + + var validator = new XMLValidator(XmlReader.Create(writer.XMLMultistageReportFileName)); + Assert.IsTrue(validator.ValidateXML(VectoCore.Utils.XmlDocumentType.MultistageOutputData), validator.ValidationError); + } + + } +} diff --git a/VectoCore/VectoCoreTest/VectoCoreTest.csproj b/VectoCore/VectoCoreTest/VectoCoreTest.csproj index 05a4ae7fcc646c3eb852bbf896535533bdd45372..7aa23e09e27a651fe32ed947e6bcd74111b01cfa 100644 --- a/VectoCore/VectoCoreTest/VectoCoreTest.csproj +++ b/VectoCore/VectoCoreTest/VectoCoreTest.csproj @@ -4681,6 +4681,9 @@ <Content Include="TestData\XML\XMLReaderDeclaration\SchemaVersion2.8\vecto_vehicle-stage_input_only_mandatory_standard_value_airdrag.xml"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> + <Content Include="TestData\XML\XMLReaderDeclaration\SchemaVersion2.8\vecto_vehicle-stage_vif_input.xml"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> <Content Include="TestData\XML\XMLReaderDeclaration\SchemaVersionMultistage.0.1\vecto_multistage_consolidated_multiple_stages.xml"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> @@ -4696,6 +4699,9 @@ <Content Include="TestData\XML\XMLReaderDeclaration\SchemaVersionMultistage.0.1\vecto_multistage_consolidated_multiple_stages_NGTankSystem.xml"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> + <Content Include="TestData\XML\XMLReaderDeclaration\SchemaVersionMultistage.0.1\vecto_multistage_consolidated_multiple_stages_vif.xml"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> <Content Include="TestData\XML\XMLReaderDeclaration\SchemaVersionMultistage.0.1\vecto_multistage_consolidated_one_stage.xml"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content>