Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/17/13 13:32:08 (11 years ago)
Author:
ascheibe
Message:

#2031

  • made operations in ChartAnalysisView asynchronous
  • renamed views to go along with the other RunCollection views
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/ChartAnalysisView.cs

    r9706 r9713  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using System.Threading.Tasks;
    2526using System.Windows.Forms;
    2627using HeuristicLab.Common;
     
    2829using HeuristicLab.Data;
    2930using HeuristicLab.MainForm;
     31using HeuristicLab.MainForm.WindowsForms;
    3032using HeuristicLab.Optimization;
    3133using HeuristicLab.PluginInfrastructure;
    3234
    3335namespace HeuristicLab.Analysis.Statistics {
    34   [View("RunCollection Chart Analysis View")]
     36  [View("RunCollection Chart Analysis")]
    3537  [Content(typeof(RunCollection), false)]
    3638  public sealed partial class ChartAnalysisView : ItemView {
     
    4648
    4749    private List<IRun> runs;
     50    private Progress progress;
     51    private ProgressView progressView;
     52    private bool valuesAdded = false;
    4853
    4954    public ChartAnalysisView() {
    5055      InitializeComponent();
     56      progress = new Progress() {
     57        CanBeCanceled = false,
     58        ProgressState = ProgressState.Finished
     59      };
     60      progressView = new ProgressView(this, progress);
     61
    5162      stringConvertibleMatrixView.DataGridView.RowHeaderMouseDoubleClick += new DataGridViewCellMouseEventHandler(DataGridView_RowHeaderMouseDoubleClick);
    5263
     
    6778        components.Dispose();
    6879      }
     80      if (disposing)
     81        progressView.Dispose();
    6982      base.Dispose(disposing);
    7083    }
     
    98111
    99112    private void Content_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
    100       RebuildDataTable();
     113      RebuildDataTableAsync();
    101114    }
    102115
    103116    private void Content_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
    104       RebuildDataTable();
     117      RebuildDataTableAsync();
    105118    }
    106119
    107120    private void Content_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
    108       RebuildDataTable();
     121      RebuildDataTableAsync();
    109122    }
    110123
    111124    void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) {
    112       if (!Content.UpdateOfRunsInProgress) {
    113         RebuildDataTable();
     125      if (!Content.UpdateOfRunsInProgress && !valuesAdded) {
     126        RebuildDataTableAsync();
     127      }
     128      if (valuesAdded) {
     129        valuesAdded = false;
    114130      }
    115131    }
     
    133149
    134150    private void dataRowComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    135       RebuildDataTable();
     151      RebuildDataTableAsync();
    136152    }
    137153
    138154    private void addLineToChart_Click(object sender, EventArgs e) {
     155      progress.Status = "Adding fitted lines to charts...";
     156      progress.ProgressState = ProgressState.Started;
     157      progress.ProgressValue = 0.0;
     158
     159      var task = System.Threading.Tasks.Task.Factory.StartNew(AddLineToChart);
     160
     161      task.ContinueWith((t) => {
     162        progress.Finish();
     163        ErrorHandling.ShowErrorDialog("An error occured while adding lines to charts. ", t.Exception);
     164      }, TaskContinuationOptions.OnlyOnFaulted);
     165
     166      task.ContinueWith((t) => {
     167        progress.Finish();
     168      }, TaskContinuationOptions.OnlyOnRanToCompletion);
     169    }
     170
     171    private void AddLineToChart() {
    139172      string resultName = (string)dataTableComboBox.SelectedItem;
    140173      string rowName = (string)dataRowComboBox.SelectedItem;
     
    171204        }
    172205      }
     206      valuesAdded = true;
    173207      Content.UpdateOfRunsInProgress = false;
    174208    }
     
    200234    }
    201235
     236    private void RebuildDataTableAsync() {
     237      progress.Status = "Calculating values...";
     238      progress.ProgressState = ProgressState.Started;
     239      progress.ProgressValue = 0.0;
     240
     241      var task = System.Threading.Tasks.Task.Factory.StartNew(RebuildDataTable);
     242
     243      task.ContinueWith((t) => {
     244        progress.Finish();
     245        ErrorHandling.ShowErrorDialog("An error occured while calculating values. ", t.Exception);
     246      }, TaskContinuationOptions.OnlyOnFaulted);
     247
     248      task.ContinueWith((t) => {
     249        progress.Finish();
     250      }, TaskContinuationOptions.OnlyOnRanToCompletion);
     251    }
     252
    202253    private void RebuildDataTable() {
    203254      string resultName = (string)dataTableComboBox.SelectedItem;
    204255      string rowName = (string)dataRowComboBox.SelectedItem;
    205       string[] columnNames = new string[] { "Count", "Minimum", "Maximum", "Average", "Median", "Standard Deviation", "Variance", "25th Percentile", "75th Percentile", "Gradient", "Relative Error", "Avg. of Upper 25 %", " Avg. of Lower 25 %", "Avg. of First 25 %", "Avg. of Last 25 %" };
     256      LinearLeastSquaresFitting llsFitting = new LinearLeastSquaresFitting();
     257      LogFitting logFitting = new LogFitting();
     258      string[] columnNames = new string[] { "Count", "Minimum", "Maximum", "Average", "Median", "Standard Deviation", "Variance", "25th Percentile", "75th Percentile", "Avg. of Upper 25 %", " Avg. of Lower 25 %", "Avg. of First 25 %", "Avg. of Last 25 %", "Gradient", "Relative Error", "a", "b" };
    206259
    207260      runs = Content.Where(x => x.Results.ContainsKey(resultName) && x.Visible).ToList();
     
    226279        double percentile25 = values.Percentile(0.25);
    227280        double percentile75 = values.Percentile(0.75);
    228         double k, d, r;
    229         LinearLeastSquaresFitting llsf = new LinearLeastSquaresFitting();
    230         llsf.Calculate(values.ToArray(), out k, out d);
    231         r = llsf.CalculateError(values.ToArray(), k, d);
    232281        double lowerAvg = values.OrderBy(x => x).Take((int)(values.Count() * 0.25)).Average();
    233282        double upperAvg = values.OrderByDescending(x => x).Take((int)(values.Count() * 0.25)).Average();
    234283        double firstAvg = values.Take((int)(values.Count() * 0.25)).Average();
    235284        double lastAvg = values.Skip((int)(values.Count() * 0.75)).Average();
     285        double k, d, r, a, b;
     286        llsFitting.Calculate(values.ToArray(), out k, out d);
     287        r = llsFitting.CalculateError(values.ToArray(), k, d);
     288        logFitting.Calculate(values.ToArray(), out a, out b);
    236289
    237290        dt[i, 0] = cnt;
     
    244297        dt[i, 7] = percentile25;
    245298        dt[i, 8] = percentile75;
    246         dt[i, 9] = k;
    247         dt[i, 10] = r;
    248         dt[i, 11] = upperAvg;
    249         dt[i, 12] = lowerAvg;
    250         dt[i, 13] = firstAvg;
    251         dt[i, 14] = lastAvg;
     299        dt[i, 9] = upperAvg;
     300        dt[i, 10] = lowerAvg;
     301        dt[i, 11] = firstAvg;
     302        dt[i, 12] = lastAvg;
     303        dt[i, 13] = k;
     304        dt[i, 14] = r;
     305        dt[i, 15] = a;
     306        dt[i, 16] = b;
    252307
    253308        i++;
Note: See TracChangeset for help on using the changeset viewer.