[10709] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16057] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[10709] | 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;
|
---|
| 23 | using System.Drawing;
|
---|
[12676] | 24 | using System.Globalization;
|
---|
| 25 | using System.Linq;
|
---|
| 26 | using System.Text;
|
---|
[10709] | 27 | using System.Windows.Forms;
|
---|
| 28 | using HeuristicLab.Core.Views;
|
---|
| 29 | using HeuristicLab.MainForm;
|
---|
| 30 |
|
---|
| 31 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
| 32 | [View("Manipulation Chart View")]
|
---|
[10712] | 33 | [Content(typeof(ManipulationContent), true)]
|
---|
[10709] | 34 | public partial class ManipulationView : ItemView {
|
---|
| 35 | private Action[] validators;
|
---|
| 36 | private Action[] manipulations;
|
---|
| 37 |
|
---|
[15110] | 38 | public new ManipulationContent Content {
|
---|
| 39 | get { return (ManipulationContent)base.Content; }
|
---|
| 40 | set { base.Content = value; }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
[10709] | 43 | public ManipulationView() {
|
---|
| 44 | InitializeComponent();
|
---|
| 45 | tabsData.Appearance = TabAppearance.FlatButtons;
|
---|
| 46 | tabsData.ItemSize = new Size(0, 1);
|
---|
| 47 | tabsData.SizeMode = TabSizeMode.Fixed;
|
---|
| 48 | tabsPreview.Appearance = TabAppearance.FlatButtons;
|
---|
| 49 | tabsPreview.ItemSize = new Size(0, 1);
|
---|
| 50 | tabsPreview.SizeMode = TabSizeMode.Fixed;
|
---|
| 51 |
|
---|
[15110] | 52 | validators = new Action[] {
|
---|
| 53 | () => ValidateDeleteColumnsInfo(),
|
---|
| 54 | () => ValidateDeleteColumnsVariance(),
|
---|
| 55 | () => ValidateDeleteRowsInfo(),
|
---|
[10709] | 56 | };
|
---|
[10737] | 57 |
|
---|
[15110] | 58 | manipulations = new Action[] {
|
---|
[16057] | 59 | () => Content.DeleteColumnsWithMissingValuesGreater(GetDeleteColumnsInfo()),
|
---|
| 60 | () => Content.DeleteColumnsWithVarianceSmaller(GetDeleteColumnsVariance()),
|
---|
| 61 | () => Content.DeleteRowsWithMissingValuesGreater(GetRowsColumnsInfo()),
|
---|
[10709] | 62 | };
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[10905] | 65 | protected override void OnContentChanged() {
|
---|
| 66 | base.OnContentChanged();
|
---|
| 67 | if (Content != null) {
|
---|
[10977] | 68 | CheckFilters();
|
---|
[10905] | 69 | }
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[10737] | 72 | protected override void RegisterContentEvents() {
|
---|
| 73 | base.RegisterContentEvents();
|
---|
[16057] | 74 | Content.PreprocessingData.FilterChanged += FilterLogic_FilterChanged;
|
---|
[10737] | 75 | }
|
---|
| 76 |
|
---|
| 77 | protected override void DeregisterContentEvents() {
|
---|
[16057] | 78 | Content.PreprocessingData.FilterChanged -= FilterLogic_FilterChanged;
|
---|
[10737] | 79 | base.DeregisterContentEvents();
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[10970] | 82 | private void FilterLogic_FilterChanged(object sender, EventArgs e) {
|
---|
| 83 | if (Content != null) {
|
---|
[10977] | 84 | CheckFilters();
|
---|
[10970] | 85 | }
|
---|
| 86 | }
|
---|
| 87 |
|
---|
[10977] | 88 | private void CheckFilters() {
|
---|
[16057] | 89 | if (Content.PreprocessingData.IsFiltered) {
|
---|
[10970] | 90 | tabsPreview.SelectedIndex = 0;
|
---|
| 91 | lstMethods.Enabled = false;
|
---|
| 92 | tabsData.Enabled = false;
|
---|
| 93 | tabsPreview.Enabled = false;
|
---|
| 94 | lblPreviewInActive.Visible = true;
|
---|
| 95 | btnApply.Enabled = false;
|
---|
| 96 | } else {
|
---|
| 97 | lblPreviewInActive.Visible = false;
|
---|
| 98 | tabsData.Enabled = true;
|
---|
| 99 | tabsPreview.Enabled = true;
|
---|
| 100 | lstMethods.Enabled = true;
|
---|
| 101 | lstMethods_SelectedIndexChanged(null, null);
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 |
|
---|
[15110] | 105 | private double GetDeleteColumnsInfo() {
|
---|
[10737] | 106 | return double.Parse(txtDeleteColumnsInfo.Text);
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[15110] | 109 | private double GetDeleteColumnsVariance() {
|
---|
[10737] | 110 | return double.Parse(txtDeleteColumnsVariance.Text);
|
---|
| 111 | }
|
---|
| 112 |
|
---|
[15110] | 113 | private double GetRowsColumnsInfo() {
|
---|
[10737] | 114 | return double.Parse(txtDeleteRowsInfo.Text);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
[15110] | 117 | private void ValidateDeleteColumnsInfo() {
|
---|
| 118 | ValidateDoubleTextBox(txtDeleteColumnsInfo.Text);
|
---|
[10737] | 119 | if (btnApply.Enabled) {
|
---|
[16057] | 120 | var filteredColumns = Content.ColumnsWithMissingValuesGreater(GetDeleteColumnsInfo());
|
---|
[12676] | 121 | int count = filteredColumns.Count;
|
---|
[16057] | 122 | int columnCount = Content.PreprocessingData.Columns;
|
---|
[13796] | 123 | lblPreviewColumnsInfo.Text = string.Format("{0} column{1} of {2} ({3}) were detected with more than {4}% missing values.", count, (count > 1 || count == 0 ? "s" : ""), columnCount, string.Format("{0:F2}%", 100d / columnCount * count), txtDeleteColumnsInfo.Text);
|
---|
| 124 |
|
---|
| 125 | //only display column names more than 0 and fewer than 50 are affected
|
---|
| 126 | if (count > 0 && count < 50) {
|
---|
[12676] | 127 | StringBuilder sb = new StringBuilder();
|
---|
| 128 | sb.Append(Environment.NewLine);
|
---|
| 129 | sb.Append("Columns: ");
|
---|
[16057] | 130 | sb.Append(Content.PreprocessingData.VariableNames.ElementAt(filteredColumns.ElementAt(0)));
|
---|
[12676] | 131 | for (int i = 1; i < filteredColumns.Count; i++) {
|
---|
[16057] | 132 | string columnName = Content.PreprocessingData.VariableNames.ElementAt(filteredColumns.ElementAt(i));
|
---|
[12676] | 133 | sb.Append(", ");
|
---|
| 134 | sb.Append(columnName);
|
---|
| 135 | }
|
---|
| 136 | sb.Append(Environment.NewLine);
|
---|
| 137 | sb.Append("Please press the button \"Apply Manipulation\" if you wish to delete those columns.");
|
---|
| 138 |
|
---|
| 139 | lblPreviewColumnsInfo.Text += sb.ToString();
|
---|
[10737] | 140 | }
|
---|
[13796] | 141 |
|
---|
| 142 | btnApply.Enabled = count > 0;
|
---|
[10737] | 143 | } else {
|
---|
| 144 | lblPreviewColumnsInfo.Text = "Preview not possible yet - please input the limit above.";
|
---|
| 145 | }
|
---|
| 146 | }
|
---|
| 147 |
|
---|
[15110] | 148 | private void ValidateDeleteColumnsVariance() {
|
---|
| 149 | ValidateDoubleTextBox(txtDeleteColumnsVariance.Text);
|
---|
[10737] | 150 | if (btnApply.Enabled) {
|
---|
[16057] | 151 | var filteredColumns = Content.ColumnsWithVarianceSmaller(GetDeleteColumnsVariance());
|
---|
[12676] | 152 | int count = filteredColumns.Count;
|
---|
[16057] | 153 | int columnCount = Content.PreprocessingData.Columns;
|
---|
[13796] | 154 | lblPreviewColumnsVariance.Text = string.Format("{0} column{1} of {2} ({3}) were detected with a variance smaller than {4}.", count, (count > 1 || count == 0 ? "s" : ""), columnCount, string.Format("{0:F2}%", 100d / columnCount * count), txtDeleteColumnsVariance.Text);
|
---|
| 155 |
|
---|
| 156 | //only display column names more than 0 and fewer than 50 are affected
|
---|
| 157 | if (count > 0 && count < 50) {
|
---|
[12676] | 158 | StringBuilder sb = new StringBuilder();
|
---|
| 159 | sb.Append(Environment.NewLine);
|
---|
| 160 | sb.Append("Columns: ");
|
---|
[16057] | 161 | sb.Append(Content.PreprocessingData.VariableNames.ElementAt(filteredColumns.ElementAt(0)));
|
---|
[12676] | 162 | for (int i = 1; i < filteredColumns.Count; i++) {
|
---|
[16057] | 163 | string columnName = Content.PreprocessingData.VariableNames.ElementAt(filteredColumns.ElementAt(i));
|
---|
[12676] | 164 | sb.Append(", ");
|
---|
| 165 | sb.Append(columnName);
|
---|
| 166 | }
|
---|
| 167 | sb.Append(Environment.NewLine);
|
---|
| 168 | sb.Append("Please press the button \"Apply Manipulation\" if you wish to delete those columns.");
|
---|
| 169 |
|
---|
| 170 | lblPreviewColumnsVariance.Text += sb.ToString();
|
---|
[10737] | 171 | }
|
---|
[13796] | 172 |
|
---|
| 173 | btnApply.Enabled = count > 0;
|
---|
[10737] | 174 | } else {
|
---|
| 175 | lblPreviewColumnsVariance.Text = "Preview not possible yet - please input the limit for the variance above.";
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
| 178 |
|
---|
[15110] | 179 | private void ValidateDeleteRowsInfo() {
|
---|
| 180 | ValidateDoubleTextBox(txtDeleteRowsInfo.Text);
|
---|
[10737] | 181 | if (btnApply.Enabled) {
|
---|
[16057] | 182 | int count = Content.RowsWithMissingValuesGreater(GetRowsColumnsInfo()).Count;
|
---|
| 183 | int rowCount = Content.PreprocessingData.Rows;
|
---|
[11045] | 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.";
|
---|
[10737] | 185 | if (count > 0) {
|
---|
| 186 | lblPreviewRowsInfo.Text += Environment.NewLine + Environment.NewLine + "Please press the button \"Apply Manipulation\" if you wish to delete those rows.";
|
---|
| 187 | } else {
|
---|
| 188 | btnApply.Enabled = false;
|
---|
| 189 | }
|
---|
| 190 | } else {
|
---|
| 191 | lblPreviewRowsInfo.Text = "Preview not possible yet - please input the limit above.";
|
---|
| 192 | }
|
---|
| 193 | }
|
---|
| 194 |
|
---|
[10709] | 195 | private void lstMethods_SelectedIndexChanged(object sender, System.EventArgs e) {
|
---|
| 196 | int index = lstMethods.SelectedIndex;
|
---|
| 197 | tabsData.SelectedIndex = index + 1;
|
---|
| 198 | tabsPreview.SelectedIndex = index + 1;
|
---|
| 199 | btnApply.Enabled = false;
|
---|
| 200 |
|
---|
[10737] | 201 | //in order that button is enabled if necessary input was already entered
|
---|
[10710] | 202 | if (index >= 0) {
|
---|
| 203 | validators[index]();
|
---|
| 204 | }
|
---|
[10709] | 205 | }
|
---|
| 206 |
|
---|
| 207 | private void btnApply_Click(object sender, System.EventArgs e) {
|
---|
| 208 | manipulations[lstMethods.SelectedIndex]();
|
---|
[10737] | 209 | switch (lstMethods.SelectedIndex) {
|
---|
| 210 | case 0:
|
---|
| 211 | lblPreviewColumnsInfo.Text = "columns successfully deleted.";
|
---|
| 212 | break;
|
---|
| 213 | case 1:
|
---|
| 214 | lblPreviewColumnsVariance.Text = "columns successfully deleted.";
|
---|
| 215 | break;
|
---|
| 216 | case 2:
|
---|
| 217 | lblPreviewRowsInfo.Text = "rows successfully deleted.";
|
---|
| 218 | break;
|
---|
| 219 | }
|
---|
[10709] | 220 | }
|
---|
| 221 |
|
---|
[15110] | 222 | private void ValidateDoubleTextBox(String text) {
|
---|
[10709] | 223 | btnApply.Enabled = false;
|
---|
| 224 | if (!string.IsNullOrEmpty(text)) {
|
---|
| 225 | double percent;
|
---|
[12676] | 226 | if (Double.TryParse(text, NumberStyles.Number ^ NumberStyles.AllowThousands, CultureInfo.CurrentCulture, out percent)) {
|
---|
[10709] | 227 | btnApply.Enabled = true;
|
---|
| 228 | }
|
---|
| 229 | }
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | private void txtDeleteColumnsInfo_TextChanged(object sender, EventArgs e) {
|
---|
[15110] | 233 | ValidateDeleteColumnsInfo();
|
---|
[10709] | 234 | }
|
---|
| 235 |
|
---|
| 236 | private void txtDeleteColumnsVariance_TextChanged(object sender, EventArgs e) {
|
---|
[15110] | 237 | ValidateDeleteColumnsVariance();
|
---|
[10709] | 238 | }
|
---|
| 239 |
|
---|
| 240 | private void txtDeleteRowsInfo_TextChanged(object sender, EventArgs e) {
|
---|
[15110] | 241 | ValidateDeleteRowsInfo();
|
---|
[10709] | 242 | }
|
---|
| 243 | }
|
---|
| 244 | }
|
---|