Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit f0da03df authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

Merge pull request #692 in VECTO/vecto-sim from...

Merge pull request #692 in VECTO/vecto-sim from ~EMQUARIMA/vecto-sim:feature/VECTO-808-add-moitoring-report to develop

* commit 'bcf2786f':
  add link to monitoring report in GUI
  adding testcase for validating generated reports
  adding monitoring report type and monitoring repot class
  updating schema for monitoring report
parents a39a181e bcf2786f
No related branches found
No related tags found
No related merge requests found
......@@ -1084,8 +1084,8 @@ Imports TUGraz.VectoCore.Utils
dim w as FileOutputWriter = new FileOutputWriter(job)
For Each entry as KeyValuePair(Of string, string) In _
new Dictionary(Of string, string) _
from {{w.XMLFullReportName, "XML Manufacturer Report"}, {w.XMLCustomerReportName, "Customer Report"},
{w.XMLVTPReportName, "VTP Report"}}
from {{w.XMLFullReportName, "XML Manufacturer Report"}, {w.XMLCustomerReportName, "XML Customer Report"},
{w.XMLVTPReportName, "VTP Report"}, {w.XMLMonitoringReportName, "XML Monitoring Report"}}
If File.Exists(entry.Key) Then
sender.ReportProgress(100, New VectoProgress With {.Target = "ListBox",
.Message =
......
......@@ -65,6 +65,11 @@ namespace TUGraz.VectoCore.OutputData.FileIO
get { return Path.ChangeExtension(_jobFile, "RSLT_CUSTOMER.xml"); }
}
public string XMLMonitoringReportName
{
get { return Path.ChangeExtension(_jobFile, "RSLT_MONITORING.xml"); }
}
public string XMLVTPReportName
{
get { return Path.ChangeExtension(_jobFile, "VTP_Report.xml"); }
......@@ -116,6 +121,9 @@ namespace TUGraz.VectoCore.OutputData.FileIO
case ReportType.DeclarationReportCustomerXML:
fileName = XMLCustomerReportName;
break;
case ReportType.DeclarationReportMonitoringXML:
fileName = XMLMonitoringReportName;
break;
case ReportType.DeclarationVTPReportXML:
fileName = XMLVTPReportName;
break;
......
......@@ -59,6 +59,7 @@ namespace TUGraz.VectoCore.OutputData
DeclarationReportPdf,
DeclarationReportManufacturerXML,
DeclarationReportCustomerXML,
DeclarationVTPReportXML
DeclarationVTPReportXML,
DeclarationReportMonitoringXML
}
}
\ No newline at end of file
......@@ -52,6 +52,7 @@ namespace TUGraz.VectoCore.OutputData.XML
{
private readonly XMLManufacturerReport _manufacturerReport;
private readonly XMLCustomerReport _customerReport;
private readonly XMLMonitoringReport _monitoringReport;
private readonly IOutputDataWriter _writer;
......@@ -171,6 +172,7 @@ namespace TUGraz.VectoCore.OutputData.XML
{
_manufacturerReport = new XMLManufacturerReport();
_customerReport = new XMLCustomerReport();
_monitoringReport = new XMLMonitoringReport(_manufacturerReport);
_writer = writer;
}
......@@ -185,6 +187,11 @@ namespace TUGraz.VectoCore.OutputData.XML
get { return _customerReport.Report; }
}
public XDocument MonitoringReport
{
get { return _monitoringReport.Report; }
}
protected override void DoAddResult(ResultEntry entry, VectoRunData runData, IModalDataContainer modData)
{
......@@ -206,6 +213,7 @@ namespace TUGraz.VectoCore.OutputData.XML
if (_writer != null) {
_writer.WriteReport(ReportType.DeclarationReportCustomerXML, _customerReport.Report);
_writer.WriteReport(ReportType.DeclarationReportManufacturerXML, _manufacturerReport.Report);
_writer.WriteReport(ReportType.DeclarationReportMonitoringXML, _monitoringReport.Report);
}
}
......@@ -227,6 +235,7 @@ namespace TUGraz.VectoCore.OutputData.XML
: DeclarationData.WeightingFactors.Lookup(weightingGroup);
_manufacturerReport.Initialize(modelData);
_customerReport.Initialize(modelData);
_monitoringReport.Initialize(modelData);
}
private static IDictionary<Tuple<MissionType, LoadingType>, double> ZeroWeighting
......
using System;
using System.Linq;
using System.Xml.Linq;
using System.Xml.XPath;
using TUGraz.IVT.VectoXML.Writer;
using TUGraz.VectoCommon.Models;
using TUGraz.VectoCommon.Resources;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.OutputData.XML
{
public class XMLMonitoringReport
{
public const string CURRENT_SCHEMA_VERSION = "0.7";
private XMLManufacturerReport _manufacturerReport;
protected XNamespace tns;
protected XNamespace di;
private XElement _additionalFields;
public XMLMonitoringReport(XMLManufacturerReport manufacturerReport)
{
di = "http://www.w3.org/2000/09/xmldsig#";
tns = "urn:tugraz:ivt:VectoAPI:MonitoringOutput:v" + CURRENT_SCHEMA_VERSION;
_manufacturerReport = manufacturerReport;
}
public XDocument Report
{
get {
var mrf = _manufacturerReport.Report;
if (mrf == null) {
return null;
}
var retVal = GenerateReport();
retVal.Root?.Add(
new XElement(
tns + "ManufacturerRecord",
GetManufacturerData(mrf)),
_additionalFields
);
return retVal;
}
}
private object[] GetManufacturerData(XDocument mrf)
{
return mrf.Root?.XPathSelectElements("./*").ToArray<object>();
}
private XDocument GenerateReport()
{
var xsi = XNamespace.Get("http://www.w3.org/2001/XMLSchema-instance");
var retVal = new XDocument();
//retVal.Add(
// new XProcessingInstruction(
// "xml-stylesheet", "href=\"https://webgate.ec.europa.eu/CITnet/svn/VECTO/trunk/Share/XML/CSS/VectoReports.css\""));
retVal.Add(
new XElement(
tns + "VectoMonitoring",
new XAttribute("schemaVersion", CURRENT_SCHEMA_VERSION),
new XAttribute(XNamespace.Xmlns + "xsi", xsi.NamespaceName),
new XAttribute("xmlns", tns),
new XAttribute(XNamespace.Xmlns + "di", di),
new XAttribute(
xsi + "schemaLocation",
string.Format(
"{0} {1}VectoMonitoring.{2}.xsd", tns, AbstractXMLWriter.SchemaLocationBaseUrl, CURRENT_SCHEMA_VERSION))
)
);
return retVal;
}
public void Initialize(VectoRunData modelData)
{
var numAxles = modelData.VehicleData.AxleData.Count(x => x.AxleType != AxleType.Trailer);
var axleData = new object[numAxles];
for (var i = 0; i < axleData.Length; i++) {
axleData[i] = new XElement(tns + "Axle",
new XAttribute("axleNumber", i+1),
new XElement(tns + "Tyre", GetStandardFields(string.Format("TYRE_{0}", i+1))
));
}
_additionalFields = new XElement(
tns + "AdditionalData",
new XElement(tns + "Vehicle",
new XElement(tns + "Make", "##VEHICLE_MAKE##")),
new XElement(tns + "Engine",
new XElement(tns + "WHTC",
new XElement(tns + "CO2", XMLHelper.ValueAsUnit(double.NaN, "g/kWh", 0)),
new XElement(tns + "FuelConsumption", XMLHelper.ValueAsUnit(double.NaN, "g/kWh", 0))
),
new XElement(tns + "WHSC",
new XElement(tns + "CO2", XMLHelper.ValueAsUnit(double.NaN, "g/kWh", 0)),
new XElement(tns + "FuelConsumption", XMLHelper.ValueAsUnit(double.NaN, "g/kWh", 0))
)
),
new XElement(tns + "Gearbox",GetStandardFields("GEARBOX")),
new XElement(tns + "Axlegear", GetStandardFields("AXLEGEAR")),
new XElement(tns + "AxleWheels", axleData),
new XElement(tns + "AdvancedReducingTechnologies", new XComment(GetReducingTechnologiesExample())),
new XElement(tns + "VectoLicenseNbr", "##VECTO_LICENSE_NUMBER##")
);
}
private object[] GetStandardFields(string prefix)
{
return new[] {
new XElement(tns + "Manufacturer", string.Format("##{0}_MANUFACTURER##", prefix)),
new XElement(tns + "ManufacturerAddress", string.Format("##{0}_MANUFACTURERADDRESS##", prefix)),
new XElement(tns + "Make", string.Format("##{0}_MAKE##", prefix))
};
}
private string GetReducingTechnologiesExample()
{
var categories = new[] {
"advanced aerodynamic measures",
"advanced rolling resistance measures",
"advanced drivetrain technologies",
"advanced engine technologies",
"advanced auxiliary technologies",
"additional ADAS technologies",
"advanced powertrain integration and hybridisation",
"other"
};
var retVal = new object[categories.Length];
//var tmp = new XElement(tns + "foo");
for (var i = 0; i < retVal.Length; i++) {
retVal[i] = new XElement("Entry",
new XAttribute("category", categories[i]),
"##TECHNOLOGY_BRAND_NAME##"
);
}
return Environment.NewLine + string.Join(Environment.NewLine, retVal.Select(x => x.ToString())) + Environment.NewLine;
}
}
}
......@@ -180,7 +180,14 @@
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="axleNumber" use="required"/>
<xs:attribute name="axleNumber" use="required">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="4"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
......@@ -192,7 +199,7 @@
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="Entry" maxOccurs="unbounded">
<xs:element name="Entry" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
......@@ -226,6 +233,7 @@
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="schemaVersion" type="xs:decimal" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
......@@ -100,8 +100,8 @@ namespace TUGraz.VectoCore.Utils {
{
switch (unit) {
case "%": return GetValueAsUnit(value * 100, unit, decimals);
default: return GetValueAsUnit(value, unit, decimals);
}
throw new NotImplementedException(string.Format("unknown unit '{0}'", unit));
}
private static object[] GetValueAsUnit(double value, string unit, uint? decimals)
......
......@@ -52,7 +52,8 @@ namespace TUGraz.VectoCore.Utils
{XmlDocumentType.DeclarationComponentData, Tuple.Create("VectoComponent{0}.xsd", new [] {"1.0"}) },
{XmlDocumentType.EngineeringData, Tuple.Create("VectoEngineeringInput{0}.xsd", new [] {"0.7"}) },
{XmlDocumentType.ManufacturerReport, Tuple.Create("VectoOutputManufacturer{0}.xsd", new [] {"0.4", "0.5", "0.6", "0.7"}) },
{ XmlDocumentType.CustomerReport , Tuple.Create("VectoOutputCustomer{0}.xsd", new [] {"0.4", "0.5", "0.7"})},
{XmlDocumentType.CustomerReport , Tuple.Create("VectoOutputCustomer{0}.xsd", new [] {"0.4", "0.5", "0.7"})},
{XmlDocumentType.MonitoringReport , Tuple.Create("VectoMonitoring{0}.xsd", new [] {"0.7"})},
};
private XMLValidator(Action<bool> resultaction, Action<XmlSeverityType, ValidationEvent> validationErrorAction)
......@@ -134,6 +135,7 @@ namespace TUGraz.VectoCore.Utils
EngineeringData = 1<<4,
ManufacturerReport = 1<<5,
CustomerReport = 1<<6,
MonitoringReport = 1<<7,
}
}
......
......@@ -202,6 +202,7 @@
<Compile Include="InputData\Reader\Impl\EngineeringVTPModeVectoRunDataFactory.cs" />
<Compile Include="Models\SimulationComponent\Impl\VTPCycle.cs" />
<Compile Include="Models\Simulation\Impl\ExemptedRun.cs" />
<Compile Include="OutputData\XML\XMLMonitoringReport.cs" />
<Compile Include="OutputData\XML\XMLVTPReport.cs" />
<Compile Include="OutputData\VTPReport.cs" />
<Compile Include="OutputData\ModFilter\ActualModalDataFilter.cs" />
......@@ -476,6 +477,9 @@
<EmbeddedResource Include="Resources\Declaration\CO2Standards\MissionProfileWeights.csv" />
<EmbeddedResource Include="Resources\Declaration\CO2Standards\WeightingGroups.csv" />
<EmbeddedResource Include="Resources\Declaration\TyreLabeling.csv" />
<EmbeddedResource Include="Resources\XSD\VectoMonitoring.0.7.xsd">
<SubType>Designer</SubType>
</EmbeddedResource>
<None Include="Utils\VectoVersionCore.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>VectoVersionCore.cs</LastGenOutput>
......
......@@ -31,7 +31,9 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
using NUnit.Framework;
using TUGraz.VectoCommon.Models;
......@@ -105,6 +107,50 @@ namespace TUGraz.VectoCore.Tests.Integration
}
}
[TestCase()]
public void TestValidationXMLReports()
{
var jobfile = @"Testdata\XML\XMLReaderDeclaration\vecto_vehicle-sample.xml";
var dataProvider = new XMLDeclarationInputDataProvider(XmlReader.Create(jobfile), true);
var writer = new FileOutputWriter(jobfile);
var xmlReport = new XMLDeclarationReport(writer);
var sumData = new SummaryDataContainer(writer);
var jobContainer = new JobContainer(sumData);
if (File.Exists(writer.SumFileName)) {
File.Delete(writer.SumFileName);
}
var runsFactory = new SimulatorFactory(ExecutionMode.Declaration, dataProvider, writer, xmlReport) {
WriteModalResults = false,
Validate = false,
};
jobContainer.AddRuns(runsFactory);
jobContainer.Execute();
jobContainer.WaitFinished();
var mrfValidator = GetValidator(xmlReport.FullReport);
mrfValidator.ValidateXML(XMLValidator.XmlDocumentType.ManufacturerReport);
var cifValidator = GetValidator(xmlReport.CustomerReport);
cifValidator.ValidateXML(XMLValidator.XmlDocumentType.CustomerReport);
var monitoringValidator = GetValidator(xmlReport.MonitoringReport);
monitoringValidator.ValidateXML(XMLValidator.XmlDocumentType.MonitoringReport);
}
private static XMLValidator GetValidator(XDocument xmlReport)
{
var mrfStream = new MemoryStream();
var mrfWriter = new XmlTextWriter(mrfStream, Encoding.UTF8);
xmlReport.WriteTo(mrfWriter);
mrfWriter.Flush();
mrfStream.Flush();
mrfStream.Seek(0, SeekOrigin.Begin);
return new XMLValidator(new XmlTextReader(mrfStream));
}
[TestCase()]
public void TestXMLReportPTO()
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment