diff --git a/VectoCoreTest/Integration/DriverStrategy/DriverStrategyTestTruck.cs b/VectoCoreTest/Integration/DriverStrategy/DriverStrategyTestTruck.cs index 080f29443d3b8e1f9f4a7718876a7cf86788a743..ec63359c55bda8ba1854b4790ccfdca953774f0f 100644 --- a/VectoCoreTest/Integration/DriverStrategy/DriverStrategyTestTruck.cs +++ b/VectoCoreTest/Integration/DriverStrategy/DriverStrategyTestTruck.cs @@ -1,8 +1,5 @@ -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using NLog; -using TUGraz.VectoCore.FileIO.Reader; -using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Tests.Utils; namespace TUGraz.VectoCore.Tests.Integration.DriverStrategy @@ -74,6 +71,9 @@ namespace TUGraz.VectoCore.Tests.Integration.DriverStrategy { var cycle = SimpleDrivingCycles.CreateCycleData(SimpleDrivingCycles.CycleAccelerate_0_85_level); Truck40tPowerTrain.CreateEngineeringRun(cycle, "Truck_DriverStrategy_Accelerate_0_85_level.vmod").Run(); + + GraphWriter.Write("Truck_DriverStrategy_Accelerate_0_85_level.vmod", + @"..\..\TestData\Integration\DriverStrategy\Vecto2.2\40t Truck\40t_Long_Haul_Truck_Cycle_Accelerate_0_85_level.vmod"); } [TestMethod] diff --git a/VectoCoreTest/Utils/GraphWriter.cs b/VectoCoreTest/Utils/GraphWriter.cs new file mode 100644 index 0000000000000000000000000000000000000000..a8d8c4ad0113512e3cf1590b2093277cf8e177ea --- /dev/null +++ b/VectoCoreTest/Utils/GraphWriter.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Specialized; +using System.Data; +using System.IO; +using System.Linq; +using System.Net; +using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.Utils; + +namespace TUGraz.VectoCore.Tests.Utils +{ + public static class GraphWriter + { + public static void Write(string fileNameV3, string fileNameV22) + { + var modDataV3 = VectoCSVFile.Read(fileNameV3); + var modDataV22 = VectoCSVFile.Read(fileNameV22); + + var xfields = new[] { ModalResultField.time, ModalResultField.dist }; + + var yfields = new[] { + ModalResultField.v_act, ModalResultField.n, ModalResultField.Gear, ModalResultField.Pe_eng, ModalResultField.Tq_eng, + ModalResultField.FCMap + }; + + foreach (var xfield in xfields) { + for (var i = 1; i <= yfields.Length; i++) { + var yfield = yfields[i - 1]; + var x = modDataV3.Rows.Cast<DataRow>().Select(v => v.Field<string>(ModalResultField.time.GetName())).ToArray(); + var y = modDataV3.Rows.Cast<DataRow>().Select(v => v.Field<string>(yfield.GetName())).ToArray(); + + var x2 = modDataV22.Rows.Cast<DataRow>().Select(v => v.Field<string>(ModalResultField.time.GetName())).ToArray(); + var y2 = modDataV22.Rows.Cast<DataRow>().Select(v => v.Field<string>(yfield.GetName())).ToArray(); + + + var fileName = string.Format("{0}_{1}_{2}.png", Path.GetFileNameWithoutExtension(fileNameV3), xfield, i); + var values = string.Format("{0}|{1}|{2}|{3}", string.Join(",", x), string.Join(",", y), string.Join(",", x2), + string.Join(",", y2)); + + var maxX = (int)Math.Ceiling(Math.Max(x.ToDouble().Max(), x2.ToDouble().Max())); + CreateGraphFile(fileName, xfield.GetCaption(), yfield.GetCaption(), maxX, values); + } + } + } + + private static void CreateGraphFile(string filename, string xLabel, string yLabel, int xAxisRange, string values) + { + using (var client = new WebClient()) { + byte[] response = client.UploadValues("https://chart.googleapis.com/chart", new NameValueCollection { + { "cht", "lxy" }, + { "chd", "t:" + values }, + { "chs", "1000x300" }, + { "chxt", "x,x,y,y" }, + { "chds", "a" }, + { "chxr", string.Format("0,0,{0},10", xAxisRange) }, + { "chco", "0000FF,FF0000" }, + { "chg", "5,10" }, + { "chxl", string.Format("1:|{0}|3:|{1}", xLabel, yLabel) }, + { "chxp", "1,0|3,0" }, + { "chdl", "V3|V2.2" }, + }); + + File.WriteAllBytes(filename, response); + } + } + } +} \ No newline at end of file diff --git a/VectoCoreTest/VectoCoreTest.csproj b/VectoCoreTest/VectoCoreTest.csproj index 977814744122561716a2fce2937a933983a58f95..b70a6a6c16baaf6bcf2746b54891b8f20d454163 100644 --- a/VectoCoreTest/VectoCoreTest.csproj +++ b/VectoCoreTest/VectoCoreTest.csproj @@ -64,6 +64,7 @@ <Compile Include="Integration\CoachPowerTrain.cs" /> <Compile Include="Integration\DriverStrategy\DriverStrategyTestCoach.cs" /> <Compile Include="Integration\DriverStrategy\DriverStrategyTestTruck.cs" /> + <Compile Include="Utils\GraphWriter.cs" /> <Compile Include="Integration\EngineOnlyCycle\EngineOnlyCycleTest.cs" /> <Compile Include="Integration\SimpleDrivingCycles.cs" /> <Compile Include="Integration\SimulationRuns\FullPowertrain.cs" />