Skip to content

Commit

Permalink
Added option to choose the tolerance direction(horizontal or vertical)
Browse files Browse the repository at this point in the history
Added the fix for modelica-tools#17 Missing variables are not always skipped
  • Loading branch information
abhilash-kumar-nair committed Aug 22, 2018
1 parent d335141 commit 209c607
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 8 deletions.
77 changes: 70 additions & 7 deletions Modelica_ResultCompare/CsvFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class CsvFile:IDisposable
private Dictionary<string, List<double>> _values = new Dictionary<string, List<double>>();
private bool _bShowRelativeErrors = true;
private bool _bDisposed = false;
public int userchoice;///used in calculation of tube dimensions

/// Holds values for x axis (time)
public List<double> XAxis { get { return _xAxis; } }
Expand Down Expand Up @@ -281,12 +282,44 @@ public Report CompareFiles(Log log, CsvFile csvBase, string sReportPath, ref Opt
TubeReport tubeReport = new TubeReport();
TubeSize size = null;
Tube tube = new Tube(size);
IOptions tubeOptions = new Options1(_dRangeDelta, Axes.X);
switch (options.Direction)
{
case ToleranceDirection.X:
userchoice = 1; ///set to 1 for tolerenace in X axis
break;
case ToleranceDirection.Y:
userchoice = 0; ///set to 0 for tolerance in Y-axis
break;

default://Invalid mode
Console.WriteLine(options.GetUsage());
break;
}

if (userchoice == 1)
{
IOptions tubeOptions = new Options1(_dRangeDelta, Axes.X);
}
else if (userchoice == 0)
{
IOptions tubeOptions = new Options1(_dRangeDelta, Axes.Y);
}
else
{
Console.WriteLine("opted for wrong choice");
Environment.ExitCode = 2;
}


foreach (KeyValuePair<string, List<double>> res in csvBase.Results)
{
if (!this.Results.ContainsKey(res.Key))
log.WriteLine(LogLevel.Warning, "{0} not found in \"{1}\", skipping checks.", res.Key, this._fileName);
{
log.Error("{0} not found in \"{1}\", skipping checks.", res.Key, this._fileName);
rep.Chart.Add(new Chart() { Title = res.Key, Errors = 1 });
Environment.ExitCode = 1;
continue;
}
else
{
compareCurve = new Curve(res.Key, this.XAxis.ToArray<double>(), this.Results[res.Key].ToArray<double>());
Expand All @@ -310,7 +343,32 @@ public Report CompareFiles(Log log, CsvFile csvBase, string sReportPath, ref Opt
log.WriteLine(LogLevel.Debug, "The resolution of the base x-axis is good.");

size = new TubeSize(reference, true);
size.Calculate(_dRangeDelta, Axes.X, Relativity.Relative);
switch (options.Method)
{
case ExecutionMethod.Relative:
if (userchoice == 1)
{
size.Calculate(_dRangeDelta, Axes.X, Relativity.Relative);
}
else
{
size.Calculate(_dRangeDelta, Axes.Y, Relativity.Relative);
}
break;
case ExecutionMethod.Absolute:
if (userchoice == 1)
{
size.Calculate(_dRangeDelta, Axes.X, Relativity.Absolute);
}
else
{
size.Calculate(_dRangeDelta, Axes.Y, Relativity.Absolute);
}
break;
default://Invalid mode
Console.WriteLine(options.GetUsage());
break;
}
tube = new Tube(size);
tubeReport = tube.Calculate(reference);
tube.Validate(compareCurve);
Expand Down Expand Up @@ -346,16 +404,21 @@ public Report CompareFiles(Log log, CsvFile csvBase, string sReportPath, ref Opt
writer.WriteLine(". Time: {0:o}", DateTime.Now);
writer.WriteLine(". Operation: {0}", options.Mode);
writer.WriteLine(". Tolerance: {0}", options.Tolerance);
writer.WriteLine(". Execution Method: {0}", options.Method);
writer.WriteLine(". Direction of Tolerence: {0}", options.Direction);
writer.WriteLine(". Result: {0}", sResult);

if (rep.TotalErrors > 0)
{
Chart pairMax = rep.Chart.Aggregate((l, r) => l.DeltaError > r.DeltaError ? l : r);
writer.WriteLine(". Biggest error: {0}=>{1}", pairMax.Title, pairMax.DeltaError.ToString(CultureInfo.InvariantCulture));
writer.WriteLine(". Failed values:");
if (pairMax.DeltaError > 0)
{
writer.WriteLine(". Largest error: {0}=>{1}", pairMax.Title, pairMax.DeltaError);
writer.WriteLine(". Failed values:");

foreach (Chart c in (from r in rep.Chart where r.DeltaError > 0 select r).OrderByDescending(er => er.DeltaError))
writer.WriteLine("{0}=>{1}", c.Title, c.DeltaError.ToString(CultureInfo.InvariantCulture));
foreach (Chart c in (from r in rep.Chart where r.DeltaError > 0 select r).OrderByDescending(er => er.DeltaError))
writer.WriteLine("{0}=>{1}", c.Title, c.DeltaError.ToString(CultureInfo.InvariantCulture));
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions Modelica_ResultCompare/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ public enum OperationMode
PlotOnly
}

public enum ExecutionMethod
{
Relative,
Absolute
}

public enum ToleranceDirection
{
X,
Y
}

public class Options
{
[Option('a', "args", Required = false, HelpText = "Arguments to run FMU checker with. [Default is \"-l 5 -h 1e-2 -s 1.5\"]")]
Expand All @@ -33,6 +45,12 @@ public class Options
[Option('m', "mode", DefaultValue = OperationMode.CsvFileCompare, Required = false, HelpText = "Set the tools operation mode. Valid modes are: CsvFileCompare, CsvTreeCompare, FmuChecker, PlotOnly(experimental)")]
public OperationMode Mode { get; set; }

[Option("method", DefaultValue = ExecutionMethod.Relative, Required = false, HelpText = "Set the tools execution method. Valid methods are: Relative and Absolute.If relative method is opted range of tolerance is [0,1] and for absolute there is no limit.")]
public ExecutionMethod Method { get; set; }

[Option("direction", DefaultValue = ToleranceDirection.X, Required = false, HelpText = "Set the tolerance to any one of the axis.valid directions are: X and Y.")]
public ToleranceDirection Direction { get; set; }

[Option('o', "override", DefaultValue = false, HelpText = "Override output files if they already exist (Default behaviour is to put the output next to the found file with a time stamp in the file name).")]
public bool OverrideOutput { get; set; }

Expand Down
2 changes: 2 additions & 0 deletions Modelica_ResultCompare/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ private static void Run(string[] cmdArgs)
_log.WriteLine(LogLevel.Debug, "Parsing command line options: {0} * {1}", Environment.NewLine, string.Join(" ", cmdArgs));
_log.WriteLine(LogLevel.Debug, "Successfully parsed the following options:");
_log.WriteLine(LogLevel.Debug, "Operation mode is {0}", options.Mode);
_log.WriteLine(LogLevel.Debug, "Execution method is {0}", options.Method);
_log.WriteLine(LogLevel.Debug, "Given tolerance is in {0} direction", options.Direction);
_log.WriteLine(LogLevel.Debug, "Tolerance is {0}", options.Tolerance);

if (options.Delimiter == 0)
Expand Down
7 changes: 6 additions & 1 deletion Modelica_ResultCompare/Report.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ private bool GetHeaderTable(out StringBuilder sb)
{
sb.AppendLine("<table class=\"info\">");
sb.AppendFormat(" <tr><td class=\"header\">Value:</td><td>{0}</td></tr>", this.Title).AppendLine();
sb.AppendLine(" <tr><td class=\"header\">Errors:</td><td>Exception during validation, skipping!</td></tr>");
sb.AppendFormat(" <tr><td class=\"header\">Errors:</td><td>variable {0} missing !</td></tr>",this.Title).AppendLine();
sb.AppendLine("</table>");
sb.AppendLine("<p style=\"width: 100%; text-align: right;\"><a href=\"#top\">[Back to top]</a></p>");

Expand Down Expand Up @@ -541,6 +541,9 @@ public bool WriteReport(Log log, Options options)
if (null != options.Tolerance)
writer.WriteLine(" <tr><td colspan=\"2\" class=\"header\">Tolerance:</td><td>{0}</td></tr>", options.Tolerance);

writer.WriteLine(" <tr><td colspan=\"2\" class=\"header\">Execution method:</td><td>{0}</td></tr>", options.Method);
writer.WriteLine(" <tr><td colspan=\"2\" class=\"header\">Tolerence is given in:</td><td>{0} direction</td></tr>", options.Method);

if (!String.IsNullOrEmpty(options.Logfile))
{
writer.WriteLine(" <tr><td colspan=\"2\" class=\"header\">Logfile:</td><td><a href=\"file:///{0}\">{0}</a></td></tr>", options.Logfile);
Expand Down Expand Up @@ -838,6 +841,8 @@ private void WriteHeader(TextWriter writer, Options options)
writer.WriteLine(" <tr><td class=\"header\">Compare File:</td><td><a href=\"file:///{0}\">{1}</a></td></tr>", this.CompareFile.Replace("\\", "/"), this.CompareFile);

writer.WriteLine(" <tr><td class=\"header\">Tolerance:</td><td>{0}</td></tr>", _tolerance);
writer.WriteLine(" <tr><td class=\"header\">Execution method:</td><td>{0}</td></tr>", options.Method);
writer.WriteLine(" <tr><td class=\"header\">Tolerance direction:</td><td>{0}</td></tr>", options.Direction);
writer.WriteLine(" <tr><td class=\"header\">Tested:</td><td>{0} [UTC]</td></tr>", DateTime.UtcNow);

int iTested = _chart.Count - (from c in _chart where c.Errors == -1 select c).Count();
Expand Down

0 comments on commit 209c607

Please sign in to comment.