Changeset 9378
- Timestamp:
- 04/18/13 13:07:15 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/ChartAnalysisView.cs
r9377 r9378 44 44 } 45 45 46 private List<IRun> runs; 47 46 48 public ChartAnalysisView() { 47 49 InitializeComponent(); … … 77 79 Content.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved); 78 80 Content.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset); 79 80 RegisterRunEvents(Content); 81 } 82 83 private void RegisterRunEvents(IEnumerable<IRun> runs) { 84 foreach (IRun run in runs) 85 run.Changed += new EventHandler(run_Changed); 81 Content.UpdateOfRunsInProgressChanged += Content_UpdateOfRunsInProgressChanged; 86 82 } 87 83 … … 91 87 Content.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved); 92 88 Content.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset); 93 94 DeregisterRunEvents(Content); 95 } 96 97 private void DeregisterRunEvents(IEnumerable<IRun> runs) { 98 foreach (IRun run in runs) 99 run.Changed -= new EventHandler(run_Changed); 89 Content.UpdateOfRunsInProgressChanged -= Content_UpdateOfRunsInProgressChanged; 100 90 } 101 91 102 92 private void Content_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) { 103 DeregisterRunEvents(e.OldItems); 104 RegisterRunEvents(e.Items); 105 RebuildCombinedDataTable(); 93 RebuildDataTable(); 106 94 } 107 95 108 96 private void Content_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) { 109 DeregisterRunEvents(e.Items); 110 RebuildCombinedDataTable(); 97 RebuildDataTable(); 111 98 } 112 99 113 100 private void Content_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) { 114 RegisterRunEvents(e.Items); 115 RebuildCombinedDataTable(); 116 } 117 118 private void run_Changed(object sender, EventArgs e) { 119 if (InvokeRequired) 120 this.Invoke(new EventHandler(run_Changed), sender, e); 121 else { 122 if (!Content.UpdateOfRunsInProgress) { 123 IRun run = (IRun)sender; 124 UpdateRun(run); 125 } 101 RebuildDataTable(); 102 } 103 104 void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) { 105 if (!Content.UpdateOfRunsInProgress) { 106 RebuildDataTable(); 126 107 } 127 108 } … … 131 112 void DataGridView_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { 132 113 if (e.RowIndex >= 0) { 133 IRun run = Content.ElementAt(stringConvertibleMatrixView.GetRowIndex(e.RowIndex));114 IRun run = runs[stringConvertibleMatrixView.GetRowIndex(e.RowIndex)]; 134 115 IContentView view = MainFormManager.MainForm.ShowContent(run); 135 116 if (view != null) { … … 145 126 146 127 private void dataRowComboBox_SelectedIndexChanged(object sender, EventArgs e) { 147 Rebuild CombinedDataTable();128 RebuildDataTable(); 148 129 } 149 130 … … 151 132 string resultName = (string)dataTableComboBox.SelectedItem; 152 133 string rowName = (string)dataRowComboBox.SelectedItem; 153 var runs = Content.Where(x => x.Results.ContainsKey(resultName) && x.Visible); 154 155 foreach (Run run in runs) { 134 135 foreach (IRun run in runs) { 156 136 DataTable resTable = (DataTable)run.Results[resultName]; 157 137 DataRow row = resTable.Rows[rowName]; … … 173 153 string resultName = (string)dataTableComboBox.SelectedItem; 174 154 string rowName = (string)dataRowComboBox.SelectedItem; 175 var runs = Content.Where(x => x.Results.ContainsKey(resultName) && x.Visible); 176 StringMatrix sm = (StringMatrix)stringConvertibleMatrixView.Content; 155 DoubleMatrix sm = (DoubleMatrix)stringConvertibleMatrixView.Content; 177 156 178 157 Content.UpdateOfRunsInProgress = true; 179 158 for (int i = 0; i < runs.Count(); i++) { 180 IRun run = runs .ElementAt(i);159 IRun run = runs[i]; 181 160 182 161 for (int j = 0; j < sm.ColumnNames.Count(); j++) { 183 string newResultName = resultName + " " + rowName + " " + sm.ColumnNames.ElementAt(j); 184 if (!run.Results.ContainsKey(newResultName)) 185 run.Results.Add(new KeyValuePair<string, Core.IItem>(newResultName, new DoubleValue(double.Parse(sm[i, j])))); 162 if (stringConvertibleMatrixView.DataGridView.Columns[j].Visible) { 163 string newResultName = resultName + " " + rowName + " " + sm.ColumnNames.ElementAt(j); 164 if (!run.Results.ContainsKey(newResultName)) { 165 run.Results.Add(new KeyValuePair<string, Core.IItem>(newResultName, new DoubleValue(sm[i, j]))); 166 } 167 } 186 168 } 187 169 } 188 170 Content.UpdateOfRunsInProgress = false; 189 //update column names of run collection190 Content.Modify();191 171 } 192 172 #endregion 193 194 private void UpdateRun(IRun run) {195 //TODO: hacky di hack... this is baaaadddd196 RebuildCombinedDataTable();197 }198 173 199 174 private void UpdateDataRowComboBox() { … … 222 197 } 223 198 224 private void Rebuild CombinedDataTable() {199 private void RebuildDataTable() { 225 200 string resultName = (string)dataTableComboBox.SelectedItem; 226 201 string rowName = (string)dataRowComboBox.SelectedItem; 227 202 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 %" }; 228 203 229 var runs = Content.Where(x => x.Results.ContainsKey(resultName) && x.Visible); 230 231 StringMatrix dt = new StringMatrix(runs.Count(), columnNames.Count()); 204 runs = Content.Where(x => x.Results.ContainsKey(resultName) && x.Visible).ToList(); 205 DoubleMatrix dt = new DoubleMatrix(runs.Count(), columnNames.Count()); 232 206 dt.RowNames = runs.Select(x => x.Name); 233 207 dt.ColumnNames = columnNames; … … 257 231 double lastAvg = values.Skip((int)(values.Count() * 0.75)).Average(); 258 232 259 dt[i, 0] = cnt .ToString();260 dt[i, 1] = min .ToString();261 dt[i, 2] = max .ToString();262 dt[i, 3] = avg .ToString();263 dt[i, 4] = median .ToString();264 dt[i, 5] = stdDev .ToString();265 dt[i, 6] = variance .ToString();266 dt[i, 7] = percentile25 .ToString();267 dt[i, 8] = percentile75 .ToString();268 dt[i, 9] = k .ToString();269 dt[i, 10] = r .ToString();270 dt[i, 11] = upperAvg .ToString();271 dt[i, 12] = lowerAvg .ToString();272 dt[i, 13] = firstAvg .ToString();273 dt[i, 14] = lastAvg .ToString();233 dt[i, 0] = cnt; 234 dt[i, 1] = min; 235 dt[i, 2] = max; 236 dt[i, 3] = avg; 237 dt[i, 4] = median; 238 dt[i, 5] = stdDev; 239 dt[i, 6] = variance; 240 dt[i, 7] = percentile25; 241 dt[i, 8] = percentile75; 242 dt[i, 9] = k; 243 dt[i, 10] = r; 244 dt[i, 11] = upperAvg; 245 dt[i, 12] = lowerAvg; 246 dt[i, 13] = firstAvg; 247 dt[i, 14] = lastAvg; 274 248 275 249 i++; 276 250 } 277 278 251 stringConvertibleMatrixView.Content = dt; 252 253 for (i = 0; i < runs.Count(); i++) { 254 stringConvertibleMatrixView.DataGridView.Rows[i].DefaultCellStyle.ForeColor = runs[i].Color; 255 } 279 256 } 280 257 }
Note: See TracChangeset
for help on using the changeset viewer.