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

Skip to content
Snippets Groups Projects
Commit e795c71a authored by Michael KRISPER's avatar Michael KRISPER
Browse files

added console output of detected driving cycles

parent 2bcef72f
No related branches found
No related tags found
No related merge requests found
{
"Header": {
"CreatedBy": "Raphael Luz IVT TU-Graz (14fea510-e457-4bf6-860f-a9514dc327f1)",
"Date": "25.06.2015 11:23:31",
"AppVersion": "2.2 beta",
"CreatedBy": " ()",
"Date": "8/21/2015 10:16:31 AM",
"AppVersion": "2.2 beta-2",
"FileVersion": 5
},
"Body": {
......
......@@ -3,7 +3,7 @@
"CreatedBy": "Raphael Luz IVT TU-Graz (85407225-fc3f-48a8-acda-c84a05df6837)",
"Date": "29.07.2014 16:59:13",
"AppVersion": "2.0.4-beta",
"FileVersion": 5
"FileVersion": 7
},
"Body": {
"SavedInDeclMode": false,
......@@ -12,11 +12,10 @@
"CurbWeightExtra": 0.0,
"Loading": 3300.0,
"MassMax": 24.0,
"Cd": 0.441,
"CrossSecArea": 7.4,
"CdA": 3.2634,
"rdyn": 520.0,
"Rim": "-",
"CdCorrMode": "CdOfV",
"CdCorrMode": "CdofVdecl",
"CdCorrFile": "24t Coach.vcdv",
"Retarder": {
"Type": "Secondary",
......
......@@ -35,13 +35,11 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Remoting.Channels;
using System.Threading;
using NLog;
using NLog.Config;
using TUGraz.VectoCore.Configuration;
using TUGraz.VectoCore.InputData.FileIO.JSON;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.Simulation.Impl;
using TUGraz.VectoCore.OutputData;
using TUGraz.VectoCore.OutputData.FileIO;
......@@ -50,12 +48,12 @@ namespace VectoConsole
{
internal static class Program
{
private static int NumLines;
private static int _numLines;
private static int ProgessCounter { get; set; }
private const string USAGE = @"Usage: vecto.exe [-h] [-v] FILE1.vecto [FILE2.vecto ...]";
private const string Usage = @"Usage: vecto.exe [-h] [-v] FILE1.vecto [FILE2.vecto ...]";
private const string HELP = @"
private const string Help = @"
Commandline Interface for Vecto.
Synopsis:
......@@ -84,7 +82,7 @@ Examples:
vecto.exe -h
";
private static JobContainer jobContainer;
private static JobContainer _jobContainer;
private static int Main(string[] args)
{
......@@ -92,7 +90,7 @@ Examples:
// on -h display help and terminate.
if (args.Contains("-h")) {
ShowVersionInformation();
Console.Write(HELP);
Console.Write(Help);
return 0;
}
......@@ -134,7 +132,7 @@ Examples:
// if no other arguments given: display usage and terminate
if (!args.Any()) {
Console.Write(USAGE);
Console.Write(Usage);
return 1;
}
......@@ -144,70 +142,75 @@ Examples:
// process the file list and start simulation
//var sumFileName = Path.Combine(Path.GetDirectoryName(fileList.First()) ?? "",
// Path.GetFileNameWithoutExtension(fileList.First()) + Constants.FileExtensions.SumFile);
var fileWriter = new FileOutputWriter(Path.GetDirectoryName(fileList.First() ?? ""));
var fileWriter = new FileOutputWriter(fileList.First());
var sumWriter = new SummaryDataContainer(fileWriter);
jobContainer = new JobContainer(sumWriter);
_jobContainer = new JobContainer(sumWriter);
var mode = ExecutionMode.Declaration;
if (args.Contains("-eng")) {
mode = ExecutionMode.Engineering;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(
"Switching to Engineering Mode. Make sure the job-file is saved in engineering mode!");
Console.WriteLine(@"Switching to Engineering Mode. Make sure the job-file is saved in engineering mode!");
Console.ResetColor();
}
Console.WriteLine("Reading Job Files");
Console.WriteLine(@"Reading Job Files");
stopWatch.Start();
foreach (var file in fileList.Where(f => Path.GetExtension(f) == Constants.FileExtensions.VectoJobFile)) {
var dataProvider = JSONInputDataFactory.ReadJsonJob(file);
var runsFactory = new SimulatorFactory(mode, dataProvider, fileWriter);
if (args.Contains("-mod")) {
runsFactory.WriteModalResults = true;
}
jobContainer.AddRuns(runsFactory);
_jobContainer.AddRuns(runsFactory);
}
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(@"Detected cycles:");
Console.ResetColor();
var cycles = _jobContainer.GetCycleTypes().ToList();
foreach (var cycle in _jobContainer.GetCycleTypes()) {
Console.WriteLine(@" {0}: {1}", cycle.Name, cycle.CycleType);
}
Console.WriteLine();
stopWatch.Stop();
timings.Add("Reading input files", stopWatch.Elapsed.TotalMilliseconds);
stopWatch.Reset();
Console.WriteLine("Starting simulation runs");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(@"Starting simulation runs");
if (debugEnabled) {
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Debug-Output is enabled, executing simulation runs sequentially");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(@"Debug-Output is enabled, executing simulation runs sequentially");
}
Console.ResetColor();
Console.WriteLine();
stopWatch.Start();
jobContainer.Execute(!debugEnabled);
Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs e) => {
var isCtrlC = e.SpecialKey == ConsoleSpecialKey.ControlC;
var isCtrlBreak = e.SpecialKey == ConsoleSpecialKey.ControlBreak;
_jobContainer.Execute(!debugEnabled);
if (!isCtrlC) {
return;
Console.CancelKeyPress += (sender, e) => {
if (e.SpecialKey == ConsoleSpecialKey.ControlC) {
e.Cancel = true;
_jobContainer.CancelCurrent();
}
//Console.WriteLine("Canceling simulation!");
e.Cancel = true;
Program.jobContainer.CancelCurrent();
};
//var x = Console.CursorLeft;
while (!jobContainer.AllCompleted) {
PrintProgress(jobContainer.GetProgress());
while (!_jobContainer.AllCompleted) {
PrintProgress(_jobContainer.GetProgress());
Thread.Sleep(250);
}
stopWatch.Stop();
timings.Add("Simulation runs", stopWatch.Elapsed.TotalMilliseconds);
PrintProgress(jobContainer.GetProgress(), args.Contains("-t"));
PrintProgress(_jobContainer.GetProgress(), args.Contains("-t"));
if (args.Contains("-t")) {
PrintTimings(timings);
}
} catch (Exception e) {
Console.Error.WriteLine(e.Message);
//Trace.TraceError(e.ToString());
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.WriteLine("Please see log-file for further details (logs/log.txt)");
Console.ResetColor();
......@@ -219,15 +222,15 @@ Examples:
private static void ShowVersionInformation()
{
var vectodll = AssemblyName.GetAssemblyName("VectoCore.dll");
Console.WriteLine("VectoConsole: {0}", Assembly.GetExecutingAssembly().GetName().Version);
Console.WriteLine("VectoCore: {0}", vectodll.Version);
Console.WriteLine(@"VectoConsole: {0}", Assembly.GetExecutingAssembly().GetName().Version);
Console.WriteLine(@"VectoCore: {0}", vectodll.Version);
}
private static void PrintProgress(Dictionary<uint, JobContainer.ProgressEntry> progessData,
bool showTiming = true)
{
Console.SetCursorPosition(0, Console.CursorTop - NumLines);
NumLines = 0;
Console.SetCursorPosition(0, Console.CursorTop - _numLines);
_numLines = 0;
var sumProgress = 0.0;
foreach (var progressEntry in progessData) {
if (progressEntry.Value.Success) {
......@@ -241,24 +244,24 @@ Examples:
}
var runName = string.Format("{0} {1} {2}", progressEntry.Value.RunName, progressEntry.Value.CycleName,
progressEntry.Value.RunSuffix);
Console.WriteLine("{0,-60} {1,8:P}{2}", runName, progressEntry.Value.Progress, timingString);
Console.WriteLine(@"{0,-60} {1,8:P}{2}", runName, progressEntry.Value.Progress, timingString);
Console.ResetColor();
sumProgress += progressEntry.Value.Progress;
NumLines++;
_numLines++;
}
sumProgress /= NumLines;
sumProgress /= _numLines;
var spinner = "/-\\|"[ProgessCounter++ % 4];
var bar = new string('#', (int)(sumProgress * 100.0 / 2));
Console.WriteLine(string.Format(" {2} [{1,-50}] [{0,7:P}]", sumProgress, bar, spinner));
NumLines++;
Console.WriteLine(@" {2} [{1,-50}] [{0,7:P}]", sumProgress, bar, spinner);
_numLines++;
}
private static void PrintTimings(Dictionary<string, double> timings)
{
Console.WriteLine();
Console.WriteLine("---- timing information ----");
Console.WriteLine(@"---- timing information ----");
foreach (var timing in timings) {
Console.WriteLine("{0,-20}: {1:F2}s", timing.Key, timing.Value / 1000);
Console.WriteLine(@"{0,-20}: {1:F2}s", timing.Key, timing.Value / 1000);
}
}
}
......
......@@ -64,6 +64,8 @@ namespace TUGraz.VectoCore.InputData.Reader.Impl
var vehicleInputData = InputDataProvider.VehicleInputData;
var crossWindRequired = vehicleInputData.CrossWindCorrectionMode == CrossWindCorrectionMode.VAirBetaLookupTable;
return InputDataProvider.JobInputData().Cycles.Select(cycle => new VectoRunData {
JobName = InputDataProvider.JobInputData().JobName,
EngineData = engineData,
......@@ -73,9 +75,7 @@ namespace TUGraz.VectoCore.InputData.Reader.Impl
DriverData = driver,
Aux = dao.CreateAuxiliaryData(InputDataProvider.AuxiliaryInputData()),
Retarder = dao.CreateRetarderData(InputDataProvider.RetarderInputData, InputDataProvider.VehicleInputData),
Cycle =
DrivingCycleDataReader.ReadFromDataTable(cycle.CycleData, cycle.Name,
vehicleInputData.CrossWindCorrectionMode == CrossWindCorrectionMode.VAirBetaLookupTable),
Cycle = DrivingCycleDataReader.ReadFromDataTable(cycle.CycleData, cycle.Name, crossWindRequired),
IsEngineOnly = InputDataProvider.JobInputData().EngineOnlyMode
});
}
......
......@@ -34,9 +34,8 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
using TUGraz.VectoCore.OutputData;
namespace TUGraz.VectoCore.Models.Simulation.Impl
......@@ -66,6 +65,20 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
Runs.Add(new RunEntry { Run = run, JobContainer = this });
}
public struct CycleTypeDescription
{
public string Name;
public CycleType CycleType;
}
public IEnumerable<CycleTypeDescription> GetCycleTypes()
{
return Runs.Select(r => new CycleTypeDescription {
Name = r.Run.CycleName,
CycleType = r.Run.GetContainer().RunData.Cycle.CycleType
}).Distinct();
}
public void AddRuns(IEnumerable<IVectoRun> runs)
{
_jobNumber++;
......@@ -116,11 +129,11 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
}
}
private static readonly AutoResetEvent resetEvent = new AutoResetEvent(false);
private static readonly AutoResetEvent ResetEvent = new AutoResetEvent(false);
public void WaitFinished()
{
resetEvent.WaitOne();
ResetEvent.WaitOne();
}
......@@ -133,7 +146,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
}
if (AllCompleted) {
_sumWriter.Finish();
resetEvent.Set();
ResetEvent.Set();
}
}
......@@ -154,7 +167,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
public bool AllCompleted
{
get { return (Runs.Count(x => x.Done == true) == Runs.Count()); }
get { return Runs.All(r => r.Done); }
}
public class ProgressEntry
......
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