Changeset 13838
- Timestamp:
- 05/09/16 13:47:13 (8 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/DataCompletenessView.cs
r13502 r13838 23 23 using System.Collections.Generic; 24 24 using System.Drawing; 25 using System.Linq; 25 26 using System.Windows.Forms; 26 27 using System.Windows.Forms.DataVisualization.Charting; … … 33 34 [Content(typeof(DataCompletenessChartContent), true)] 34 35 public partial class DataCompletenessView : ItemView { 35 36 //list of columns, bool indicates wether the cell is a missing value or not37 private List<List<bool>> matrix = new List<List<bool>>();38 36 //series colors 39 private static Color colorNonMissingVal= Color.CornflowerBlue;40 private static Color colorMissingVal= Color.Orange;37 private static readonly Color colorNonMissingValue = Color.CornflowerBlue; 38 private static readonly Color colorMissingValue = Color.Orange; 41 39 42 40 public new DataCompletenessChartContent Content { … … 44 42 set { base.Content = value; } 45 43 } 46 47 44 48 45 public DataCompletenessView() { … … 52 49 protected override void OnContentChanged() { 53 50 base.OnContentChanged(); 54 if (Content != null) { 55 InitData(); 56 } 51 if (Content == null) return; 52 InitData(); 57 53 } 58 54 59 55 private void InitData() { 60 56 IDictionary<int, IList<int>> missingValueIndices = Content.SearchLogic.GetMissingValueIndices(); 61 for (int i = 0; i < Content.SearchLogic.Columns; i++) { 62 //append column 63 List<bool> column = new List<bool>(); 64 for (int j = 0; j < Content.SearchLogic.Rows; j++) { 65 column.Add(missingValueIndices[i].Contains(j)); 66 } 67 matrix.Add(column); 57 58 bool[,] valueMissing = new bool[Content.SearchLogic.Rows, Content.SearchLogic.Columns]; 59 foreach (var columnMissingValues in missingValueIndices) { 60 var column = columnMissingValues.Key; 61 foreach (var missingValueIndex in columnMissingValues.Value) 62 valueMissing[missingValueIndex, column] = true; 68 63 } 69 List<List<int>> yValuesPerColumn = ProcessMatrixForCharting(matrix, missingValueIndices); 64 65 var yValuesPerColumn = ProcessMatrixForCharting(valueMissing); 70 66 PrepareChart(); 71 67 CreateSeries(yValuesPerColumn); … … 95 91 96 92 private void CreateSeries(List<List<int>> yValuesPerColumn) { 93 chart.Series.SuspendUpdates(); 97 94 //prepare series 98 95 int seriesCount = DetermineSeriesCount(yValuesPerColumn); 99 96 for (int i = 0; i < seriesCount; i++) { 100 chart.Series.Add(CreateSeriesName(i)); 101 Series series = chart.Series[CreateSeriesName(i)]; 97 Series series = new Series(CreateSeriesName(i)); 102 98 series.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn; 103 99 series.IsVisibleInLegend = false; 104 100 series["PointWidth"] = "1.0"; 105 if (i % 2 == 0) { 106 if (i == 0) //show legend for non missing values only once 107 series.IsVisibleInLegend = true; 108 series.Color = colorNonMissingVal; 109 } else { 110 if (i == 1) //show legend for missing values only once 111 series.IsVisibleInLegend = true; 112 series.Color = colorMissingVal; 113 } 101 series.IsVisibleInLegend = i < 2; //only first two series are visible, non-missing and missing values 102 series.Color = i % 2 == 0 ? colorNonMissingValue : colorMissingValue; 103 104 var values = yValuesPerColumn.Select(y => i < y.Count ? y[i] : 0).ToArray(); 105 series.Points.DataBindY(values); 106 chart.Series.Add(series); 114 107 } 115 //fill series 116 for (int i = 0; i < yValuesPerColumn.Count; i++) { 117 List<int> column = yValuesPerColumn[i]; 118 for (int j = 0; j < seriesCount; j++) { 119 if (column.Count - 1 < j) { 120 chart.Series[CreateSeriesName(j)].Points.AddY(0); 121 } else { 122 chart.Series[CreateSeriesName(j)].Points.AddY(column[j]); 123 } 124 } 125 } 108 chart.Series.ResumeUpdates(); 126 109 } 127 110 … … 136 119 #region data_preparation_for_chartseries 137 120 private int DetermineSeriesCount(List<List<int>> yValuesPerColumn) { 138 int highest = 0; 139 foreach (List<int> values in yValuesPerColumn) { 140 highest = Math.Max(values.Count, highest); 141 } 142 return highest; 121 return yValuesPerColumn.Max(values => values.Count); 143 122 } 144 123 145 private List<List<int>> ProcessMatrixForCharting(List<List<bool>> matrix, IDictionary<int, IList<int>> missingValueIndices) { 146 List<List<int>> columnsYValues = new List<List<int>>(); 147 for (int i = 0; i < matrix.Count; i++) //column 148 { 149 List<int> yValues = new List<int>(); 150 List<bool> column = matrix[i]; 124 private List<List<int>> ProcessMatrixForCharting(bool[,] matrix) { 125 var columnsYValues = new List<List<int>>(); 126 for (int column = 0; column < matrix.GetLength(1); column++) { 127 var yValues = new List<int>(); 151 128 bool missingState = false; 152 129 int valueCount = 0; 153 for (int j = 0; j < column.Count; j++) { 154 if (missingState == missingValueIndices[i].Contains(j)) { 130 131 for (int row = 0; row < matrix.GetLength(0); row++) { 132 if (missingState == matrix[row, column]) { 155 133 valueCount++; 156 134 } else { … … 165 143 yValues.Add(0); 166 144 } 167 //yValues.Reverse();168 145 columnsYValues.Add(yValues); 169 146 } -
trunk/sources/HeuristicLab.DataPreprocessing/3.4/Logic/SearchLogic.cs
r13508 r13838 93 93 } 94 94 95 public IList<int> GetMissingValueIndices(int columnIndex) { 96 int index = 0; 97 var indices = new List<int>(); 98 99 if (MissingValueIndicies.ContainsKey(columnIndex)) { 100 return MissingValueIndicies[columnIndex]; 101 } 102 103 if (preprocessingData.VariableHasType<double>(columnIndex)) { 104 foreach (var v in preprocessingData.GetValues<double>(columnIndex)) { 105 if (double.IsNaN(v)) indices.Add(index); 106 index++; 107 } 108 } else if (preprocessingData.VariableHasType<string>(columnIndex)) { 109 foreach (var v in preprocessingData.GetValues<string>(columnIndex)) { 110 if (string.IsNullOrEmpty(v)) indices.Add(index); 111 index++; 112 } 113 } else if (preprocessingData.VariableHasType<DateTime>(columnIndex)) { 114 foreach (var v in preprocessingData.GetValues<DateTime>(columnIndex)) { 115 if (DateTime.MinValue.Equals(v)) indices.Add(index); 116 index++; 117 } 118 } else { 119 throw new ArgumentException("column " + columnIndex + " contains a non supported type."); 120 } 121 122 MissingValueIndicies[columnIndex] = indices; 123 return MissingValueIndicies[columnIndex]; 124 } 125 126 95 127 public bool IsMissingValue(int columnIndex, int rowIndex) { 96 128 if (preprocessingData.VariableHasType<double>(columnIndex)) { … … 103 135 throw new ArgumentException("cell in column " + columnIndex + " and row index " + rowIndex + " contains a non supported type."); 104 136 } 105 }106 107 public IList<int> GetMissingValueIndices(int columnIndex) {108 if (!MissingValueIndicies.ContainsKey(columnIndex)) {109 if (preprocessingData.VariableHasType<double>(columnIndex)) {110 MissingValueIndicies[columnIndex] = GetMissingValueIndices<double>(columnIndex);111 } else if (preprocessingData.VariableHasType<string>(columnIndex)) {112 MissingValueIndicies[columnIndex] = GetMissingValueIndices<string>(columnIndex);113 } else if (preprocessingData.VariableHasType<DateTime>(columnIndex)) {114 MissingValueIndicies[columnIndex] = GetMissingValueIndices<DateTime>(columnIndex);115 } else {116 throw new ArgumentException("column " + columnIndex + " contains a non supported type.");117 }118 }119 return MissingValueIndicies[columnIndex];120 }121 122 private IList<int> GetMissingValueIndices<T>(int columnIndex) {123 List<int> missingIndices = new List<int>();124 125 for (int row = 0; row < preprocessingData.Rows; ++row) {126 if (IsMissingValue(columnIndex, row)) {127 missingIndices.Add(row);128 }129 }130 131 return missingIndices;132 137 } 133 138
Note: See TracChangeset
for help on using the changeset viewer.