Changeset 9713 for branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/ChartAnalysisView.cs
- Timestamp:
- 07/17/13 13:32:08 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/ChartAnalysisView.cs
r9706 r9713 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading.Tasks; 25 26 using System.Windows.Forms; 26 27 using HeuristicLab.Common; … … 28 29 using HeuristicLab.Data; 29 30 using HeuristicLab.MainForm; 31 using HeuristicLab.MainForm.WindowsForms; 30 32 using HeuristicLab.Optimization; 31 33 using HeuristicLab.PluginInfrastructure; 32 34 33 35 namespace HeuristicLab.Analysis.Statistics { 34 [View("RunCollection Chart Analysis View")]36 [View("RunCollection Chart Analysis")] 35 37 [Content(typeof(RunCollection), false)] 36 38 public sealed partial class ChartAnalysisView : ItemView { … … 46 48 47 49 private List<IRun> runs; 50 private Progress progress; 51 private ProgressView progressView; 52 private bool valuesAdded = false; 48 53 49 54 public ChartAnalysisView() { 50 55 InitializeComponent(); 56 progress = new Progress() { 57 CanBeCanceled = false, 58 ProgressState = ProgressState.Finished 59 }; 60 progressView = new ProgressView(this, progress); 61 51 62 stringConvertibleMatrixView.DataGridView.RowHeaderMouseDoubleClick += new DataGridViewCellMouseEventHandler(DataGridView_RowHeaderMouseDoubleClick); 52 63 … … 67 78 components.Dispose(); 68 79 } 80 if (disposing) 81 progressView.Dispose(); 69 82 base.Dispose(disposing); 70 83 } … … 98 111 99 112 private void Content_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) { 100 RebuildDataTable ();113 RebuildDataTableAsync(); 101 114 } 102 115 103 116 private void Content_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) { 104 RebuildDataTable ();117 RebuildDataTableAsync(); 105 118 } 106 119 107 120 private void Content_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) { 108 RebuildDataTable ();121 RebuildDataTableAsync(); 109 122 } 110 123 111 124 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; 114 130 } 115 131 } … … 133 149 134 150 private void dataRowComboBox_SelectedIndexChanged(object sender, EventArgs e) { 135 RebuildDataTable ();151 RebuildDataTableAsync(); 136 152 } 137 153 138 154 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() { 139 172 string resultName = (string)dataTableComboBox.SelectedItem; 140 173 string rowName = (string)dataRowComboBox.SelectedItem; … … 171 204 } 172 205 } 206 valuesAdded = true; 173 207 Content.UpdateOfRunsInProgress = false; 174 208 } … … 200 234 } 201 235 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 202 253 private void RebuildDataTable() { 203 254 string resultName = (string)dataTableComboBox.SelectedItem; 204 255 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" }; 206 259 207 260 runs = Content.Where(x => x.Results.ContainsKey(resultName) && x.Visible).ToList(); … … 226 279 double percentile25 = values.Percentile(0.25); 227 280 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);232 281 double lowerAvg = values.OrderBy(x => x).Take((int)(values.Count() * 0.25)).Average(); 233 282 double upperAvg = values.OrderByDescending(x => x).Take((int)(values.Count() * 0.25)).Average(); 234 283 double firstAvg = values.Take((int)(values.Count() * 0.25)).Average(); 235 284 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); 236 289 237 290 dt[i, 0] = cnt; … … 244 297 dt[i, 7] = percentile25; 245 298 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; 252 307 253 308 i++;
Note: See TracChangeset
for help on using the changeset viewer.