diff --git a/VectoCoreTest/Integration/CoachPowerTrain.cs b/VectoCoreTest/Integration/CoachPowerTrain.cs index 0e99089da48c2b8e2bbc369ac489c578e78ac3d3..3faf0a538e71227b75361e29fb161ead20473f96 100644 --- a/VectoCoreTest/Integration/CoachPowerTrain.cs +++ b/VectoCoreTest/Integration/CoachPowerTrain.cs @@ -94,7 +94,9 @@ namespace TUGraz.VectoCore.Tests.Integration TractionInterruption = 1.SI<Second>(), StartSpeed = 2.SI<MeterPerSecond>(), StartAcceleration = 0.6.SI<MeterPerSquareSecond>(), - StartTorqueReserve = 0.2 + StartTorqueReserve = 0.2, + SkipGears = true, + TorqueReserve = 0.2, }; } diff --git a/VectoCoreTest/Integration/DriverStrategy/DriverStrategyTestCoach.cs b/VectoCoreTest/Integration/DriverStrategy/DriverStrategyTestCoach.cs index 317d6b0e43e7c4dbca69e38610df429d6670cde6..5b36881d0687e30764fed1467e1f13a5a356d993 100644 --- a/VectoCoreTest/Integration/DriverStrategy/DriverStrategyTestCoach.cs +++ b/VectoCoreTest/Integration/DriverStrategy/DriverStrategyTestCoach.cs @@ -14,6 +14,16 @@ namespace TUGraz.VectoCore.Tests.Integration.DriverStrategy //GraphWriter.Disable(); } + [TestMethod] + public void TestGraph() + { + var imgV3 = @"..\..\..\VectoCoreTest\bin\Debug\Coach_DriverStrategy_Drive_50_slope_dec-inc.vmod"; + var imgv22 = + @"..\..\..\VectoCoreTest\TestData\Integration\DriverStrategy\Vecto2.2\Coach\24t Coach_Cycle_Drive_50_Dec_Increasing_Slope.vmod"; + + GraphWriter.Write(imgV3, imgv22); + } + #region Accelerate [TestMethod] @@ -514,7 +524,7 @@ namespace TUGraz.VectoCore.Tests.Integration.DriverStrategy [TestMethod] public void Coach_Drive_10_downhill_5() { - var cycle = SimpleDrivingCycles.CreateCycleData(SimpleDrivingCycles.CycleDrive_10_uphill_5); + var cycle = SimpleDrivingCycles.CreateCycleData(SimpleDrivingCycles.CycleDrive_10_downhill_5); CoachPowerTrain.CreateEngineeringRun(cycle, "Coach_DriverStrategy_Drive_10_downhill_5.vmod").Run(); GraphWriter.Write("Coach_DriverStrategy_Drive_10_downhill_5.vmod", diff --git a/VectoCoreTest/Integration/SimpleDrivingCycles.cs b/VectoCoreTest/Integration/SimpleDrivingCycles.cs index bd79f8203ec4b635f03b699bc4f004952db328f1..04460f5dc3b97922af049529e4de5b5a12f922ee 100644 --- a/VectoCoreTest/Integration/SimpleDrivingCycles.cs +++ b/VectoCoreTest/Integration/SimpleDrivingCycles.cs @@ -8,13 +8,26 @@ namespace TUGraz.VectoCore.Tests.Integration [SuppressMessage("ReSharper", "InconsistentNaming")] public class SimpleDrivingCycles { + public static DrivingCycleData CreateCycleData(string[] entries) + { + var cycleData = new MemoryStream(); + var writer = new StreamWriter(cycleData); + writer.WriteLine("<s>,<v>,<grad>,<stop>"); + foreach (var entry in entries) { + writer.WriteLine(entry); + } + writer.Flush(); + cycleData.Seek(0, SeekOrigin.Begin); + return DrivingCycleDataReader.ReadFromStream(cycleData, CycleType.DistanceBased); + } + #region Accelerate public static readonly string[] CycleAccelerate_20_60_Level = { // <s>,<v>,<grad>,<stop> " 0, 20, 0, 0", " 100, 60, 0, 0", - "1000, 60, 0, 0", + "1000, 60, 0, 0" }; @@ -22,167 +35,168 @@ namespace TUGraz.VectoCore.Tests.Integration // <s>,<v>,<grad>,<stop> " 0, 20, 5, 0", " 100, 60, 5, 0", - "1000, 60, 5, 0", + "1000, 60, 5, 0" }; public static readonly string[] CycleAccelerate_20_60_downhill_5 = { // <s>,<v>,<grad>,<stop> " 0, 20, -5, 0", " 100, 60, -5, 0", - "1000, 60, -5, 0", + "1000, 60, -5, 0" }; public static readonly string[] CycleAccelerate_20_60_uphill_25 = { // <s>,<v>,<grad>,<stop> " 0, 20, 25, 0", " 100, 60, 25, 0", - "1000, 60, 25, 0", + "1000, 60, 25, 0" }; public static readonly string[] CycleAccelerate_20_60_downhill_25 = { // <s>,<v>,<grad>,<stop> " 0, 20, -25, 0", " 100, 60, -25, 0", - "1000, 60, -25, 0", + "1000, 60, -25, 0" }; + public static readonly string[] CycleAccelerate_20_60_uphill_15 = { // <s>,<v>,<grad>,<stop> " 0, 20, 15, 0", " 100, 60, 15, 0", - "1000, 60, 15, 0", + "1000, 60, 15, 0" }; public static readonly string[] CycleAccelerate_20_60_downhill_15 = { // <s>,<v>,<grad>,<stop> " 0, 20, -15, 0", " 100, 60, -15, 0", - "1000, 60, -15, 0", + "1000, 60, -15, 0" }; public static readonly string[] CycleAccelerate_0_85_level = { // <s>,<v>,<grad>,<stop> " 0, 0, 0, 2", - "1000, 85, 0, 0", + "1000, 85, 0, 0" }; public static readonly string[] CycleAccelerate_0_85_uphill_1 = { // <s>,<v>,<grad>,<stop> " 0, 0, 1, 2", - "1000, 85, 1, 0", + "1000, 85, 1, 0" }; public static readonly string[] CycleAccelerate_0_85_uphill_2 = { // <s>,<v>,<grad>,<stop> " 0, 0, 2, 2", - "1000, 85, 2, 0", + "1000, 85, 2, 0" }; public static readonly string[] CycleAccelerate_0_85_uphill_5 = { // <s>,<v>,<grad>,<stop> " 0, 0, 5, 2", - "1000, 85, 5, 0", + "1000, 85, 5, 0" }; public static readonly string[] CycleAccelerate_0_85_downhill_5 = { // <s>,<v>,<grad>,<stop> " 0, 0, 0, 2", " 0, 85, -5, 0", - "1000, 85, -5, 0", + "1000, 85, -5, 0" }; public static readonly string[] CycleAccelerate_0_85_downhill_3 = { // <s>,<v>,<grad>,<stop> " 0, 0, 0, 2", " 0, 85, -3, 0", - "1000, 85, -3, 0", + "1000, 85, -3, 0" }; public static readonly string[] CycleAccelerate_0_85_downhill_1 = { // <s>,<v>,<grad>,<stop> " 0, 0, 0, 2", " 0, 85, -1, 0", - "1000, 85, -1, 0", + "1000, 85, -1, 0" }; public static readonly string[] CycleAccelerate_0_60_downhill_5 = { // <s>,<v>,<grad>,<stop> " 0, 0, 0, 2", " 0, 60, -5, 0", - "1000, 60, -5, 0", + "1000, 60, -5, 0" }; public static readonly string[] CycleAccelerate_0_60_downhill_3 = { // <s>,<v>,<grad>,<stop> " 0, 0, 0, 2", " 0, 60, -3, 0", - "1000, 60, -3, 0", + "1000, 60, -3, 0" }; public static readonly string[] CycleAccelerate_0_60_downhill_1 = { // <s>,<v>,<grad>,<stop> " 0, 0, 0, 2", " 0, 60, -1, 0", - "1000, 60, -1, 0", + "1000, 60, -1, 0" }; public static readonly string[] CycleAccelerate_0_40_downhill_5 = { // <s>,<v>,<grad>,<stop> " 0, 0, 0, 2", " 0, 40, -5, 0", - "1000, 40, -5, 0", + "1000, 40, -5, 0" }; public static readonly string[] CycleAccelerate_0_40_downhill_3 = { // <s>,<v>,<grad>,<stop> " 0, 0, 0, 2", " 0, 40, -3, 0", - "1000, 40, -3, 0", + "1000, 40, -3, 0" }; public static readonly string[] CycleAccelerate_0_40_downhill_1 = { // <s>,<v>,<grad>,<stop> " 0, 0, 0, 2", " 0, 40, -1, 0", - "1000, 40, -1, 0", + "1000, 40, -1, 0" }; public static readonly string[] CycleAccelerate_0_85_uphill_25 = { // <s>,<v>,<grad>,<stop> " 0, 0, 0, 2", " 0, 85, 25, 0", - "1000, 85, 25, 0", + "1000, 85, 25, 0" }; public static readonly string[] CycleAccelerate_0_85_downhill_25 = { // <s>,<v>,<grad>,<stop> " 0, 0, -25, 2", - "1000, 85, -25, 0", + "1000, 85, -25, 0" }; public static readonly string[] CycleAccelerate_0_85_uphill_10 = { // <s>,<v>,<grad>,<stop> " 0, 0, 10, 2", - "1000, 85, 10, 0", + "1000, 85, 10, 0" }; public static readonly string[] CycleAccelerate_0_85_downhill_15 = { // <s>,<v>,<grad>,<stop> " 0, 0, -15, 2", - "1000, 85, -15, 0", + "1000, 85, -15, 0" }; public static readonly string[] CycleAccelerate_stop_0_85_level = { // <s>,<v>,<grad>,<stop> " 0, 0, 0, 2", - "1000, 85, 0, 0", + "1000, 85, 0, 0" }; public static readonly string[] CycleAccelerate_20_22_uphill_5 = { // <s>,<v>,<grad>,<stop> " 0, 20, 5, 0", " 100, 22, 5, 0", - " 200, 22, 5, 0", + " 200, 22, 5, 0" }; #endregion @@ -193,32 +207,32 @@ namespace TUGraz.VectoCore.Tests.Integration // <s>,<v>,<grad>,<stop> " 0, 22, -5, 0", " 100, 20, -5, 0", - " 300, 20, -5, 0", + " 300, 20, -5, 0" }; public static readonly string[] CycleDecelerate_60_20_level = { // <s>,<v>,<grad>,<stop> " 0, 60, 0, 0", "1000, 20, 0, 0", - "1100, 20, 0, 0", + "1100, 20, 0, 0" }; public static readonly string[] CycleDecelerate_45_0_level = { // <s>,<v>,<grad>,<stop> " 0, 45, 0, 0", - " 200, 0, 0, 2", + " 200, 0, 0, 2" }; public static readonly string[] CycleDecelerate_45_0_uphill_5 = { // <s>,<v>,<grad>,<stop> " 0, 45, 5, 0", - " 200, 0, 5, 2", + " 200, 0, 5, 2" }; public static readonly string[] CycleDecelerate_45_0_downhill_5 = { // <s>,<v>,<grad>,<stop> " 0, 45, -5, 0", - " 200, 0, -5, 2", + " 200, 0, -5, 2" }; public static readonly string[] CycleDecelerate_60_20_uphill_5 = { @@ -232,20 +246,20 @@ namespace TUGraz.VectoCore.Tests.Integration // <s>,<v>,<grad>,<stop> " 0, 60, -5, 0", "1000, 20, -5, 0", - "1100, 20, -5, 0", + "1100, 20, -5, 0" }; public static readonly string[] CycleDecelerate_60_20_uphill_25 = { // <s>,<v>,<grad>,<stop> " 0, 60, 25, 0", - "1000, 20, 25, 0", + "1000, 20, 25, 0" }; public static readonly string[] CycleDecelerate_60_20_downhill_25 = { // <s>,<v>,<grad>,<stop> " 0, 60, -25, 0", "1000, 20, -25, 0", - "1100, 20, -25, 0", + "1100, 20, -25, 0" }; public static readonly string[] CycleDecelerate_60_20_uphill_15 = { @@ -259,58 +273,58 @@ namespace TUGraz.VectoCore.Tests.Integration // <s>,<v>,<grad>,<stop> " 0, 60, -15, 0", " 800, 20, -15, 0", - "1000, 20, -15, 0", + "1000, 20, -15, 0" }; public static readonly string[] CycleDecelerate_80_0_level = { // <s>,<v>,<grad>,<stop> " 0, 80, 0, 0", - "1000, 0, 0, 2", + "1000, 0, 0, 2" // "1000, 0, 5, 2", }; public static readonly string[] CycleDecelerate_80_0_uphill_3 = { // <s>,<v>,<grad>,<stop> " 0, 80, 3, 0", - "1000, 0, 3, 2", + "1000, 0, 3, 2" // "1000, 0, 5, 2", }; public static readonly string[] CycleDecelerate_80_0_uphill_5 = { // <s>,<v>,<grad>,<stop> " 0, 80, 5, 0", - "1000, 0, 5, 2", + "1000, 0, 5, 2" // "1000, 0, 5, 2", }; public static readonly string[] CycleDecelerate_80_0_downhill_5 = { // <s>,<v>,<grad>,<stop> " 0, 80, -5, 0", - " 500, 0, -5, 2", + " 500, 0, -5, 2" }; public static readonly string[] CycleDecelerate_80_0_uphill_25 = { // <s>,<v>,<grad>,<stop> " 0, 80, 25, 0", - "1000, 0, 25, 2", + "1000, 0, 25, 2" }; public static readonly string[] CycleDecelerate_80_0_downhill_25 = { // <s>,<v>,<grad>,<stop> " 0, 80, -25, 0", - "1000, 0, -25, 2", + "1000, 0, -25, 2" }; public static readonly string[] CycleDecelerate_80_0_uphill_15 = { // <s>,<v>,<grad>,<stop> " 0, 80, 15, 0", - "1000, 0, 15, 0", + "1000, 0, 15, 0" }; public static readonly string[] CycleDecelerate_80_0_downhill_15 = { // <s>,<v>,<grad>,<stop> " 0, 80, -15, 0", - "1000, 0, -15, 2", + "1000, 0, -15, 2" }; #endregion @@ -320,98 +334,98 @@ namespace TUGraz.VectoCore.Tests.Integration public static readonly string[] CycleDrive_80_level = { // <s>,<v>,<grad>,<stop> " 0, 80, 0, 0", - "1000, 80, 0, 0", + "1000, 80, 0, 0" }; public static readonly string[] CycleDrive_80_uphill_5 = { // <s>,<v>,<grad>,<stop> " 0, 80, 5, 0", - "1000, 80, 5, 0", + "1000, 80, 5, 0" }; public static readonly string[] CycleDrive_80_downhill_5 = { // <s>,<v>,<grad>,<stop> " 0, 80, -5, 0", - " 1000, 80, -5, 0", + " 1000, 80, -5, 0" }; public static readonly string[] CycleDrive_20_downhill_15 = { // <s>, <v>, <grad>, <stop> " 0, 20, -15, 0", - " 500, 20, -25, 0", + " 500, 20, -25, 0" }; public static readonly string[] CycleDrive_30_downhill_15 = { // <s>, <v>, <grad>, <stop> " 0, 30, -15, 0", - " 500, 30, -15, 0", + " 500, 30, -15, 0" }; public static readonly string[] CycleDrive_50_downhill_15 = { // <s>, <v>, <grad>, <stop> " 0, 50, -15, 0", - " 500, 50, -15, 0", + " 500, 50, -15, 0" }; public static readonly string[] CycleDrive_80_uphill_25 = { // <s>,<v>,<grad>,<stop> " 0, 80, 25, 0", - " 500, 80, 25, 0", + " 500, 80, 25, 0" }; public static readonly string[] CycleDrive_80_downhill_15 = { // <s>, <v>, <grad>, <stop> " 0, 80, -15, 0", - " 500, 80, -15, 0", + " 500, 80, -15, 0" }; public static readonly string[] CycleDrive_80_uphill_15 = { // <s>,<v>,<grad>,<stop> " 0, 80, 15, 0", - " 500, 80, 15, 0", + " 500, 80, 15, 0" }; public static readonly string[] CycleDrive_10_level = { // <s>,<v>,<grad>,<stop> " 0, 10, 0, 0", - "200, 10, 0, 0", + "200, 10, 0, 0" }; public static readonly string[] CycleDrive_10_uphill_5 = { // <s>,<v>,<grad>,<stop> " 0, 10, 5, 0", - "200, 10, 5, 0", + "200, 10, 5, 0" }; public static readonly string[] CycleDrive_10_downhill_5 = { // <s>,<v>,<grad>,<stop> " 0, 10, -5, 0", - " 200, 10, -5, 0", + " 200, 10, -5, 0" }; public static readonly string[] CycleDrive_10_downhill_25 = { // <s>, <v>, <grad>, <stop> " 0, 10, -25, 0", - " 200, 10, -25, 0", + " 200, 10, -25, 0" }; public static readonly string[] CycleDrive_10_uphill_25 = { // <s>,<v>,<grad>,<stop> " 0, 10, 25, 0", - " 200, 10, 25, 0", + " 200, 10, 25, 0" }; public static readonly string[] CycleDrive_10_downhill_15 = { // <s>, <v>, <grad>, <stop> " 0, 10, -15, 0", - " 200, 10, -15, 0", + " 200, 10, -15, 0" }; public static readonly string[] CycleDrive_10_uphill_15 = { // <s>,<v>,<grad>,<stop> " 0, 10, 15, 0", - " 200, 10, 15, 0", + " 200, 10, 15, 0" }; #endregion @@ -431,7 +445,7 @@ namespace TUGraz.VectoCore.Tests.Integration " 800, 80, 2, 0", " 900, 80, 2.25, 0", "1000, 80, 2.5, 0", - "1100, 80, 0, 0", + "1100, 80, 0, 0" }; public static readonly string[] CycleDrive_50_Increasing_Slope = { @@ -447,7 +461,7 @@ namespace TUGraz.VectoCore.Tests.Integration " 800, 50, 2, 0", " 900, 50, 2.25, 0", "1000, 50, 2.5, 0", - "1100, 50, 0, 0", + "1100, 50, 0, 0" }; public static readonly string[] CycleDrive_30_Increasing_Slope = { @@ -463,7 +477,7 @@ namespace TUGraz.VectoCore.Tests.Integration " 800, 30, 2, 0", " 900, 30, 2.25, 0", "1000, 30, 2.5, 0", - "1100, 30, 0, 0", + "1100, 30, 0, 0" }; public static readonly string[] CycleDrive_80_Decreasing_Slope = { @@ -479,7 +493,7 @@ namespace TUGraz.VectoCore.Tests.Integration " 800, 80, -2, 0", " 900, 80, -2.25, 0", "1000, 80, -2.5, 0", - "1100, 80, 0, 0", + "1100, 80, 0, 0" }; public static readonly string[] CycleDrive_50_Decreasing_Slope = { @@ -495,7 +509,7 @@ namespace TUGraz.VectoCore.Tests.Integration " 800, 50, -2, 0", " 900, 50, -2.25, 0", "1000, 50, -2.5, 0", - "1100, 50, 0, 0", + "1100, 50, 0, 0" }; public static readonly string[] CycleDrive_30_Decreasing_Slope = { @@ -511,7 +525,7 @@ namespace TUGraz.VectoCore.Tests.Integration " 800, 30, -2, 0", " 900, 30, -2.25, 0", "1000, 30, -2.5, 0", - "1100, 30, 0, 0", + "1100, 30, 0, 0" }; public static readonly string[] CycleDrive_80_Dec_Increasing_Slope = { @@ -539,7 +553,7 @@ namespace TUGraz.VectoCore.Tests.Integration "2000, 80, 2, 0", "2100, 80, 2.25, 0", "2200, 80, 2.5, 0", - "2300, 80, 0, 0", + "2300, 80, 0, 0" }; public static readonly string[] CycleDrive_50_Dec_Increasing_Slope = { @@ -568,7 +582,7 @@ namespace TUGraz.VectoCore.Tests.Integration "1050, 50, 2.25, 0", "1100, 50, 2.5, 0", "1150, 50, 5, 0", - "1200, 50, 0, 0", + "1200, 50, 0, 0" }; public static readonly string[] CycleDrive_30_Dec_Increasing_Slope = { @@ -596,14 +610,14 @@ namespace TUGraz.VectoCore.Tests.Integration "1000, 30, 2, 0", "1050, 30, 2.25, 0", "1100, 30, 2.5, 0", - "1150, 30, 0, 0", + "1150, 30, 0, 0" }; public static readonly string[] CycleDecelerateWhileBrake_80_0_level = { // <s>,<v>,<grad>,<stop> " 0, 80, 0, 0", " 990, 65, 0, 0", - "1000, 0, 0, 2", + "1000, 0, 0, 2" }; public static readonly string[] CycleAccelerateWhileBrake_80_0_level = { @@ -611,7 +625,7 @@ namespace TUGraz.VectoCore.Tests.Integration " 0, 80, 0, 0", " 800, 90, 0, 0", " 950, 80, 0, 0", - "1000, 0, 0, 2", + "1000, 0, 0, 2" }; public static readonly string[] CycleAccelerateAtBrake_80_0_level = { @@ -619,7 +633,7 @@ namespace TUGraz.VectoCore.Tests.Integration " 0, 80, 0, 0", " 505, 90, 0, 0", " 650, 80, 0, 0", - "1000, 0, 0, 2", + "1000, 0, 0, 2" }; public static readonly string[] CycleAccelerateBeforeBrake_80_0_level = { @@ -627,7 +641,7 @@ namespace TUGraz.VectoCore.Tests.Integration " 0, 80, 0, 0", " 450, 90, 0, 0", " 650, 80, 0, 0", - "1000, 0, 0, 2", + "1000, 0, 0, 2" }; public static readonly string[] CycleDrive_stop_85_stop_85_level = { @@ -635,22 +649,9 @@ namespace TUGraz.VectoCore.Tests.Integration " 0, 0, 0, 2", "1000, 85, 0, 0", "2000, 0, 0, 2", - "3000, 85, 0, 0", + "3000, 85, 0, 0" }; #endregion - - public static DrivingCycleData CreateCycleData(string[] entries) - { - var cycleData = new MemoryStream(); - var writer = new StreamWriter(cycleData); - writer.WriteLine("<s>,<v>,<grad>,<stop>"); - foreach (var entry in entries) { - writer.WriteLine(entry); - } - writer.Flush(); - cycleData.Seek(0, SeekOrigin.Begin); - return DrivingCycleDataReader.ReadFromStream(cycleData, CycleType.DistanceBased); - } } } \ No newline at end of file diff --git a/VectoCoreTest/Utils/GraphWriter.cs b/VectoCoreTest/Utils/GraphWriter.cs index 3c5f169ceb96a3e48df6ac0fe127fdf0405bdef2..a5daa407f5be3efd8a543fccb0014af32df54bfe 100644 --- a/VectoCoreTest/Utils/GraphWriter.cs +++ b/VectoCoreTest/Utils/GraphWriter.cs @@ -7,10 +7,14 @@ using System.Drawing; using System.Drawing.Text; using System.Linq; using System.Net; +using System.Security.Cryptography.X509Certificates; using System.Text.RegularExpressions; +using System.Windows.Forms.DataVisualization.Charting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using NLog; using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Utils; +using Point = System.Drawing.Point; namespace TUGraz.VectoCore.Tests.Utils { @@ -18,6 +22,8 @@ namespace TUGraz.VectoCore.Tests.Utils { private static bool _enabled = true; + private static Size diagramSize = new Size(2000, 440); + public static void Enabled() { _enabled = true; @@ -28,60 +34,6 @@ namespace TUGraz.VectoCore.Tests.Utils _enabled = false; } - - public static void Write(string fileName) - { - if (!_enabled) { - return; - } - - var modDataV3 = VectoCSVFile.Read(fileName); - - var xfields = new[] { ModalResultField.time, ModalResultField.dist }; - - var yfields = new[] { - ModalResultField.v_act, ModalResultField.acc, ModalResultField.n, ModalResultField.Gear, ModalResultField.Pe_eng, - ModalResultField.Tq_eng, ModalResultField.FCMap - }; - - var images = new List<Stream>(); - try { - foreach (var xfield in xfields) { - var x = modDataV3.Rows.Cast<DataRow>().Select(v => v.Field<string>(xfield.GetName())).ToArray(); - - for (var i = 1; i <= yfields.Length; i++) { - var yfield = yfields[i - 1]; - var y = modDataV3.Rows.Cast<DataRow>().Select(v => v.Field<string>(yfield.GetName())).ToArray(); - - var values = string.Format("{0}|{1}", string.Join(",", x), string.Join(",", y)); - - if (yfield == ModalResultField.v_act) { - var y3 = - modDataV3.Rows.Cast<DataRow>() - .Select(v => v.Field<string>(ModalResultField.v_targ.GetName())) - .Select(v => string.IsNullOrWhiteSpace(v) ? "0" : v); - - values += string.Format("|{0}|{1}|0|0", string.Join(",", x), string.Join(",", y3)); - } - - values = values.Replace("NaN", "0"); - if (values.Length > 14000) { - // remove all decimal places to reduce request size - values = Regex.Replace(values, @"\..*?,", ","); - } - var maxX = (int)Math.Ceiling(x.ToDouble().Max()); - images.Add(CreateGraphStream(xfield.GetCaption(), yfield.GetCaption(), maxX, values)); - } - var outfileName = string.Format("{0}_{1}.png", Path.GetFileNameWithoutExtension(fileName), xfield.GetName()); - SaveImages(outfileName, images.ToArray()); - images.Clear(); - } - } finally { - images.ForEach(x => x.Close()); - } - } - - public static void Write(string fileNameV3, string fileNameV22) { if (!_enabled) { @@ -91,7 +43,7 @@ namespace TUGraz.VectoCore.Tests.Utils var modDataV3 = VectoCSVFile.Read(fileNameV3); if (!File.Exists(fileNameV22)) { LogManager.GetCurrentClassLogger().Error("Modfile V2.2 not found: " + fileNameV22); - Write(fileNameV3); + //Write(fileNameV3); return; } var modDataV22 = VectoCSVFile.Read(fileNameV22); @@ -100,115 +52,212 @@ namespace TUGraz.VectoCore.Tests.Utils var yfields = new[] { ModalResultField.v_act, ModalResultField.acc, ModalResultField.n, ModalResultField.Gear, ModalResultField.Pe_eng, - ModalResultField.Tq_eng, - ModalResultField.FCMap + ModalResultField.Tq_eng, ModalResultField.FCMap }; - var images = new List<Stream>(); - try { - foreach (var xfield in xfields) { - var x = modDataV3.Rows.Cast<DataRow>().Select(v => v.Field<string>(xfield.GetName())).ToArray(); - var x2 = modDataV22.Rows.Cast<DataRow>().Select(v => v.Field<string>(xfield.GetName())).ToArray(); - - for (var i = 1; i <= yfields.Length; i++) { - var yfield = yfields[i - 1]; - var y = - modDataV3.Rows.Cast<DataRow>() - .Select(v => v.Field<string>(yfield.GetName())) - .Select(v => v == "-1" ? "-1.00001" : v) - .ToArray(); - //y = y.ToArray(); - var y2 = - modDataV22.Rows.Cast<DataRow>() - .Select(v => v.Field<string>(yfield.GetName())) - .Select(v => v == "-1" ? "-1.00001" : v) - .ToArray(); - - var values = string.Format("{0}|{1}|{2}|{3}", string.Join(",", x), string.Join(",", y), string.Join(",", x2), - string.Join(",", y2)); - - if (yfield == ModalResultField.v_act) { - var y3 = - modDataV3.Rows.Cast<DataRow>() - .Select(v => v.Field<string>(ModalResultField.v_targ.GetName())) - .Select(v => string.IsNullOrWhiteSpace(v) ? "0" : v); - - values += string.Format("|{0}|{1}", string.Join(",", x), string.Join(",", y3)); - } - - values = values.Replace("NaN", "_"); - //values = values.Replace("-1", "-1.00001"); - if (values.Length > 14000) { - // remove all decimal places to reduce request size - values = Regex.Replace(values, @"(\.[0-9]).*?,", "$1,"); - } - var maxX = (int)Math.Ceiling(Math.Max(x.ToDouble().Max(), x2.ToDouble().Max())); - images.Add(CreateGraphStream(xfield.GetCaption(), yfield.GetCaption(), maxX, values)); + var titleHeight = (50 * 100.0f) / (diagramSize.Height * yfields.Count()); + + foreach (var xfield in xfields) { + var fileName = string.Format("{0}_{1}.png", Path.GetFileNameWithoutExtension(fileNameV3), xfield.GetName()); + + var x = modDataV3.Rows.Cast<DataRow>().Select(v => v.Field<string>(xfield.GetName()).ToDouble()).ToArray(); + var x2 = modDataV22.Rows.Cast<DataRow>().Select(v => v.Field<string>(xfield.GetName()).ToDouble()).ToArray(); + + var plotSize = new Size(diagramSize.Width, diagramSize.Height * yfields.Count()); + var maxX = (int)(Math.Ceiling(Math.Max(x.Max(), x2.Max()) * 1.01 / 10.0) * 10.0); + var minX = (int)(Math.Floor(Math.Max(x.Min(), x2.Min()) / 10.0) * 10.0); + var chart = new Chart { Size = plotSize }; + + + for (var i = 0; i < yfields.Length; i++) { + var yfield = yfields[i]; + var y = + modDataV3.Rows.Cast<DataRow>() + .Select( + v => v.Field<string>(yfield.GetName()).Length == 0 ? Double.NaN : v.Field<string>(yfield.GetName()).ToDouble()) + .ToArray(); + var y2 = + modDataV22.Rows.Cast<DataRow>() + .Select( + v => + v.Field<string>(yfield.GetName()).Length == 0 ? Double.NaN : v.Field<string>(yfield.GetName()).ToDouble()) + .ToArray(); + + + var chartArea = new ChartArea { Name = yfield.ToString() }; + chartArea.AxisX.MajorGrid.LineColor = Color.DarkGray; + chartArea.AxisY.MajorGrid.LineColor = Color.DarkGray; + chartArea.AxisX.LabelStyle.Font = new Font("Consolas", 10); + chartArea.AxisY.LabelStyle.Font = new Font("Consolas", 10); + + chartArea.AxisX.Interval = maxX / 20.0; + chartArea.AxisX.Maximum = maxX; + chartArea.AxisX.Minimum = minX; + chartArea.AxisX.MinorGrid.Enabled = true; + chartArea.AxisX.MinorGrid.Interval = maxX / 100.0; + chartArea.AxisX.MinorGrid.LineColor = Color.LightGray; + chartArea.AxisX.Title = xfield.GetCaption(); + chartArea.AxisX.TitleFont = new Font("Verdana", 12); + chartArea.AxisX.RoundAxisValues(); + chartArea.AxisX.MajorTickMark.Size = 2 * 100.0f / diagramSize.Height; + + chartArea.AxisY.Title = yfield.GetCaption(); + chartArea.AxisY.TitleFont = new Font("Verdana", 12); + chartArea.AxisY.RoundAxisValues(); + if (yfield == ModalResultField.Gear) { + chartArea.AxisY.MajorGrid.Interval = 1; + chartArea.AxisY.MinorGrid.Enabled = false; + } else { + chartArea.AxisY.MinorGrid.Enabled = true; + } + chartArea.AxisY.MinorGrid.LineColor = Color.LightGray; + chartArea.AxisY.MajorTickMark.Size = 5 * 100.0f / diagramSize.Width; + + chart.ChartAreas.Add(chartArea); + + var legend = new Legend(yfield.ToString()) { + Docking = Docking.Right, + IsDockedInsideChartArea = false, + DockedToChartArea = yfield.ToString(), + Font = new Font("Verdana", 14), + + }; + chart.Legends.Add(legend); + + if (yfield == ModalResultField.v_act) { + var y3 = modDataV3.Rows.Cast<DataRow>() + .Select( + v => + v.Field<string>(ModalResultField.v_targ.GetName()).Length == 0 + ? Double.NaN + : v.Field<string>(ModalResultField.v_targ.GetName()).ToDouble()) + .ToArray(); + + var series3 = new Series { + Name = "v_target", + ChartType = SeriesChartType.FastLine, + Color = Color.Green, + BorderWidth = 3, + Legend = legend.Name, + IsVisibleInLegend = true + }; + chart.Series.Add(series3); + chart.Series[series3.Name].Points.DataBindXY(x, y3); + series3.ChartArea = chartArea.Name; } - var fileName = string.Format("{0}_{1}.png", Path.GetFileNameWithoutExtension(fileNameV3), xfield.GetName()); - SaveImages(fileName, images.ToArray()); - images.Clear(); - } - } finally { - images.ForEach(x => x.Close()); - } - } - - private static Stream CreateGraphStream(string xLabel, string yLabel, int xAxisRange, string values) - { - // see https://developers.google.com/chart/image/?hl=en for details - using (var client = new WebClient()) { - var response = client.UploadValues("https://chart.googleapis.com/chart", new NameValueCollection { - { "cht", "lxy" }, - { "chd", "t:" + values }, - { "chs", "1000x230" }, - { "chxt", "x,x,y,y" }, - { "chds", "a" }, - { "chxr", string.Format("0,0,{0},{1}", xAxisRange, xAxisRange / 10) }, - { "chco", "0000FF,FF0000,00FF00" }, - { "chg", "5,10" }, - { "chxl", string.Format("1:|{0}|3:|{1}", xLabel, yLabel) }, - { "chxp", "1,0|3,0" }, - { "chdl", "V3|V2.2" }, - }); - - return new MemoryStream(response); - } - } - public static void SaveImages(string outputFile, params Stream[] inputFiles) - { - var titleHeight = 36; - var images = new List<Image>(); - Bitmap output = null; - Graphics g = null; - - try { - images = inputFiles.Select(Image.FromStream).ToList(); - output = new Bitmap(images.Max(x => x.Width), images.Sum(x => x.Height) + titleHeight); - g = Graphics.FromImage(output); - g.TextRenderingHint = TextRenderingHint.AntiAlias; - - g.DrawString(outputFile, new Font("Arial", 16), Brushes.Black, output.Width / 2, 10, - new StringFormat { Alignment = StringAlignment.Center }); - - var ypos = titleHeight; - foreach (var image in images) { - g.DrawImage(image, new System.Drawing.Point(0, ypos)); - ypos += image.Height; - image.Dispose(); - } - output.Save(outputFile); - } finally { - images.ForEach(x => x.Dispose()); - if (output != null) { - output.Dispose(); + var series1 = new Series { + Name = String.Format("Vecto 3 - {0}", yfield), + ChartType = SeriesChartType.Line, + Color = Color.Blue, + BorderWidth = 2, + Legend = legend.Name, + IsVisibleInLegend = true, + //MarkerColor = Color.Blue, + //MarkerSize = 4, + //MarkerStyle = MarkerStyle.Circle, + //MarkerBorderColor = Color.White, + //MarkerBorderWidth = 1, + }; + series1.ChartArea = chartArea.Name; + + chart.Series.Add(series1); + chart.Series[series1.Name].Points.DataBindXY(x, y); + + var series2 = new Series { + Name = String.Format("Vecto 2.2 - {0}", yfield), + ChartType = SeriesChartType.Line, + Color = Color.Red, + BorderWidth = 2, + Legend = legend.Name, + IsVisibleInLegend = true, + //MarkerColor = Color.Red, + //MarkerSize = 4, + //MarkerStyle = MarkerStyle.Circle, + //MarkerBorderColor = Color.White, + //MarkerBorderWidth = 1, + }; + series2.ChartArea = chartArea.Name; + + chart.Series.Add(series2); + chart.Series[series2.Name].Points.DataBindXY(x2, y2); + + + chartArea.Position.Auto = false; + chartArea.Position.Width = 85; + chartArea.Position.Height = (100.0f - titleHeight) / yfields.Count(); + chartArea.Position.X = 0; + chartArea.Position.Y = (i * (100.0f - titleHeight)) / yfields.Count() + titleHeight; + + if (i > 0) { + chart.ChartAreas[yfield.ToString()].AlignWithChartArea = yfields[0].ToString(); + chart.ChartAreas[yfield.ToString()].AlignmentOrientation = AreaAlignmentOrientations.Vertical; + chart.ChartAreas[yfield.ToString()].AlignmentStyle = AreaAlignmentStyles.All; + } } - if (g != null) { - g.Dispose(); - } + var title = new Title(); + title.Text = Path.GetFileNameWithoutExtension(fileName); + title.DockedToChartArea = yfields[0].ToString(); + title.IsDockedInsideChartArea = false; + title.Font = new Font("Verdana", 18, FontStyle.Bold); + chart.Titles.Add(title); + + chart.Invalidate(); + chart.SaveImage(fileName, ChartImageFormat.Png); } } + + //public static void Write(string fileName) + //{ + // if (!_enabled) { + // return; + // } + + // var modDataV3 = VectoCSVFile.Read(fileName); + + // var xfields = new[] { ModalResultField.time, ModalResultField.dist }; + + // var yfields = new[] { + // ModalResultField.v_act, ModalResultField.acc, ModalResultField.n, ModalResultField.Gear, ModalResultField.Pe_eng, + // ModalResultField.Tq_eng, ModalResultField.FCMap + // }; + + // var images = new List<Stream>(); + // try { + // foreach (var xfield in xfields) { + // var x = modDataV3.Rows.Cast<DataRow>().Select(v => v.Field<string>(xfield.GetName())).ToArray(); + + // for (var i = 1; i <= yfields.Length; i++) { + // var yfield = yfields[i - 1]; + // var y = modDataV3.Rows.Cast<DataRow>().Select(v => v.Field<string>(yfield.GetName())).ToArray(); + + // var values = string.Format("{0}|{1}", string.Join(",", x), string.Join(",", y)); + + // if (yfield == ModalResultField.v_act) { + // var y3 = + // modDataV3.Rows.Cast<DataRow>() + // .Select(v => v.Field<string>(ModalResultField.v_targ.GetName())) + // .Select(v => string.IsNullOrWhiteSpace(v) ? "0" : v); + + // values += string.Format("|{0}|{1}|0|0", string.Join(",", x), string.Join(",", y3)); + // } + + // values = values.Replace("NaN", "0"); + // if (values.Length > 14000) { + // // remove all decimal places to reduce request size + // values = Regex.Replace(values, @"\..*?,", ","); + // } + // var maxX = (int)Math.Ceiling(x.ToDouble().Max()); + // images.Add(CreateGraphStream(xfield.GetCaption(), yfield.GetCaption(), maxX, values)); + // } + // var outfileName = string.Format("{0}_{1}.png", Path.GetFileNameWithoutExtension(fileName), xfield.GetName()); + // SaveImages(outfileName, images.ToArray()); + // images.Clear(); + // } + // } finally { + // images.ForEach(x => x.Close()); + // } + //} } } \ No newline at end of file diff --git a/VectoCoreTest/VectoCoreTest.csproj b/VectoCoreTest/VectoCoreTest.csproj index 208bf34b4479fa2b92193c4f9bf2e05b87f2c541..06233e388145a450c31dbc69dd6352410a0f0171 100644 --- a/VectoCoreTest/VectoCoreTest.csproj +++ b/VectoCoreTest/VectoCoreTest.csproj @@ -44,6 +44,8 @@ <Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Design" /> <Reference Include="System.Drawing" /> + <Reference Include="System.Windows.Forms" /> + <Reference Include="System.Windows.Forms.DataVisualization" /> <Reference Include="System.Xml" /> </ItemGroup> <Choose>