private void PrepareCharts(Report rep, Curve compare)//Draw result only { PrepareCharts(compare, null, null, rep, null, new KeyValuePair <string, List <double> >(compare.Name, null), false); }
private void PrepareCharts(Curve reference, Curve compare, Curve error, Report rep, TubeReport tubeReport, KeyValuePair <string, List <double> > res, bool bDrawBitmapPlots) { Chart ch = new Chart() { LabelX = "Time", LabelY = res.Key, Errors = (null != error && null != error.X) ? error.X.Length : 0, Title = string.Format("{0}.{1}", Path.GetFileNameWithoutExtension(this._fileName), res.Key), UseBitmap = bDrawBitmapPlots }; if (null != compare) { ch.Series.Add(new Series() { Color = Color.Orange, ArrayString = (bDrawBitmapPlots) ? string.Empty : Series.GetArrayString(reference.X, reference.Y), Title = "Base (to compare with)", XAxis = (bDrawBitmapPlots) ? reference.X : null, YAxis = (bDrawBitmapPlots) ? reference.Y : null }); ch.Series.Add(new Series() { Color = Color.Green, ArrayString = (bDrawBitmapPlots) ? string.Empty : Series.GetArrayString(compare.X, compare.Y), Title = "Result", XAxis = (bDrawBitmapPlots) ? compare.X : null, YAxis = (bDrawBitmapPlots) ? compare.Y : null }); ch.Series.Add(new Series() { Color = Color.LightBlue, ArrayString = (bDrawBitmapPlots) ? string.Empty : Series.GetArrayString(tubeReport.Lower.X, tubeReport.Lower.Y), Title = "Low Tube", XAxis = (bDrawBitmapPlots) ? tubeReport.Lower.X : null, YAxis = (bDrawBitmapPlots) ? tubeReport.Lower.Y : null }); ch.Series.Add(new Series() { Color = Color.LightGreen, ArrayString = (bDrawBitmapPlots) ? string.Empty : Series.GetArrayString(tubeReport.Upper.X, tubeReport.Upper.Y), Title = "High Tube", XAxis = (bDrawBitmapPlots) ? tubeReport.Upper.X : null, YAxis = (bDrawBitmapPlots) ? tubeReport.Upper.Y : null }); } else { ch.Series.Add(new Series() { Color = Color.Green, ArrayString = (bDrawBitmapPlots) ? string.Empty : Series.GetArrayString(reference.X, reference.Y), Title = "Compare", XAxis = (bDrawBitmapPlots) ? reference.X : null, YAxis = (bDrawBitmapPlots) ? reference.Y : null }); } if (null != error && null != error.X && error.X.Length > 0) { //Get complete error curve as "error" only holds error points Curve curveErrors = new Curve("ERRORS", new double[compare.X.Length], new double[compare.X.Length]); int j = 0; for (int i = 0; i < compare.X.Length - 1; i++) { curveErrors.X[i] = compare.X[i]; if (error.X.Contains(compare.X[i])) { curveErrors.Y[i] = (this._bShowRelativeErrors) ? error.Y[j] : 1; if (compare.X[i + 1] > compare.X[i]) { j++; } } else { curveErrors.Y[i] = 0; } } ch.Series.Add(new Series() { Color = Color.Red, ArrayString = (bDrawBitmapPlots) ? string.Empty : Series.GetArrayString(curveErrors.X, curveErrors.Y), Title = curveErrors.Name, XAxis = (bDrawBitmapPlots) ? error.X : null, YAxis = (bDrawBitmapPlots) ? error.Y : null }); //Calculate delta error List <double> lDeltas = new List <double>(); j = 0; for (int i = 1; i < compare.X.Length - 1; i++) { if (j < error.X.Length) { while (compare.X[i] < error.X[j]) { i++; continue; } if (i < compare.X.Length - 1) { lDeltas.Add((Math.Abs(error.Y[j]) * ((Math.Abs(compare.X[i] - compare.X[i - 1])) + (Math.Abs(compare.X[i + 1] - compare.X[i])))) / 2); } else // handle errors in the last point (there is no i+1) { lDeltas.Add((Math.Abs(error.Y[j]) * ((Math.Abs(compare.X[i] - compare.X[i - 1])))) / 2); } j++; } } ch.DeltaError = lDeltas.Sum() / (1e-3 + compare.Y.Max(x => Math.Abs(x))); } if (null != tubeReport && tubeReport.Lower.X.ToList <double>().Count > 2)//Remember Start and Stop values for graph scaling { ch.MinValue = tubeReport.Lower.X[0]; ch.MaxValue = tubeReport.Lower.X.Last(); } rep.Chart.Add(ch); }
public Report CompareFiles(Log log, CsvFile csvBase, string sReportPath, ref Options options) { int iInvalids = 0; Report rep = new Report(sReportPath); log.WriteLine("Comparing \"{0}\" to \"{1}\"", _fileName, csvBase.ToString()); rep.BaseFile = csvBase.ToString(); rep.CompareFile = _fileName; Curve reference = new Curve(); Curve compareCurve = new Curve(); TubeReport tubeReport = new TubeReport(); TubeSize size = null; Tube tube = new Tube(size); IOptions tubeOptions = new Options1(_dRangeDelta, Axes.X); foreach (KeyValuePair <string, List <double> > res in csvBase.Results) { if (!this.Results.ContainsKey(res.Key)) { size = null; tube = new Tube(size); log.WriteLine(LogLevel.Warning, "{0} not found in \"{1}\", skipping checks.", res.Key, this._fileName); } else { compareCurve = new Curve(res.Key, this.XAxis.ToArray <double>(), this.Results[res.Key].ToArray <double>()); if (res.Value.Count == 0) { log.Error("{0} has no y-Values! Maybe error during parsing? Skipping", res.Key); continue; } reference = new Curve("Reference ", csvBase.XAxis.ToArray(), csvBase.Results[res.Key].ToArray()); if (!reference.ImportSuccessful) { log.Error("Error in the calculation of the tubes. Skipping {0}", res.Key); rep.Chart.Add(new Chart() { Title = res.Key, Errors = 1 }); continue; } if (reference.X.Length < compareCurve.X.Length) { log.WriteLine(LogLevel.Warning, "The resolution of the base x-axis is smaller than the compare x-axis. The better the base resolution is, the better the validation result will be!"); } else { 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); tube = new Tube(size); tubeReport = tube.Calculate(reference); tube.Validate(compareCurve); if (tubeReport.Valid == Validity.Valid) { log.WriteLine(res.Key + " is valid"); } else { log.WriteLine(LogLevel.Warning, "{0} is invalid! {1} errors have been found during validation.", res.Key, (null != tube.Report.Errors && null != tube.Report.Errors.X) ? tube.Report.Errors.X.Length : 0); iInvalids++; Environment.ExitCode = 1; } } if (null != tube.Report)//No charts for missing reports { PrepareCharts(reference, compareCurve, tube.Report.Errors, rep, tubeReport, res, options.UseBitmapPlots); } } rep.Tolerance = _dRangeDelta; string sResult = "na"; if (rep.TotalErrors == 0) { sResult = "passed"; } else { sResult = "failed"; } if (options.ComparisonFlag) { using (TextWriter writer = File.CreateText(string.Format("{0}{1}compare_{2}.log", Path.GetDirectoryName(_fileName), Path.DirectorySeparatorChar, sResult))) { //Content needs to be defined writer.WriteLine("CSV Compare Version {0} ({1})", Info.AssemblyVersion, Assembly.GetExecutingAssembly().GetName().ProcessorArchitecture); writer.WriteLine("Comparison result file for {0}", _fileName); writer.WriteLine(". Time: {0:o}", DateTime.Now); writer.WriteLine(". Operation: {0}", options.Mode); writer.WriteLine(". Tolerance: {0}", options.Tolerance); 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:"); 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)); } } } } rep.WriteReport(log, (string.IsNullOrEmpty(options.ReportDir) || options.NoMetaReport) ? string.Empty : options.ReportDir, options); GC.Collect();//immediately forget big charts and data return(rep); }