Changeset 12843 for branches/HiveStatistics/sources/HeuristicLab.Analysis.Statistics.Views/3.3/SampleSizeInfluenceView.cs
- Timestamp:
- 08/11/15 10:11:47 (9 years ago)
- Location:
- branches/HiveStatistics/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources
- Property svn:ignore
-
old new 23 23 bin 24 24 protoc.exe 25 obj
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/HiveStatistics/sources/HeuristicLab.Analysis.Statistics.Views/3.3/SampleSizeInfluenceView.cs
r12689 r12843 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Drawing; 24 25 using System.Linq; 25 26 using System.Windows.Forms; … … 33 34 using HeuristicLab.Optimization; 34 35 using HeuristicLab.PluginInfrastructure; 36 using ViewEventArgs = System.Windows.Forms.DataVisualization.Charting.ViewEventArgs; 35 37 36 38 namespace HeuristicLab.Analysis.Statistics.Views { … … 43 45 private const string delimiter = ";"; 44 46 45 private bool suppressUpdates = false;47 private bool suppressUpdates; 46 48 private string yAxisValue; 47 49 private Dictionary<int, Dictionary<object, double>> categoricalMapping; … … 66 68 } 67 69 public IStringConvertibleMatrix Matrix { 68 get { return this.Content; }70 get { return Content; } 69 71 } 70 72 … … 72 74 protected override void RegisterContentEvents() { 73 75 base.RegisterContentEvents(); 74 Content.ColumnNamesChanged += new EventHandler(Content_ColumnNamesChanged);75 Content.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);76 Content.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);77 Content.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);78 Content.UpdateOfRunsInProgressChanged += new EventHandler(Content_UpdateOfRunsInProgressChanged);79 Content.OptimizerNameChanged += new EventHandler(Content_AlgorithmNameChanged);76 Content.ColumnNamesChanged += Content_ColumnNamesChanged; 77 Content.ItemsAdded += Content_ItemsAdded; 78 Content.ItemsRemoved += Content_ItemsRemoved; 79 Content.CollectionReset += Content_CollectionReset; 80 Content.UpdateOfRunsInProgressChanged += Content_UpdateOfRunsInProgressChanged; 81 Content.OptimizerNameChanged += Content_AlgorithmNameChanged; 80 82 RegisterRunEvents(Content); 81 83 } 82 84 protected override void DeregisterContentEvents() { 83 85 base.DeregisterContentEvents(); 84 Content.ColumnNamesChanged -= new EventHandler(Content_ColumnNamesChanged);85 Content.ItemsAdded -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);86 Content.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);87 Content.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);88 Content.UpdateOfRunsInProgressChanged -= new EventHandler(Content_UpdateOfRunsInProgressChanged);89 Content.OptimizerNameChanged -= new EventHandler(Content_AlgorithmNameChanged);86 Content.ColumnNamesChanged -= Content_ColumnNamesChanged; 87 Content.ItemsAdded -= Content_ItemsAdded; 88 Content.ItemsRemoved -= Content_ItemsRemoved; 89 Content.CollectionReset -= Content_CollectionReset; 90 Content.UpdateOfRunsInProgressChanged -= Content_UpdateOfRunsInProgressChanged; 91 Content.OptimizerNameChanged -= Content_AlgorithmNameChanged; 90 92 DeregisterRunEvents(Content); 91 93 } … … 167 169 private void run_Changed(object sender, EventArgs e) { 168 170 if (InvokeRequired) 169 this.Invoke(new EventHandler(run_Changed), sender, e);171 Invoke(new EventHandler(run_Changed), sender, e); 170 172 else if (!suppressUpdates) UpdateDataPoints(); 171 173 } … … 185 187 186 188 private void UpdateAll() { 187 this.categoricalMapping.Clear();189 categoricalMapping.Clear(); 188 190 UpdateComboBoxes(); 189 191 UpdateDataPoints(); … … 196 198 197 199 private void UpdateSampleSizes(bool forceUpdate = false) { 198 string selectedYAxis = (string) this.yAxisComboBox.SelectedItem;200 string selectedYAxis = (string)yAxisComboBox.SelectedItem; 199 201 200 202 if (selectedYAxis != null && (xAxisTextBox.Text.Trim() == string.Empty || forceUpdate)) { … … 210 212 if (values.Any()) { 211 213 if (hypergeometricCheckBox.Checked) { 212 xAxisTextBox.Text += ((int)(values.Count() / 16))+ delimiter + " ";213 xAxisTextBox.Text += ((int)(values.Count() / 8))+ delimiter + " ";214 xAxisTextBox.Text += (int)(values.Count() / 4);214 xAxisTextBox.Text += values.Count() / 16 + delimiter + " "; 215 xAxisTextBox.Text += values.Count() / 8 + delimiter + " "; 216 xAxisTextBox.Text += values.Count() / 4; 215 217 } else { 216 xAxisTextBox.Text += ((int)(values.Count() / 4))+ delimiter + " ";217 xAxisTextBox.Text += ((int)(values.Count() / 2))+ delimiter + " ";218 xAxisTextBox.Text += ((int)(values.Count() / 4 * 3))+ delimiter + " ";219 xAxisTextBox.Text += (int)(values.Count());218 xAxisTextBox.Text += values.Count() / 4 + delimiter + " "; 219 xAxisTextBox.Text += values.Count() / 2 + delimiter + " "; 220 xAxisTextBox.Text += values.Count() / 4 * 3 + delimiter + " "; 221 xAxisTextBox.Text += values.Count(); 220 222 } 221 223 } … … 224 226 225 227 private void UpdateComboBoxes() { 226 string selectedYAxis = (string)this.yAxisComboBox.SelectedItem; 227 this.xAxisTextBox.Text = string.Empty; 228 this.yAxisComboBox.Items.Clear(); 229 if (Content != null) { 230 string[] additionalAxisDimension = Enum.GetNames(typeof(AxisDimension)); 231 UpdateSampleSizes(); 232 this.yAxisComboBox.Items.AddRange(additionalAxisDimension); 233 this.yAxisComboBox.Items.AddRange(Matrix.ColumnNames.ToArray()); 234 235 if (selectedYAxis != null && yAxisComboBox.Items.Contains(selectedYAxis)) { 236 yAxisComboBox.SelectedItem = selectedYAxis; 237 UpdateDataPoints(); 228 if (InvokeRequired) { 229 Invoke((Action)UpdateComboBoxes); 230 } else { 231 string selectedYAxis = (string)yAxisComboBox.SelectedItem; 232 xAxisTextBox.Text = string.Empty; 233 yAxisComboBox.Items.Clear(); 234 if (Content != null) { 235 string[] additionalAxisDimension = Enum.GetNames(typeof(AxisDimension)); 236 UpdateSampleSizes(); 237 yAxisComboBox.Items.AddRange(additionalAxisDimension); 238 yAxisComboBox.Items.AddRange(Matrix.ColumnNames.ToArray()); 239 240 if (selectedYAxis != null && yAxisComboBox.Items.Contains(selectedYAxis)) { 241 yAxisComboBox.SelectedItem = selectedYAxis; 242 UpdateDataPoints(); 243 } 238 244 } 239 245 } … … 241 247 242 248 private void UpdateDataPoints() { 243 this.chart.Series.Clear();244 this.seriesCache.Clear();249 chart.Series.Clear(); 250 seriesCache.Clear(); 245 251 if (Content != null) { 246 252 var usableRuns = Content.Where(r => r.Visible).ToList(); … … 253 259 } 254 260 255 foreach (Series s in this.seriesCache.Values)256 this.chart.Series.Add(s);261 foreach (Series s in seriesCache.Values) 262 chart.Series.Add(s); 257 263 258 264 UpdateStatistics(); 259 265 if (seriesCache.Count > 0) { 260 266 Series boxPlotSeries = CreateBoxPlotSeries(); 261 this.chart.Series.Add(boxPlotSeries);267 chart.Series.Add(boxPlotSeries); 262 268 } 263 269 … … 314 320 315 321 if (!yAxisComboBox.DroppedDown) 316 this.yAxisValue = (string)yAxisComboBox.SelectedItem;317 318 List<double?> yValue = usableRuns.Select(x => GetValue(x, this.yAxisValue)).ToList();322 yAxisValue = (string)yAxisComboBox.SelectedItem; 323 324 List<double?> yValue = usableRuns.Select(x => GetValue(x, yAxisValue)).ToList(); 319 325 if (yValue.Any(x => !x.HasValue)) return; 320 326 … … 335 341 v = int.Parse(ns); 336 342 vals.Add(v); 337 } catch (Exception ex) { 343 } 344 catch (Exception ex) { 338 345 if (verbose) { 339 346 ErrorHandling.ShowErrorDialog("Can't parse group sizes. Please only use numbers seperated by a " + delimiter + ". ", ex); … … 369 376 } 370 377 matrix.ColumnNames = columnNames; 371 matrix.RowNames = new string[] { "Count", "Minimum", "Maximum", "Average", "Median", "Standard Deviation", "Variance", "25th Percentile", "75th Percentile", "Lower Confidence Int.", "Upper Confidence Int." };378 matrix.RowNames = new[] { "Count", "Minimum", "Maximum", "Average", "Median", "Standard Deviation", "Variance", "25th Percentile", "75th Percentile", "Lower Confidence Int.", "Upper Confidence Int." }; 372 379 373 380 for (int i = 0; i < seriesCache.Count; i++) { … … 400 407 boxPlotSeries["BoxPlotShowUnusualValues"] = "true"; 401 408 boxPlotSeries["PointWidth"] = "0.4"; 402 boxPlotSeries.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.VerticalCenter;403 boxPlotSeries.BackSecondaryColor = System.Drawing.Color.FromArgb(130, 224, 64, 10);404 boxPlotSeries.BorderColor = System.Drawing.Color.FromArgb(64, 64, 64);405 boxPlotSeries.Color = System.Drawing.Color.FromArgb(224, 64, 10);409 boxPlotSeries.BackGradientStyle = GradientStyle.VerticalCenter; 410 boxPlotSeries.BackSecondaryColor = Color.FromArgb(130, 224, 64, 10); 411 boxPlotSeries.BorderColor = Color.FromArgb(64, 64, 64); 412 boxPlotSeries.Color = Color.FromArgb(224, 64, 10); 406 413 407 414 return boxPlotSeries; … … 414 421 415 422 if (!yAxisComboBox.DroppedDown) 416 this.yAxisValue = (string)yAxisComboBox.SelectedItem;423 yAxisValue = (string)yAxisComboBox.SelectedItem; 417 424 418 425 xValue = idx; 419 yValue = GetValue(run, this.yAxisValue);426 yValue = GetValue(run, yAxisValue); 420 427 421 428 if (yValue.HasValue) { 422 if (! this.seriesCache.ContainsKey(xValue))429 if (!seriesCache.ContainsKey(xValue)) 423 430 seriesCache[xValue] = new Series(xValue.ToString()); 424 431 … … 439 446 AxisDimension axisDimension = (AxisDimension)Enum.Parse(typeof(AxisDimension), columnName); 440 447 return GetValue(run, axisDimension); 441 } else { 442 int columnIndex = Matrix.ColumnNames.ToList().IndexOf(columnName); 443 IItem value = Content.GetValue(run, columnIndex); 444 if (value == null) 445 return null; 446 447 DoubleValue doubleValue = value as DoubleValue; 448 IntValue intValue = value as IntValue; 449 TimeSpanValue timeSpanValue = value as TimeSpanValue; 450 double? ret = null; 451 if (doubleValue != null) { 452 if (!double.IsNaN(doubleValue.Value) && !double.IsInfinity(doubleValue.Value)) 453 ret = doubleValue.Value; 454 } else if (intValue != null) 455 ret = intValue.Value; 456 else if (timeSpanValue != null) { 457 ret = timeSpanValue.Value.TotalSeconds; 458 } else 459 ret = GetCategoricalValue(columnIndex, value.ToString()); 460 461 return ret; 462 } 448 } 449 int columnIndex = Matrix.ColumnNames.ToList().IndexOf(columnName); 450 IItem value = Content.GetValue(run, columnIndex); 451 if (value == null) 452 return null; 453 454 DoubleValue doubleValue = value as DoubleValue; 455 IntValue intValue = value as IntValue; 456 TimeSpanValue timeSpanValue = value as TimeSpanValue; 457 double? ret = null; 458 if (doubleValue != null) { 459 if (!double.IsNaN(doubleValue.Value) && !double.IsInfinity(doubleValue.Value)) 460 ret = doubleValue.Value; 461 } else if (intValue != null) 462 ret = intValue.Value; 463 else if (timeSpanValue != null) { 464 ret = timeSpanValue.Value.TotalSeconds; 465 } else 466 ret = GetCategoricalValue(columnIndex, value.ToString()); 467 468 return ret; 463 469 } 464 470 private double GetCategoricalValue(int dimension, string value) { 465 if (! this.categoricalMapping.ContainsKey(dimension)) {466 this.categoricalMapping[dimension] = new Dictionary<object, double>();471 if (!categoricalMapping.ContainsKey(dimension)) { 472 categoricalMapping[dimension] = new Dictionary<object, double>(); 467 473 var orderedCategories = Content.Where(r => r.Visible && Content.GetValue(r, dimension) != null).Select(r => Content.GetValue(r, dimension).ToString()) 468 474 .Distinct().OrderBy(x => x, new NaturalStringComparer()); 469 475 int count = 1; 470 476 foreach (var category in orderedCategories) { 471 this.categoricalMapping[dimension].Add(category, count);477 categoricalMapping[dimension].Add(category, count); 472 478 count++; 473 479 } 474 480 } 475 return this.categoricalMapping[dimension][value];481 return categoricalMapping[dimension][value]; 476 482 } 477 483 private double GetValue(IRun run, AxisDimension axisDimension) { … … 483 489 } 484 490 default: { 485 throw new ArgumentException("No handling strategy for " + axisDimension .ToString()+ " is defined.");491 throw new ArgumentException("No handling strategy for " + axisDimension + " is defined."); 486 492 } 487 493 } … … 492 498 #region GUI events 493 499 private void UpdateNoRunsVisibleLabel() { 494 if ( this.chart.Series.Count > 0) {500 if (chart.Series.Count > 0) { 495 501 noRunsLabel.Visible = false; 496 502 showStatisticsCheckBox.Enabled = true; … … 517 523 } 518 524 private void UpdateAxisLabels() { 519 Axis xAxis = this.chart.ChartAreas[BoxPlotChartAreaName].AxisX;520 Axis yAxis = this.chart.ChartAreas[BoxPlotChartAreaName].AxisY;525 Axis xAxis = chart.ChartAreas[BoxPlotChartAreaName].AxisX; 526 Axis yAxis = chart.ChartAreas[BoxPlotChartAreaName].AxisY; 521 527 int axisDimensionCount = Enum.GetNames(typeof(AxisDimension)).Count(); 522 528 … … 529 535 } 530 536 531 private void chart_AxisViewChanged(object sender, System.Windows.Forms.DataVisualization.Charting.ViewEventArgs e) {532 this.UpdateAxisLabels();537 private void chart_AxisViewChanged(object sender, ViewEventArgs e) { 538 UpdateAxisLabels(); 533 539 } 534 540 … … 551 557 } 552 558 } else if (dimension > 0 && Content.GetValue(0, dimension) is TimeSpanValue) { 553 this.chart.ChartAreas[0].RecalculateAxesScale();554 Axis correspondingAxis = this.chart.ChartAreas[0].Axes.Where(x => x.Name == axis.Name).SingleOrDefault();559 chart.ChartAreas[0].RecalculateAxesScale(); 560 Axis correspondingAxis = chart.ChartAreas[0].Axes.Where(x => x.Name == axis.Name).SingleOrDefault(); 555 561 if (correspondingAxis == null) 556 562 correspondingAxis = axis; 557 563 for (double i = correspondingAxis.Minimum; i <= correspondingAxis.Maximum; i += correspondingAxis.LabelStyle.Interval) { 558 564 TimeSpan time = TimeSpan.FromSeconds(i); 559 string x = string.Format("{0:00}:{1:00}:{2:00}", (int)time.Hours, time.Minutes, time.Seconds);565 string x = string.Format("{0:00}:{1:00}:{2:00}", time.Hours, time.Minutes, time.Seconds); 560 566 axis.CustomLabels.Add(i - correspondingAxis.LabelStyle.Interval / 2, i + correspondingAxis.LabelStyle.Interval / 2, x); 561 567 } … … 580 586 string newTooltipText = string.Empty; 581 587 string oldTooltipText; 582 HitTestResult h = this.chart.HitTest(e.X, e.Y);588 HitTestResult h = chart.HitTest(e.X, e.Y); 583 589 if (h.ChartElementType == ChartElementType.AxisLabels) { 584 590 newTooltipText = ((CustomLabel)h.Object).ToolTip; 585 591 } 586 592 587 oldTooltipText = t his.tooltip.GetToolTip(chart);593 oldTooltipText = tooltip.GetToolTip(chart); 588 594 if (newTooltipText != oldTooltipText) 589 t his.tooltip.SetToolTip(chart, newTooltipText);595 tooltip.SetToolTip(chart, newTooltipText); 590 596 } 591 597 #endregion
Note: See TracChangeset
for help on using the changeset viewer.