Changeset 15285 for branches/DataPreprocessing Cleanup/HeuristicLab.DataPreprocessing.Views/3.4/ManipulationView.cs
- Timestamp:
- 07/26/17 14:12:27 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing Cleanup/HeuristicLab.DataPreprocessing.Views/3.4/ManipulationView.cs
r15283 r15285 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using System.Drawing; 25 24 using System.Globalization; … … 44 43 public ManipulationView() { 45 44 InitializeComponent(); 46 cmbReplaceWith.SelectedIndex = 0;47 45 tabsData.Appearance = TabAppearance.FlatButtons; 48 46 tabsData.ItemSize = new Size(0, 1); … … 56 54 () => ValidateDeleteColumnsVariance(), 57 55 () => ValidateDeleteRowsInfo(), 58 () => ValidateReplaceWith(),59 () => ValidateShuffle()60 56 }; 61 57 62 58 manipulations = new Action[] { 63 () => Content.ManipulationLogic.DeleteColumnsWithMissingValuesGreater(GetDeleteColumnsInfo()), 64 () => Content.ManipulationLogic.DeleteColumnsWithVarianceSmaller(GetDeleteColumnsVariance()), 65 () => Content.ManipulationLogic.DeleteRowsWithMissingValuesGreater(GetRowsColumnsInfo()), 66 () => ReplaceMissingValues(), 67 () => Content.ManipulationLogic.Shuffle(shuffleSeparatelyCheckbox.Checked) 59 () => Content.DeleteColumnsWithMissingValuesGreater(GetDeleteColumnsInfo()), 60 () => Content.DeleteColumnsWithVarianceSmaller(GetDeleteColumnsVariance()), 61 () => Content.DeleteRowsWithMissingValuesGreater(GetRowsColumnsInfo()), 68 62 }; 69 63 } … … 72 66 base.OnContentChanged(); 73 67 if (Content != null) { 74 cmbVariableNames.Items.Clear();75 foreach (var name in Content.ManipulationLogic.VariableNames) {76 cmbVariableNames.Items.Add(name);77 }78 cmbVariableNames.SelectedIndex = 0;79 68 CheckFilters(); 80 69 } … … 83 72 protected override void RegisterContentEvents() { 84 73 base.RegisterContentEvents(); 85 Content. ManipulationLogic.PreprocessingData.FilterChanged += FilterLogic_FilterChanged;74 Content.PreprocessingData.FilterChanged += FilterLogic_FilterChanged; 86 75 } 87 76 88 77 protected override void DeregisterContentEvents() { 89 Content. ManipulationLogic.PreprocessingData.FilterChanged -= FilterLogic_FilterChanged;78 Content.PreprocessingData.FilterChanged -= FilterLogic_FilterChanged; 90 79 base.DeregisterContentEvents(); 91 80 } … … 126 115 } 127 116 128 private void ReplaceMissingValues() {129 var missingValuesIndices = new List<int>();130 var columnIndex = cmbVariableNames.SelectedIndex;131 var columnIndices = new Dictionary<int, IList<int>> { { columnIndex, missingValuesIndices } };132 133 for (int rowIndex = 0; rowIndex < Content.ManipulationLogic.PreprocessingData.Rows; rowIndex++)134 if (Content.ManipulationLogic.PreprocessingData.IsCellEmpty(columnIndex, rowIndex))135 missingValuesIndices.Add(rowIndex);136 137 switch (cmbReplaceWith.SelectedIndex) {138 case 0: //Value139 Content.ManipulationLogic.ReplaceIndicesByValue(columnIndices, txtReplaceValue.Text);140 break;141 case 1: //Average142 Content.ManipulationLogic.ReplaceIndicesByAverageValue(columnIndices);143 break;144 case 2: //Median145 Content.ManipulationLogic.ReplaceIndicesByMedianValue(columnIndices);146 break;147 case 3: //Most Common148 Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(columnIndices);149 break;150 case 4: //Random151 Content.ManipulationLogic.ReplaceIndicesByRandomValue(columnIndices);152 break;153 }154 }155 156 117 private void ValidateDeleteColumnsInfo() { 157 118 ValidateDoubleTextBox(txtDeleteColumnsInfo.Text); 158 119 if (btnApply.Enabled) { 159 var filteredColumns = Content. ManipulationLogic.ColumnsWithMissingValuesGreater(GetDeleteColumnsInfo());120 var filteredColumns = Content.ColumnsWithMissingValuesGreater(GetDeleteColumnsInfo()); 160 121 int count = filteredColumns.Count; 161 122 int columnCount = Content.PreprocessingData.Columns; … … 167 128 sb.Append(Environment.NewLine); 168 129 sb.Append("Columns: "); 169 sb.Append(Content. ManipulationLogic.VariableNames.ElementAt(filteredColumns.ElementAt(0)));130 sb.Append(Content.PreprocessingData.VariableNames.ElementAt(filteredColumns.ElementAt(0))); 170 131 for (int i = 1; i < filteredColumns.Count; i++) { 171 string columnName = Content. ManipulationLogic.VariableNames.ElementAt(filteredColumns.ElementAt(i));132 string columnName = Content.PreprocessingData.VariableNames.ElementAt(filteredColumns.ElementAt(i)); 172 133 sb.Append(", "); 173 134 sb.Append(columnName); … … 188 149 ValidateDoubleTextBox(txtDeleteColumnsVariance.Text); 189 150 if (btnApply.Enabled) { 190 var filteredColumns = Content. ManipulationLogic.ColumnsWithVarianceSmaller(GetDeleteColumnsVariance());151 var filteredColumns = Content.ColumnsWithVarianceSmaller(GetDeleteColumnsVariance()); 191 152 int count = filteredColumns.Count; 192 153 int columnCount = Content.PreprocessingData.Columns; … … 198 159 sb.Append(Environment.NewLine); 199 160 sb.Append("Columns: "); 200 sb.Append(Content. ManipulationLogic.VariableNames.ElementAt(filteredColumns.ElementAt(0)));161 sb.Append(Content.PreprocessingData.VariableNames.ElementAt(filteredColumns.ElementAt(0))); 201 162 for (int i = 1; i < filteredColumns.Count; i++) { 202 string columnName = Content. ManipulationLogic.VariableNames.ElementAt(filteredColumns.ElementAt(i));163 string columnName = Content.PreprocessingData.VariableNames.ElementAt(filteredColumns.ElementAt(i)); 203 164 sb.Append(", "); 204 165 sb.Append(columnName); … … 219 180 ValidateDoubleTextBox(txtDeleteRowsInfo.Text); 220 181 if (btnApply.Enabled) { 221 int count = Content. ManipulationLogic.RowsWithMissingValuesGreater(GetRowsColumnsInfo()).Count;182 int count = Content.RowsWithMissingValuesGreater(GetRowsColumnsInfo()).Count; 222 183 int rowCount = Content.PreprocessingData.Rows; 223 184 lblPreviewRowsInfo.Text = count + " row" + (count > 1 || count == 0 ? "s" : "") + " of " + rowCount + " (" + string.Format("{0:F2}%", 100d / rowCount * count) + ") were detected with more than " + txtDeleteRowsInfo.Text + "% missing values."; … … 230 191 lblPreviewRowsInfo.Text = "Preview not possible yet - please input the limit above."; 231 192 } 232 }233 234 private void ValidateReplaceWith() {235 btnApply.Enabled = false;236 string replaceWith = (string)cmbReplaceWith.SelectedItem;237 int columnIndex = cmbVariableNames.SelectedIndex;238 239 if (cmbReplaceWith.SelectedIndex == 0) {240 string errorMessage;241 string replaceValue = txtReplaceValue.Text;242 if (string.IsNullOrEmpty(replaceValue)) {243 lblPreviewReplaceMissingValues.Text = "Preview not possible yet - please input the text which will be used as replacement.";244 } else if (!Content.ManipulationLogic.PreprocessingData.Validate(txtReplaceValue.Text, out errorMessage, columnIndex)) {245 lblPreviewReplaceMissingValues.Text = "Preview not possible yet - " + errorMessage;246 } else {247 btnApply.Enabled = true;248 }249 replaceWith = "\"" + replaceValue + "\"";250 } else {251 btnApply.Enabled = true;252 }253 if (btnApply.Enabled) {254 int count = 0;255 for (int rowIndex = 0; rowIndex < Content.ManipulationLogic.PreprocessingData.Rows; rowIndex++)256 if (Content.ManipulationLogic.PreprocessingData.IsCellEmpty(columnIndex, rowIndex)) count++;257 258 int cellCount = Content.PreprocessingData.Rows * Content.PreprocessingData.Columns;259 lblPreviewReplaceMissingValues.Text = count + " cell" + (count > 1 || count == 0 ? "s" : "")260 + " of " + cellCount + " (" + string.Format("{0:F2}%", 100d / cellCount * count) + ") were detected with missing values which would be replaced with " + replaceWith;261 if (count > 0) {262 lblPreviewReplaceMissingValues.Text += Environment.NewLine + Environment.NewLine + "Please press the button \"Apply Manipulation\" if you wish to perform the replacement.";263 } else {264 btnApply.Enabled = false;265 }266 }267 }268 269 private void ValidateShuffle() {270 btnApply.Enabled = true;271 lblShuffleProperties.Enabled = false;272 lblShuffleProperties.Visible = false;273 shuffleSeparatelyCheckbox.Enabled = true;274 shuffleSeparatelyCheckbox.Visible = true;275 193 } 276 194 … … 299 217 lblPreviewRowsInfo.Text = "rows successfully deleted."; 300 218 break; 301 case 3:302 lblPreviewReplaceMissingValues.Text = "missing values successfully replaced.";303 btnApply.Enabled = false;304 break;305 case 4:306 lblPreviewShuffle.Text = "dataset shuffled successfully.";307 btnApply.Enabled = false;308 break;309 219 } 310 220 } … … 331 241 ValidateDeleteRowsInfo(); 332 242 } 333 334 private void cmbReplaceWith_SelectedIndexChanged(object sender, EventArgs e) {335 bool isReplaceWithValueSelected = cmbReplaceWith.SelectedIndex == 0;336 lblValueColon.Visible = isReplaceWithValueSelected;337 txtReplaceValue.Visible = isReplaceWithValueSelected;338 ValidateReplaceWith();339 }340 341 private void txtReplaceValue_TextChanged(object sender, EventArgs e) {342 ValidateReplaceWith();343 }344 243 } 345 244 }
Note: See TracChangeset
for help on using the changeset viewer.