Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/11/15 13:37:32 (9 years ago)
Author:
ascheibe
Message:

#2270 and #2354: merged r12173, r12458, r12077, r12599, r12613, r12112, r12116, r12117, r12131, r12631, r12672, r12684, r12690, r12692 into stable

Location:
stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Analysis.Statistics.Views/3.3/ChartAnalysisView.cs

    r12009 r12725  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using System.Threading;
    2526using System.Threading.Tasks;
    2627using System.Windows.Forms;
     
    5253    private bool valuesAdded = false;
    5354    private bool suppressUpdates = false;
     55    private SemaphoreSlim sem = new SemaphoreSlim(1, 1);
    5456
    5557    public ChartAnalysisView() {
     
    108110
    109111    void Content_RowsChanged(object sender, EventArgs e) {
    110       RebuildDataTableAsync();
     112      if (suppressUpdates) return;
     113      if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_RowsChanged, sender, e);
     114      else {
     115        RebuildDataTableAsync();
     116      }
    111117    }
    112118
    113119    void Content_ColumnsChanged(object sender, EventArgs e) {
    114       RebuildDataTableAsync();
     120      if (suppressUpdates) return;
     121      if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_ColumnsChanged, sender, e);
     122      else {
     123        UpdateDataTableComboBox();
     124        RebuildDataTableAsync();
     125      }
    115126    }
    116127
    117128    private void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    118       UpdateComboboxes();
    119       RebuildDataTableAsync();
     129      if (suppressUpdates) return;
     130      if (InvokeRequired) Invoke((Action<object, CollectionItemsChangedEventArgs<IRun>>)Content_CollectionReset, sender, e);
     131      else {
     132        UpdateComboboxes();
     133        RebuildDataTableAsync();
     134      }
    120135    }
    121136
    122137    private void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) {
    123       suppressUpdates = Content.UpdateOfRunsInProgress;
    124 
    125       if (!suppressUpdates && !valuesAdded) {
    126         RebuildDataTableAsync();
    127       }
    128       if (valuesAdded) {
    129         valuesAdded = false;
     138      if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_UpdateOfRunsInProgressChanged, sender, e);
     139      else {
     140        suppressUpdates = Content.UpdateOfRunsInProgress;
     141
     142        if (!suppressUpdates && !valuesAdded) {
     143          UpdateDataTableComboBox();
     144          RebuildDataTableAsync();
     145        }
     146        if (valuesAdded) {
     147          valuesAdded = false;
     148        }
    130149      }
    131150    }
     
    149168
    150169    private void dataRowComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     170      if (suppressUpdates) return;
    151171      RebuildDataTableAsync();
    152172    }
     
    246266
    247267    private void RebuildDataTableAsync() {
    248       progress = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Calculating values...");
    249 
    250268      string resultName = (string)dataTableComboBox.SelectedItem;
     269      if (string.IsNullOrEmpty(resultName)) return;
     270
    251271      string rowName = (string)dataRowComboBox.SelectedItem;
    252272
    253       var task = Task.Factory.StartNew(() => RebuildDataTable(resultName, rowName));
     273      var task = Task.Factory.StartNew(() => {
     274        sem.Wait();
     275        progress = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Calculating values...");
     276        RebuildDataTable(resultName, rowName);
     277      });
    254278
    255279      task.ContinueWith((t) => {
    256280        MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
    257281        ErrorHandling.ShowErrorDialog("An error occured while calculating values. ", t.Exception);
     282        sem.Release();
    258283      }, TaskContinuationOptions.OnlyOnFaulted);
    259284
    260285      task.ContinueWith((t) => {
    261286        MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     287        sem.Release();
    262288      }, TaskContinuationOptions.OnlyOnRanToCompletion);
    263289    }
     
    289315        double percentile25 = values.Percentile(0.25);
    290316        double percentile75 = values.Percentile(0.75);
    291         double lowerAvg = values.OrderBy(x => x).Take((int)(values.Count() * 0.25)).Average();
    292         double upperAvg = values.OrderByDescending(x => x).Take((int)(values.Count() * 0.25)).Average();
    293         double firstAvg = values.Take((int)(values.Count() * 0.25)).Average();
    294         double lastAvg = values.Skip((int)(values.Count() * 0.75)).Average();
     317        double lowerAvg = values.Count() > 4 ? values.OrderBy(x => x).Take((int)(values.Count() * 0.25)).Average() : double.NaN;
     318        double upperAvg = values.Count() > 4 ? values.OrderByDescending(x => x).Take((int)(values.Count() * 0.25)).Average() : double.NaN;
     319        double firstAvg = values.Count() > 4 ? values.Take((int)(values.Count() * 0.25)).Average() : double.NaN;
     320        double lastAvg = values.Count() > 4 ? values.Skip((int)(values.Count() * 0.75)).Average() : double.NaN;
    295321        double slope, intercept, r;
    296322        llsFitting.Calculate(values, out slope, out intercept);
Note: See TracChangeset for help on using the changeset viewer.