From b3374bf9ab1df594cebc7eebd0b1bf86747616fe Mon Sep 17 00:00:00 2001
From: Michael Krisper <michael.krisper@tugraz.at>
Date: Mon, 12 Oct 2015 17:54:10 +0200
Subject: [PATCH] integrated the DeclarationReport into moddatawriter

---
 .../DeclarationModeSimulationDataReader.cs    |  17 +-
 .../{Report.cs => DeclarationReport.cs}       | 300 ++++++++----------
 VectoCore/Models/Declaration/Mission.cs       |  26 +-
 .../Models/Simulation/Data/ModalDataWriter.cs |  16 +-
 .../Models/Simulation/Data/VectoRunData.cs    |   4 +-
 .../Simulation/Impl/SimulatorFactory.cs       |   3 +-
 VectoCore/VectoCore.csproj                    |   2 +-
 7 files changed, 184 insertions(+), 184 deletions(-)
 rename VectoCore/Models/Declaration/{Report.cs => DeclarationReport.cs} (92%)

diff --git a/VectoCore/FileIO/Reader/Impl/DeclarationModeSimulationDataReader.cs b/VectoCore/FileIO/Reader/Impl/DeclarationModeSimulationDataReader.cs
index 7deea301e0..4e3172c426 100644
--- a/VectoCore/FileIO/Reader/Impl/DeclarationModeSimulationDataReader.cs
+++ b/VectoCore/FileIO/Reader/Impl/DeclarationModeSimulationDataReader.cs
@@ -34,16 +34,19 @@ namespace TUGraz.VectoCore.FileIO.Reader.Impl
 			var driverdata = dao.CreateDriverData(Job);
 			driverdata.AccelerationCurve = AccelerationCurveData.ReadFromStream(segment.AccelerationFile);
 
+			var resultCount = segment.Missions.Sum(m => m.Loadings.Count);
+
 			var engineData = dao.CreateEngineData(Engine);
 			var gearboxData = dao.CreateGearboxData(Gearbox, engineData);
-			var report = new Report(engineData.FullLoadCurve, segment, "CREATOR", engineData.ModelName, "engineStr",
-				"outputfilepath", gearboxData.ModelName, "gearboxStr", Job.JobFile);
+			var report = new DeclarationReport(engineData.FullLoadCurve, segment, "CREATOR", engineData.ModelName, "engineStr",
+				"outputfilepath", gearboxData.ModelName, "gearboxStr", Job.JobFile, resultCount);
 
 			foreach (var mission in segment.Missions) {
 				var cycle = DrivingCycleDataReader.ReadFromStream(mission.CycleFile, CycleType.DistanceBased);
 				foreach (var loading in mission.Loadings) {
 					var simulationRunData = new VectoRunData {
-						VehicleData = dao.CreateVehicleData(Vehicle, mission, loading.LoadingWeight),
+						Loading = loading.Key,
+						VehicleData = dao.CreateVehicleData(Vehicle, mission, loading.Value),
 						EngineData = engineData,
 						GearboxData = dao.CreateGearboxData(Gearbox, engineData),
 						Aux = dao.CreateAuxiliaryData(Aux, mission.MissionType, segment.VehicleClass),
@@ -52,8 +55,9 @@ namespace TUGraz.VectoCore.FileIO.Reader.Impl
 						IsEngineOnly = IsEngineOnly,
 						JobFileName = Job.JobFile,
 						BasePath = "",
-						ModFileSuffix = loading.Name,
+						ModFileSuffix = loading.Key.ToString(),
 						Report = report,
+						Mission = mission,
 					};
 					simulationRunData.Cycle.Name = mission.MissionType.ToString();
 					simulationRunData.VehicleData.VehicleClass = segment.VehicleClass;
@@ -67,9 +71,8 @@ namespace TUGraz.VectoCore.FileIO.Reader.Impl
 			try {
 				var job = vectoJob as VectoJobFileV2Declaration;
 				if (job == null) {
-					throw new VectoException(
-						string.Format("Unhandled Job File Format. Expected: Job File, Version 2, Declaration Mode. Got: {0}",
-							vectoJob.GetType()));
+					throw new VectoException("Unhandled Job File Format. Expected: Job File, Version 2, Declaration Mode. Got: {0}",
+						vectoJob.GetType());
 				}
 				Vehicle = ReadVehicle(Path.Combine(job.BasePath, job.Body.VehicleFile));
 				Engine = ReadEngine(Path.Combine(job.BasePath, job.Body.EngineFile));
diff --git a/VectoCore/Models/Declaration/Report.cs b/VectoCore/Models/Declaration/DeclarationReport.cs
similarity index 92%
rename from VectoCore/Models/Declaration/Report.cs
rename to VectoCore/Models/Declaration/DeclarationReport.cs
index 24c914735b..540140da05 100644
--- a/VectoCore/Models/Declaration/Report.cs
+++ b/VectoCore/Models/Declaration/DeclarationReport.cs
@@ -17,31 +17,7 @@ using Rectangle = System.Drawing.Rectangle;
 
 namespace TUGraz.VectoCore.Models.Declaration
 {
-	public enum LoadingType
-	{
-		Full,
-		Reference,
-		Empty,
-		UserDefined
-	}
-
-
-	public static class LoadingTypeHelper
-	{
-		private static readonly Dictionary<LoadingType, string> LoadingTypeToString = new Dictionary<LoadingType, string> {
-			{ LoadingType.Empty, "E" },
-			{ LoadingType.Full, "F" },
-			{ LoadingType.Reference, "R" }
-		};
-
-
-		public static string GetName(this LoadingType loadingType)
-		{
-			return LoadingTypeToString[loadingType];
-		}
-	}
-
-	public class Report
+	public class DeclarationReport
 	{
 		public class ResultContainer
 		{
@@ -65,9 +41,10 @@ namespace TUGraz.VectoCore.Models.Declaration
 		private readonly string _gearboxModel;
 		private readonly string _gearboxStr;
 		private readonly string _jobFile;
+		private readonly int _resultCount;
 
-		public Report(FullLoadCurve flc, Segment segment, string creator, string engineModel, string engineStr,
-			string outputFilePath, string gearboxModel, string gearboxStr, string jobFile)
+		public DeclarationReport(FullLoadCurve flc, Segment segment, string creator, string engineModel, string engineStr,
+			string outputFilePath, string gearboxModel, string gearboxStr, string jobFile, int resultCount)
 		{
 			_flc = flc;
 			_segment = segment;
@@ -78,6 +55,7 @@ namespace TUGraz.VectoCore.Models.Declaration
 			_gearboxModel = gearboxModel;
 			_gearboxStr = gearboxStr;
 			_jobFile = jobFile;
+			_resultCount = resultCount;
 		}
 
 		public void AddResult(LoadingType loadingType, Mission mission, IModalDataWriter modData)
@@ -91,10 +69,135 @@ namespace TUGraz.VectoCore.Models.Declaration
 			_missions[mission.MissionType].ModData[loadingType] = modData;
 
 
-			//ChartTqN = DrawOperatingPointsChart(modData, _flc),
-			//ChartCycle = DrawCycleChart(modData)
+			if (_resultCount == _missions.Sum(v => v.Value.ModData.Count)) {
+				WriteReport();
+			}
 		}
 
+		private void WriteReport()
+		{
+			_chartCO2Missions = DrawCO2MissionsChart(_missions);
+			_chartCO2speed = DrawCO2SpeedChart(_missions);
+
+			foreach (var mission in _missions.Values) {
+				mission.ChartCycle = DrawCycleChart(mission);
+				mission.ChartTqN = DrawOperatingPointsChart(mission.ModData[LoadingType.ReferenceLoad], _flc);
+			}
+
+			WritePdfs(_missions);
+		}
+
+		private static Bitmap DrawCO2MissionsChart(Dictionary<MissionType, ResultContainer> missions)
+		{
+			var co2Chart = new Chart { Width = 1500, Height = 700 };
+			co2Chart.Legends.Add(new Legend("main") {
+				Font = new Font("Helvetica", 20),
+				BorderColor = Color.Black,
+				BorderWidth = 3,
+			});
+			co2Chart.ChartAreas.Add(new ChartArea {
+				Name = "main",
+				AxisX = {
+					Title = "Missions",
+					TitleFont = new Font("Helvetica", 20),
+					LabelStyle = { Enabled = false }
+				},
+				AxisY = {
+					Title = "CO2 [g/tkm]",
+					TitleFont = new Font("Helvetica", 20),
+					LabelStyle = { Font = new Font("Helvetica", 20) },
+					LabelAutoFitStyle = LabelAutoFitStyles.None
+				},
+				BorderDashStyle = ChartDashStyle.Solid,
+				BorderWidth = 3
+			});
+
+
+			foreach (var missionResult in missions) {
+				var series = new Series(missionResult.Key + " (Ref. load.)");
+				series.Points[0].Label = series.Points[0].YValues[0].ToString("0.0") + " [g/tkm]";
+				series.Points[0].Font = new Font("Helvetica", 20);
+				series.Points[0].LabelBackColor = Color.White;
+
+				var co2sum = missionResult.Value.ModData[LoadingType.ReferenceLoad].GetValues<SI>(ModalResultField.FCMap).Sum();
+
+				var maxDistance = missionResult.Value.ModData[LoadingType.ReferenceLoad].GetValues<SI>(ModalResultField.dist).Max();
+				var loading = missionResult.Value.Mission.Loadings[LoadingType.ReferenceLoad];
+				var co2pertkm = co2sum / maxDistance / loading * 1000;
+
+				series.Points.AddXY(missionResult.Key, co2pertkm.Value());
+				co2Chart.Series.Add(series);
+			}
+
+			co2Chart.Update();
+
+			var chartCO2tkm = new Bitmap(co2Chart.Width, co2Chart.Height, PixelFormat.Format32bppArgb);
+			co2Chart.DrawToBitmap(chartCO2tkm, new Rectangle(0, 0, chartCO2tkm.Width, chartCO2tkm.Height));
+			return chartCO2tkm;
+		}
+
+		private static Bitmap DrawCO2SpeedChart(Dictionary<MissionType, ResultContainer> missions)
+		{
+			var co2speedChart = new Chart { Width = 1500, Height = 700 };
+			co2speedChart.Legends.Add(new Legend("main") {
+				Font = new Font("Helvetica", 20),
+				BorderColor = Color.Black,
+				BorderWidth = 3,
+			});
+			co2speedChart.ChartAreas.Add(new ChartArea("main") {
+				BorderDashStyle = ChartDashStyle.Solid,
+				BorderWidth = 3,
+				AxisX = {
+					Title = "vehicle speed [km/h]",
+					TitleFont = new Font("Helvetica", 20),
+					LabelStyle = { Font = new Font("Helvetica", 20) },
+					LabelAutoFitStyle = LabelAutoFitStyles.None,
+					Minimum = 20.0,
+				},
+				AxisY = {
+					Title = "CO2 [g/km]",
+					TitleFont = new Font("Helvetica", 20),
+					LabelStyle = { Font = new Font("Helvetica", 20) },
+					LabelAutoFitStyle = LabelAutoFitStyles.None
+				}
+			});
+
+			foreach (var missionResult in missions) {
+				var series = new Series { MarkerSize = 15, MarkerStyle = MarkerStyle.Circle, ChartType = SeriesChartType.Point };
+				foreach (var pair in missionResult.Value.ModData) {
+					var dt = pair.Value.GetValues<SI>(ModalResultField.simulationInterval).ToDouble();
+					var speed = pair.Value.GetValues<SI>(ModalResultField.v_act).ToDouble();
+					var distance = pair.Value.GetValues<SI>(ModalResultField.dist).Max().Value();
+
+					//todo get co2 value
+					var co2 = pair.Value.GetValues<SI>(ModalResultField.FCMap).ToDouble();
+
+					var avgSpeed = speed.Zip(dt, (v, t) => v / t).Average();
+					var avgCO2km = co2.Zip(dt, (co, t) => co / t).Average() / distance * 1000;
+
+					var loading = missionResult.Value.Mission.Loadings[pair.Key];
+
+					var point = new DataPoint(avgSpeed, avgCO2km) {
+						Label = loading.Value().ToString("0.0") + " t",
+						Font = new Font("Helvetica", 16),
+						LabelBackColor = Color.White
+					};
+
+					if (pair.Key != LoadingType.ReferenceLoad) {
+						point.MarkerSize = 10;
+						point.Font = new Font("Helvetica", 14);
+					}
+					series.Points.Add(point);
+				}
+				series.Name = missionResult.Key.ToString();
+				co2speedChart.Series.Add(series);
+			}
+
+			co2speedChart.Update();
+			var chartCO2speed = new Bitmap(co2speedChart.Width, co2speedChart.Height, PixelFormat.Format32bppArgb);
+			co2speedChart.DrawToBitmap(chartCO2speed, new Rectangle(0, 0, co2speedChart.Width, co2speedChart.Height));
+			return chartCO2speed;
+		}
 
 		private static Bitmap DrawCycleChart(ResultContainer results)
 		{
@@ -167,7 +270,6 @@ namespace TUGraz.VectoCore.Models.Declaration
 			return cycleChart;
 		}
 
-
 		private static Bitmap DrawOperatingPointsChart(IModalDataWriter modData, FullLoadCurve flc)
 		{
 			var operatingPointsChart = new Chart { Width = 1000, Height = 427 };
@@ -228,126 +330,6 @@ namespace TUGraz.VectoCore.Models.Declaration
 			return tqnBitmap;
 		}
 
-
-		public void CreateCharts()
-		{
-			_chartCO2Missions = DrawCO2MissionsChart(_missions);
-			_chartCO2speed = DrawCO2SpeedChart(_missions);
-		}
-
-		private static Bitmap DrawCO2MissionsChart(Dictionary<MissionType, ResultContainer> missions)
-		{
-			var co2Chart = new Chart { Width = 1500, Height = 700 };
-			co2Chart.Legends.Add(new Legend("main") {
-				Font = new Font("Helvetica", 20),
-				BorderColor = Color.Black,
-				BorderWidth = 3,
-			});
-			co2Chart.ChartAreas.Add(new ChartArea {
-				Name = "main",
-				AxisX = {
-					Title = "Missions",
-					TitleFont = new Font("Helvetica", 20),
-					LabelStyle = { Enabled = false }
-				},
-				AxisY = {
-					Title = "CO2 [g/tkm]",
-					TitleFont = new Font("Helvetica", 20),
-					LabelStyle = { Font = new Font("Helvetica", 20) },
-					LabelAutoFitStyle = LabelAutoFitStyles.None
-				},
-				BorderDashStyle = ChartDashStyle.Solid,
-				BorderWidth = 3
-			});
-
-
-			foreach (var missionResult in missions) {
-				var series = new Series(missionResult.Key + " (Ref. load.)");
-				series.Points[0].Label = series.Points[0].YValues[0].ToString("0.0") + " [g/tkm]";
-				series.Points[0].Font = new Font("Helvetica", 20);
-				series.Points[0].LabelBackColor = Color.White;
-
-				var co2sum = missionResult.Value.ModData[LoadingType.Reference].GetValues<SI>(ModalResultField.FCMap).Sum();
-
-				var maxDistance = missionResult.Value.ModData[LoadingType.Reference].GetValues<SI>(ModalResultField.dist).Max();
-				var loading = GetLoading(LoadingType.Reference, missionResult.Value.Mission);
-				var co2pertkm = co2sum / maxDistance / loading * 1000;
-
-				series.Points.AddXY(missionResult.Key, co2pertkm.Value());
-				co2Chart.Series.Add(series);
-			}
-
-			co2Chart.Update();
-
-			var chartCO2tkm = new Bitmap(co2Chart.Width, co2Chart.Height, PixelFormat.Format32bppArgb);
-			co2Chart.DrawToBitmap(chartCO2tkm, new Rectangle(0, 0, chartCO2tkm.Width, chartCO2tkm.Height));
-			return chartCO2tkm;
-		}
-
-		private static Bitmap DrawCO2SpeedChart(Dictionary<MissionType, ResultContainer> missions)
-		{
-			var co2speedChart = new Chart { Width = 1500, Height = 700 };
-			co2speedChart.Legends.Add(new Legend("main") {
-				Font = new Font("Helvetica", 20),
-				BorderColor = Color.Black,
-				BorderWidth = 3,
-			});
-			co2speedChart.ChartAreas.Add(new ChartArea("main") {
-				BorderDashStyle = ChartDashStyle.Solid,
-				BorderWidth = 3,
-				AxisX = {
-					Title = "vehicle speed [km/h]",
-					TitleFont = new Font("Helvetica", 20),
-					LabelStyle = { Font = new Font("Helvetica", 20) },
-					LabelAutoFitStyle = LabelAutoFitStyles.None,
-					Minimum = 20.0,
-				},
-				AxisY = {
-					Title = "CO2 [g/km]",
-					TitleFont = new Font("Helvetica", 20),
-					LabelStyle = { Font = new Font("Helvetica", 20) },
-					LabelAutoFitStyle = LabelAutoFitStyles.None
-				}
-			});
-
-			foreach (var missionResult in missions) {
-				var series = new Series { MarkerSize = 15, MarkerStyle = MarkerStyle.Circle, ChartType = SeriesChartType.Point };
-				foreach (var pair in missionResult.Value.ModData) {
-					var dt = pair.Value.GetValues<SI>(ModalResultField.simulationInterval).ToDouble();
-					var speed = pair.Value.GetValues<SI>(ModalResultField.v_act).ToDouble();
-					var distance = pair.Value.GetValues<SI>(ModalResultField.dist).Max().Value();
-
-					//todo get co2 value
-					var co2 = pair.Value.GetValues<SI>(ModalResultField.FCMap).ToDouble();
-
-					var avgSpeed = speed.Zip(dt, (v, t) => v / t).Average();
-					var avgCO2km = co2.Zip(dt, (co, t) => co / t).Average() / distance * 1000;
-
-					var loading = GetLoading(pair.Key, missionResult.Value.Mission);
-
-					var point = new DataPoint(avgSpeed, avgCO2km) {
-						Label = loading.Value().ToString("0.0") + " t",
-						Font = new Font("Helvetica", 16),
-						LabelBackColor = Color.White
-					};
-
-					if (pair.Key != LoadingType.Reference) {
-						point.MarkerSize = 10;
-						point.Font = new Font("Helvetica", 14);
-					}
-					series.Points.Add(point);
-				}
-				series.Name = missionResult.Key.ToString();
-				co2speedChart.Series.Add(series);
-			}
-
-			co2speedChart.Update();
-			var chartCO2speed = new Bitmap(co2speedChart.Width, co2speedChart.Height, PixelFormat.Format32bppArgb);
-			co2speedChart.DrawToBitmap(chartCO2speed, new Rectangle(0, 0, co2speedChart.Width, co2speedChart.Height));
-			return chartCO2speed;
-		}
-
-
 		public void WritePdfs(Dictionary<MissionType, ResultContainer> missions)
 		{
 			var assemblyPath = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
@@ -401,7 +383,7 @@ namespace TUGraz.VectoCore.Models.Declaration
 			foreach (var results in missions.Values) {
 				pdfFields.SetField("Mission" + i, results.Mission.MissionType.ToString());
 
-				var m = results.ModData[LoadingType.Reference];
+				var m = results.ModData[LoadingType.ReferenceLoad];
 				var dt = m.GetValues<SI>(ModalResultField.simulationInterval);
 				var distance = m.GetValues<SI>(ModalResultField.dist).Max().Value();
 
@@ -468,8 +450,8 @@ namespace TUGraz.VectoCore.Models.Declaration
 				var loadingType = pair.Key;
 				var m = pair.Value;
 
-				var loadString = loadingType.GetName();
-				pdfFields.SetField("Load" + loadString, GetLoading(loadingType, results.Mission).ToString("0.0") + " t");
+				var loadString = loadingType.GetShortName();
+				pdfFields.SetField("Load" + loadString, results.Mission.Loadings[loadingType].ToString("0.0") + " t");
 
 				var dt = m.GetValues<SI>(ModalResultField.simulationInterval);
 				var distance = m.GetValues<SI>(ModalResultField.dist).Max().Value();
@@ -482,7 +464,7 @@ namespace TUGraz.VectoCore.Models.Declaration
 				var fc = avgWeighted(ModalResultField.FCMap) / distance * 1000;
 				var co2 = fc;
 
-				var loading = GetLoading(loadingType, results.Mission);
+				var loading = results.Mission.Loadings[loadingType];
 
 				pdfFields.SetField("FCkm" + loadString, fc.ToString("0.0"));
 				pdfFields.SetField("CO2km" + loadString, co2.ToString("0.0"));
@@ -539,15 +521,5 @@ namespace TUGraz.VectoCore.Models.Declaration
 
 			document.Close();
 		}
-
-
-		private static Kilogram GetLoading(LoadingType loadingType, Mission mission)
-		{
-			return loadingType == LoadingType.Full
-				? mission.MaxLoad
-				: loadingType == LoadingType.Reference
-					? mission.RefLoad
-					: mission.MinLoad;
-		}
 	}
 }
\ No newline at end of file
diff --git a/VectoCore/Models/Declaration/Mission.cs b/VectoCore/Models/Declaration/Mission.cs
index be6b86957d..9e303beb06 100644
--- a/VectoCore/Models/Declaration/Mission.cs
+++ b/VectoCore/Models/Declaration/Mission.cs
@@ -4,6 +4,22 @@ using TUGraz.VectoCore.Utils;
 
 namespace TUGraz.VectoCore.Models.Declaration
 {
+	public enum LoadingType
+	{
+		FullLoading,
+		ReferenceLoad,
+		EmptyLoading,
+	}
+
+	public static class LoadingTypeHelper
+	{
+		public static string GetShortName(this LoadingType loadingType)
+		{
+			return loadingType.ToString().Substring(0, 1);
+		}
+	}
+
+
 	public class Mission
 	{
 		public MissionType MissionType { get; set; }
@@ -17,14 +33,14 @@ namespace TUGraz.VectoCore.Models.Declaration
 		public Kilogram RefLoad { get; set; }
 		public Kilogram MaxLoad { get; set; }
 
-		public IEnumerable<LoadingEntry> Loadings
+		public Dictionary<LoadingType, Kilogram> Loadings
 		{
 			get
 			{
-				return new[] {
-					new LoadingEntry() { LoadingWeight = MinLoad, Name = "EmptyLoading" },
-					new LoadingEntry() { LoadingWeight = RefLoad, Name = "ReferenceLoad" },
-					new LoadingEntry() { LoadingWeight = MaxLoad, Name = "FullLoading" }
+				return new Dictionary<LoadingType, Kilogram> {
+					{ LoadingType.EmptyLoading, MinLoad },
+					{ LoadingType.ReferenceLoad, RefLoad },
+					{ LoadingType.FullLoading, MaxLoad }
 				};
 			}
 		}
diff --git a/VectoCore/Models/Simulation/Data/ModalDataWriter.cs b/VectoCore/Models/Simulation/Data/ModalDataWriter.cs
index d271cd8e6f..4ef22cbfa0 100644
--- a/VectoCore/Models/Simulation/Data/ModalDataWriter.cs
+++ b/VectoCore/Models/Simulation/Data/ModalDataWriter.cs
@@ -1,7 +1,7 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
 using System.Data;
 using System.Linq;
-using TUGraz.VectoCore.Models.Declaration;
 using TUGraz.VectoCore.Models.Simulation.Impl;
 using TUGraz.VectoCore.Utils;
 
@@ -10,13 +10,15 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
 	public class ModalDataWriter : IModalDataWriter
 	{
 		private readonly SimulatorFactory.FactoryMode _mode;
+		private readonly Action<ModalDataWriter> _addReportResult;
 		private ModalResults Data { get; set; }
 		private DataRow CurrentRow { get; set; }
 		private string ModFileName { get; set; }
-		private Report _report { get; set; }
 
+		public ModalDataWriter(string modFileName,
+			SimulatorFactory.FactoryMode mode = SimulatorFactory.FactoryMode.EngineeringMode) : this(modFileName, _ => {}, mode) {}
 
-		public ModalDataWriter(string modFileName, Report report,
+		public ModalDataWriter(string modFileName, Action<ModalDataWriter> addReportResult,
 			SimulatorFactory.FactoryMode mode = SimulatorFactory.FactoryMode.EngineeringMode)
 		{
 			HasTorqueConverter = false;
@@ -25,7 +27,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
 			Auxiliaries = new Dictionary<string, DataColumn>();
 			CurrentRow = Data.NewRow();
 			_mode = mode;
-			_report = report;
+			_addReportResult = addReportResult;
 		}
 
 		public bool HasTorqueConverter { get; set; }
@@ -97,6 +99,10 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
 			if (_mode != SimulatorFactory.FactoryMode.DeclarationMode) {
 				VectoCSVFile.Write(ModFileName, new DataView(Data).ToTable(false, strCols.ToArray()));
 			}
+
+			if (_mode == SimulatorFactory.FactoryMode.DeclarationMode) {
+				_addReportResult(this);
+			}
 		}
 
 
diff --git a/VectoCore/Models/Simulation/Data/VectoRunData.cs b/VectoCore/Models/Simulation/Data/VectoRunData.cs
index 062ccdf22e..6ecf013f7f 100644
--- a/VectoCore/Models/Simulation/Data/VectoRunData.cs
+++ b/VectoCore/Models/Simulation/Data/VectoRunData.cs
@@ -36,7 +36,9 @@ namespace TUGraz.VectoCore.Models.Simulation.Data
 
 		public string BasePath { get; set; }
 		public string ModFileSuffix { get; set; }
-		public Report Report { get; set; }
+		public DeclarationReport Report { get; set; }
+		public LoadingType Loading { get; set; }
+		public Mission Mission { get; set; }
 
 
 		public class AuxData
diff --git a/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs b/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs
index 867aff89ff..27a03f7f69 100644
--- a/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs
+++ b/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs
@@ -60,7 +60,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
 					data.JobFileName.Replace(Constants.FileExtensions.VectoJobFile, "") + "_{0}{1}" +
 					Constants.FileExtensions.ModDataFile);
 				IModalDataWriter modWriter =
-					new ModalDataWriter(string.Format(modFileName, data.Cycle.Name, data.ModFileSuffix ?? ""), _mode);
+					new ModalDataWriter(string.Format(modFileName, data.Cycle.Name, data.ModFileSuffix ?? ""),
+						writer => data.Report.AddResult(data.Loading, data.Mission, writer), _mode);
 				var jobName = string.Format("{0}-{1}", JobNumber, i++);
 				var sumWriterDecorator = DecorateSumWriter(data.IsEngineOnly, SumWriter, data.JobFileName, jobName, data.Cycle.Name);
 				var builder = new PowertrainBuilder(modWriter, sumWriterDecorator, DataReader.IsEngineOnly);
diff --git a/VectoCore/VectoCore.csproj b/VectoCore/VectoCore.csproj
index 6b7a4feac7..9aa3cfd82d 100644
--- a/VectoCore/VectoCore.csproj
+++ b/VectoCore/VectoCore.csproj
@@ -139,7 +139,7 @@
     <Compile Include="Models\Declaration\HVAC.cs" />
     <Compile Include="Models\Declaration\PneumaticSystem.cs" />
     <Compile Include="Models\Declaration\PT1.cs" />
-    <Compile Include="Models\Declaration\Report.cs" />
+    <Compile Include="Models\Declaration\DeclarationReport.cs" />
     <Compile Include="Models\Declaration\Rims.cs" />
     <Compile Include="Models\Declaration\Segments.cs" />
     <Compile Include="Models\Declaration\SteeringPump.cs" />
-- 
GitLab