[10709] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
[10905] | 23 | using System.Collections.Generic;
|
---|
[10709] | 24 | using System.Drawing;
|
---|
| 25 | using System.Windows.Forms;
|
---|
| 26 | using HeuristicLab.Core.Views;
|
---|
| 27 | using HeuristicLab.MainForm;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
| 30 |
|
---|
| 31 | [View("Manipulation Chart View")]
|
---|
[10712] | 32 | [Content(typeof(ManipulationContent), true)]
|
---|
[10709] | 33 | public partial class ManipulationView : ItemView {
|
---|
| 34 |
|
---|
| 35 | private Action[] validators;
|
---|
| 36 | private Action[] manipulations;
|
---|
| 37 |
|
---|
| 38 | public ManipulationView() {
|
---|
| 39 | InitializeComponent();
|
---|
[10776] | 40 | cmbReplaceWith.SelectedIndex = 0;
|
---|
[10709] | 41 | tabsData.Appearance = TabAppearance.FlatButtons;
|
---|
| 42 | tabsData.ItemSize = new Size(0, 1);
|
---|
| 43 | tabsData.SizeMode = TabSizeMode.Fixed;
|
---|
| 44 | tabsPreview.Appearance = TabAppearance.FlatButtons;
|
---|
| 45 | tabsPreview.ItemSize = new Size(0, 1);
|
---|
| 46 | tabsPreview.SizeMode = TabSizeMode.Fixed;
|
---|
| 47 |
|
---|
| 48 | validators = new Action[] {
|
---|
[10737] | 49 | ()=>validateDeleteColumnsInfo(),
|
---|
| 50 | ()=>validateDeleteColumnsVariance(),
|
---|
| 51 | ()=>validateDeleteRowsInfo(),
|
---|
[10776] | 52 | ()=>validateReplaceWith(),
|
---|
[10737] | 53 | ()=>{btnApply.Enabled = true; lblPreviewShuffle.Text = "Data will be shuffled randomly - preview not possible";} //shuffle
|
---|
[10709] | 54 | };
|
---|
[10737] | 55 |
|
---|
[10709] | 56 | manipulations = new Action[] {
|
---|
[10737] | 57 | ()=>Content.ManipulationLogic.DeleteColumnsWithMissingValuesGreater(getDeleteColumnsInfo()),
|
---|
| 58 | ()=>Content.ManipulationLogic.DeleteColumnsWithVarianceSmaller(getDeleteColumnsVariance()),
|
---|
| 59 | ()=>Content.ManipulationLogic.DeleteRowsWithMissingValuesGreater(getRowsColumnsInfo()),
|
---|
[10776] | 60 | ()=>replaceMissingValues(),
|
---|
[10709] | 61 | ()=>Content.ManipulationLogic.ShuffleWithRanges()
|
---|
| 62 | };
|
---|
[10905] | 63 |
|
---|
[10709] | 64 | }
|
---|
| 65 |
|
---|
[10905] | 66 | protected override void OnContentChanged() {
|
---|
| 67 | base.OnContentChanged();
|
---|
| 68 | if (Content != null) {
|
---|
| 69 | cmbVariableNames.Items.Clear();
|
---|
[11002] | 70 | foreach (var name in Content.ManipulationLogic.VariableNames) {
|
---|
[10905] | 71 | cmbVariableNames.Items.Add(name);
|
---|
| 72 | }
|
---|
| 73 | cmbVariableNames.SelectedIndex = 0;
|
---|
[10977] | 74 | CheckFilters();
|
---|
[10905] | 75 | }
|
---|
| 76 | }
|
---|
| 77 |
|
---|
[10737] | 78 | protected override void RegisterContentEvents() {
|
---|
| 79 | base.RegisterContentEvents();
|
---|
| 80 | Content.ManipulationLogic.Changed += Content_Changed;
|
---|
[10970] | 81 | Content.FilterLogic.FilterChanged += FilterLogic_FilterChanged;
|
---|
[10737] | 82 | }
|
---|
| 83 |
|
---|
| 84 | protected override void DeregisterContentEvents() {
|
---|
| 85 | base.DeregisterContentEvents();
|
---|
| 86 | Content.ManipulationLogic.Changed -= Content_Changed;
|
---|
[10970] | 87 | Content.FilterLogic.FilterChanged -= FilterLogic_FilterChanged;
|
---|
[10737] | 88 | }
|
---|
| 89 |
|
---|
[10970] | 90 | private void FilterLogic_FilterChanged(object sender, EventArgs e) {
|
---|
| 91 | if (Content != null) {
|
---|
[10977] | 92 | CheckFilters();
|
---|
[10970] | 93 | }
|
---|
| 94 | }
|
---|
| 95 |
|
---|
[10977] | 96 | private void CheckFilters() {
|
---|
[10970] | 97 | if (Content.FilterLogic.IsFiltered) {
|
---|
| 98 | tabsPreview.SelectedIndex = 0;
|
---|
| 99 | lstMethods.Enabled = false;
|
---|
| 100 | tabsData.Enabled = false;
|
---|
| 101 | tabsPreview.Enabled = false;
|
---|
| 102 | lblPreviewInActive.Visible = true;
|
---|
| 103 | btnApply.Enabled = false;
|
---|
| 104 | } else {
|
---|
| 105 | lblPreviewInActive.Visible = false;
|
---|
| 106 | tabsData.Enabled = true;
|
---|
| 107 | tabsPreview.Enabled = true;
|
---|
| 108 | lstMethods.Enabled = true;
|
---|
| 109 | lstMethods_SelectedIndexChanged(null, null);
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 |
|
---|
[10737] | 113 | private double getDeleteColumnsInfo() {
|
---|
| 114 | return double.Parse(txtDeleteColumnsInfo.Text);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | private double getDeleteColumnsVariance() {
|
---|
| 118 | return double.Parse(txtDeleteColumnsVariance.Text);
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | private double getRowsColumnsInfo() {
|
---|
| 122 | return double.Parse(txtDeleteRowsInfo.Text);
|
---|
| 123 | }
|
---|
| 124 |
|
---|
[10776] | 125 | private void replaceMissingValues() {
|
---|
[10905] | 126 | var allIndices = Content.SearchLogic.GetMissingValueIndices();
|
---|
| 127 | var columnIndex = cmbVariableNames.SelectedIndex;
|
---|
| 128 | var columnIndices = new Dictionary<int, IList<int>>{
|
---|
| 129 | {columnIndex, allIndices[columnIndex]}
|
---|
| 130 | };
|
---|
| 131 |
|
---|
| 132 | switch (cmbReplaceWith.SelectedIndex) {
|
---|
[10776] | 133 | case 0: //Value
|
---|
[10905] | 134 | Content.ManipulationLogic.ReplaceIndicesByValue(columnIndices, txtReplaceValue.Text);
|
---|
[10776] | 135 | break;
|
---|
| 136 | case 1: //Average
|
---|
[10905] | 137 | Content.ManipulationLogic.ReplaceIndicesByAverageValue(columnIndices);
|
---|
[10776] | 138 | break;
|
---|
| 139 | case 2: //Median
|
---|
[10905] | 140 | Content.ManipulationLogic.ReplaceIndicesByMedianValue(columnIndices);
|
---|
[10776] | 141 | break;
|
---|
| 142 | case 3: //Most Common
|
---|
[10905] | 143 | Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(columnIndices);
|
---|
[10776] | 144 | break;
|
---|
| 145 | case 4: //Random
|
---|
[10905] | 146 | Content.ManipulationLogic.ReplaceIndicesByRandomValue(columnIndices);
|
---|
[10776] | 147 | break;
|
---|
| 148 | }
|
---|
| 149 | }
|
---|
| 150 |
|
---|
[10737] | 151 | private void validateDeleteColumnsInfo() {
|
---|
| 152 | validateDoubleTextBox(txtDeleteColumnsInfo.Text);
|
---|
| 153 | if (btnApply.Enabled) {
|
---|
| 154 | int count = Content.ManipulationLogic.ColumnsWithMissingValuesGreater(getDeleteColumnsInfo()).Count;
|
---|
| 155 | lblPreviewColumnsInfo.Text = count + " column" + (count > 1 || count == 0 ? "s" : "") + " were detected with more than " + txtDeleteColumnsInfo.Text + "% missing values.";
|
---|
| 156 | if (count > 0) {
|
---|
| 157 | lblPreviewColumnsInfo.Text += Environment.NewLine + Environment.NewLine + "Please press the button \"Apply Manipulation\" if you wish to delete those columns.";
|
---|
| 158 | } else {
|
---|
| 159 | btnApply.Enabled = false;
|
---|
| 160 | }
|
---|
| 161 | } else {
|
---|
| 162 | lblPreviewColumnsInfo.Text = "Preview not possible yet - please input the limit above.";
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | private void validateDeleteColumnsVariance() {
|
---|
| 167 | validateDoubleTextBox(txtDeleteColumnsVariance.Text);
|
---|
| 168 | if (btnApply.Enabled) {
|
---|
| 169 | int count = Content.ManipulationLogic.ColumnsWithVarianceSmaller(getDeleteColumnsVariance()).Count;
|
---|
| 170 | lblPreviewColumnsVariance.Text = count + " column" + (count > 1 || count == 0 ? "s" : "") + " were detected with a variance smaller than " + txtDeleteColumnsVariance.Text + ".";
|
---|
| 171 | if (count > 0) {
|
---|
| 172 | lblPreviewColumnsVariance.Text += Environment.NewLine + Environment.NewLine + "Please press the button \"Apply Manipulation\" if you wish to delete those columns.";
|
---|
| 173 | } else {
|
---|
| 174 | btnApply.Enabled = false;
|
---|
| 175 | }
|
---|
| 176 | } else {
|
---|
| 177 | lblPreviewColumnsVariance.Text = "Preview not possible yet - please input the limit for the variance above.";
|
---|
| 178 | }
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | private void validateDeleteRowsInfo() {
|
---|
| 182 | validateDoubleTextBox(txtDeleteRowsInfo.Text);
|
---|
| 183 | if (btnApply.Enabled) {
|
---|
| 184 | int count = Content.ManipulationLogic.RowsWithMissingValuesGreater(getRowsColumnsInfo()).Count;
|
---|
| 185 | lblPreviewRowsInfo.Text = count + " row" + (count > 1 || count == 0 ? "s" : "") + " were detected with more than " + txtDeleteRowsInfo.Text + "% missing values.";
|
---|
| 186 | if (count > 0) {
|
---|
| 187 | lblPreviewRowsInfo.Text += Environment.NewLine + Environment.NewLine + "Please press the button \"Apply Manipulation\" if you wish to delete those rows.";
|
---|
| 188 | } else {
|
---|
| 189 | btnApply.Enabled = false;
|
---|
| 190 | }
|
---|
| 191 | } else {
|
---|
| 192 | lblPreviewRowsInfo.Text = "Preview not possible yet - please input the limit above.";
|
---|
| 193 | }
|
---|
| 194 | }
|
---|
| 195 |
|
---|
[10776] | 196 | private void validateReplaceWith() {
|
---|
| 197 | btnApply.Enabled = false;
|
---|
[10905] | 198 | string replaceWith = (string)cmbReplaceWith.SelectedItem;
|
---|
| 199 | int columnIndex = cmbVariableNames.SelectedIndex;
|
---|
| 200 |
|
---|
[10776] | 201 | if (cmbReplaceWith.SelectedIndex == 0) {
|
---|
[10905] | 202 | string errorMessage;
|
---|
| 203 | string replaceValue = txtReplaceValue.Text;
|
---|
| 204 | if (string.IsNullOrEmpty(replaceValue)) {
|
---|
| 205 | lblPreviewReplaceMissingValues.Text = "Preview not possible yet - please input the text which will be used as replacement.";
|
---|
[11002] | 206 | } else if (!Content.ManipulationLogic.PreProcessingData.Validate(txtReplaceValue.Text, out errorMessage, columnIndex)) {
|
---|
[10905] | 207 | lblPreviewReplaceMissingValues.Text = "Preview not possible yet - " + errorMessage;
|
---|
| 208 | } else {
|
---|
| 209 | btnApply.Enabled = true;
|
---|
| 210 | }
|
---|
| 211 | replaceWith = "\"" + replaceValue + "\"";
|
---|
[10776] | 212 | } else {
|
---|
| 213 | btnApply.Enabled = true;
|
---|
| 214 | }
|
---|
| 215 | if (btnApply.Enabled) {
|
---|
[10905] | 216 | var allIndices = Content.SearchLogic.GetMissingValueIndices();
|
---|
| 217 | int count = allIndices[columnIndex].Count;
|
---|
| 218 | lblPreviewReplaceMissingValues.Text = count + " cell" + (count > 1 || count == 0 ? "s" : "")
|
---|
| 219 | + " were detected with missing values which would be replaced with " + replaceWith;
|
---|
[10776] | 220 | if (count > 0) {
|
---|
| 221 | lblPreviewReplaceMissingValues.Text += Environment.NewLine + Environment.NewLine + "Please press the button \"Apply Manipulation\" if you wish to perform the replacement.";
|
---|
| 222 | } else {
|
---|
| 223 | btnApply.Enabled = false;
|
---|
| 224 | }
|
---|
| 225 | }
|
---|
| 226 | }
|
---|
| 227 |
|
---|
[10709] | 228 | public new ManipulationContent Content {
|
---|
| 229 | get { return (ManipulationContent)base.Content; }
|
---|
| 230 | set { base.Content = value; }
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | private void lstMethods_SelectedIndexChanged(object sender, System.EventArgs e) {
|
---|
| 234 | int index = lstMethods.SelectedIndex;
|
---|
| 235 | tabsData.SelectedIndex = index + 1;
|
---|
| 236 | tabsPreview.SelectedIndex = index + 1;
|
---|
| 237 | btnApply.Enabled = false;
|
---|
| 238 |
|
---|
[10737] | 239 | //in order that button is enabled if necessary input was already entered
|
---|
[10710] | 240 | if (index >= 0) {
|
---|
| 241 | validators[index]();
|
---|
| 242 | }
|
---|
[10709] | 243 | }
|
---|
| 244 |
|
---|
| 245 | private void btnApply_Click(object sender, System.EventArgs e) {
|
---|
| 246 | manipulations[lstMethods.SelectedIndex]();
|
---|
[10737] | 247 | switch (lstMethods.SelectedIndex) {
|
---|
| 248 | case 0:
|
---|
| 249 | lblPreviewColumnsInfo.Text = "columns successfully deleted.";
|
---|
| 250 | break;
|
---|
| 251 | case 1:
|
---|
| 252 | lblPreviewColumnsVariance.Text = "columns successfully deleted.";
|
---|
| 253 | break;
|
---|
| 254 | case 2:
|
---|
| 255 | lblPreviewRowsInfo.Text = "rows successfully deleted.";
|
---|
| 256 | break;
|
---|
| 257 | case 3:
|
---|
[10905] | 258 | lblPreviewReplaceMissingValues.Text = "missing values successfully replaced.";
|
---|
| 259 | btnApply.Enabled = false;
|
---|
| 260 | break;
|
---|
| 261 | case 4:
|
---|
[10737] | 262 | lblPreviewShuffle.Text = "dataset shuffled successfully.";
|
---|
| 263 | btnApply.Enabled = false;
|
---|
| 264 | break;
|
---|
| 265 | }
|
---|
[10709] | 266 | }
|
---|
| 267 |
|
---|
| 268 | private void validateDoubleTextBox(String text) {
|
---|
| 269 | btnApply.Enabled = false;
|
---|
| 270 | if (!string.IsNullOrEmpty(text)) {
|
---|
| 271 | double percent;
|
---|
| 272 | if (Double.TryParse(text, out percent)) {
|
---|
| 273 | btnApply.Enabled = true;
|
---|
| 274 | }
|
---|
| 275 | }
|
---|
| 276 | }
|
---|
| 277 |
|
---|
| 278 | private void txtDeleteColumnsInfo_TextChanged(object sender, EventArgs e) {
|
---|
[10737] | 279 | validateDeleteColumnsInfo();
|
---|
[10709] | 280 | }
|
---|
| 281 |
|
---|
| 282 | private void txtDeleteColumnsVariance_TextChanged(object sender, EventArgs e) {
|
---|
[10737] | 283 | validateDeleteColumnsVariance();
|
---|
[10709] | 284 | }
|
---|
| 285 |
|
---|
| 286 | private void txtDeleteRowsInfo_TextChanged(object sender, EventArgs e) {
|
---|
[10737] | 287 | validateDeleteRowsInfo();
|
---|
[10709] | 288 | }
|
---|
[10737] | 289 |
|
---|
| 290 | void Content_Changed(object sender, DataPreprocessingChangedEventArgs e) {
|
---|
[10905] | 291 | switch (lstMethods.SelectedIndex) {
|
---|
[10737] | 292 | case 0:
|
---|
| 293 | validateDeleteColumnsInfo();
|
---|
| 294 | break;
|
---|
| 295 | case 1:
|
---|
| 296 | validateDeleteColumnsVariance();
|
---|
| 297 | break;
|
---|
| 298 | case 2:
|
---|
| 299 | validateDeleteRowsInfo();
|
---|
| 300 | break;
|
---|
| 301 | }
|
---|
| 302 | }
|
---|
[10776] | 303 |
|
---|
| 304 | private void cmbReplaceWith_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 305 | bool isReplaceWithValueSelected = cmbReplaceWith.SelectedIndex == 0;
|
---|
| 306 | lblValueColon.Visible = isReplaceWithValueSelected;
|
---|
| 307 | txtReplaceValue.Visible = isReplaceWithValueSelected;
|
---|
| 308 | validateReplaceWith();
|
---|
| 309 | }
|
---|
| 310 |
|
---|
| 311 | private void txtReplaceValue_TextChanged(object sender, EventArgs e) {
|
---|
| 312 | validateReplaceWith();
|
---|
| 313 | }
|
---|
[10709] | 314 | }
|
---|
| 315 | }
|
---|