Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/26/17 14:12:27 (7 years ago)
Author:
pfleck
Message:

#2809 removed ManipulationLogic

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing Cleanup/HeuristicLab.DataPreprocessing.Views/3.4/ManipulationView.cs

    r15283 r15285  
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.Drawing;
    2524using System.Globalization;
     
    4443    public ManipulationView() {
    4544      InitializeComponent();
    46       cmbReplaceWith.SelectedIndex = 0;
    4745      tabsData.Appearance = TabAppearance.FlatButtons;
    4846      tabsData.ItemSize = new Size(0, 1);
     
    5654        () => ValidateDeleteColumnsVariance(),
    5755        () => ValidateDeleteRowsInfo(),
    58         () => ValidateReplaceWith(),
    59         () => ValidateShuffle()
    6056      };
    6157
    6258      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()),
    6862      };
    6963    }
     
    7266      base.OnContentChanged();
    7367      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;
    7968        CheckFilters();
    8069      }
     
    8372    protected override void RegisterContentEvents() {
    8473      base.RegisterContentEvents();
    85       Content.ManipulationLogic.PreprocessingData.FilterChanged += FilterLogic_FilterChanged;
     74      Content.PreprocessingData.FilterChanged += FilterLogic_FilterChanged;
    8675    }
    8776
    8877    protected override void DeregisterContentEvents() {
    89       Content.ManipulationLogic.PreprocessingData.FilterChanged -= FilterLogic_FilterChanged;
     78      Content.PreprocessingData.FilterChanged -= FilterLogic_FilterChanged;
    9079      base.DeregisterContentEvents();
    9180    }
     
    126115    }
    127116
    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: //Value
    139           Content.ManipulationLogic.ReplaceIndicesByValue(columnIndices, txtReplaceValue.Text);
    140           break;
    141         case 1: //Average
    142           Content.ManipulationLogic.ReplaceIndicesByAverageValue(columnIndices);
    143           break;
    144         case 2: //Median
    145           Content.ManipulationLogic.ReplaceIndicesByMedianValue(columnIndices);
    146           break;
    147         case 3: //Most Common
    148           Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(columnIndices);
    149           break;
    150         case 4: //Random
    151           Content.ManipulationLogic.ReplaceIndicesByRandomValue(columnIndices);
    152           break;
    153       }
    154     }
    155 
    156117    private void ValidateDeleteColumnsInfo() {
    157118      ValidateDoubleTextBox(txtDeleteColumnsInfo.Text);
    158119      if (btnApply.Enabled) {
    159         var filteredColumns = Content.ManipulationLogic.ColumnsWithMissingValuesGreater(GetDeleteColumnsInfo());
     120        var filteredColumns = Content.ColumnsWithMissingValuesGreater(GetDeleteColumnsInfo());
    160121        int count = filteredColumns.Count;
    161122        int columnCount = Content.PreprocessingData.Columns;
     
    167128          sb.Append(Environment.NewLine);
    168129          sb.Append("Columns: ");
    169           sb.Append(Content.ManipulationLogic.VariableNames.ElementAt(filteredColumns.ElementAt(0)));
     130          sb.Append(Content.PreprocessingData.VariableNames.ElementAt(filteredColumns.ElementAt(0)));
    170131          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));
    172133            sb.Append(", ");
    173134            sb.Append(columnName);
     
    188149      ValidateDoubleTextBox(txtDeleteColumnsVariance.Text);
    189150      if (btnApply.Enabled) {
    190         var filteredColumns = Content.ManipulationLogic.ColumnsWithVarianceSmaller(GetDeleteColumnsVariance());
     151        var filteredColumns = Content.ColumnsWithVarianceSmaller(GetDeleteColumnsVariance());
    191152        int count = filteredColumns.Count;
    192153        int columnCount = Content.PreprocessingData.Columns;
     
    198159          sb.Append(Environment.NewLine);
    199160          sb.Append("Columns: ");
    200           sb.Append(Content.ManipulationLogic.VariableNames.ElementAt(filteredColumns.ElementAt(0)));
     161          sb.Append(Content.PreprocessingData.VariableNames.ElementAt(filteredColumns.ElementAt(0)));
    201162          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));
    203164            sb.Append(", ");
    204165            sb.Append(columnName);
     
    219180      ValidateDoubleTextBox(txtDeleteRowsInfo.Text);
    220181      if (btnApply.Enabled) {
    221         int count = Content.ManipulationLogic.RowsWithMissingValuesGreater(GetRowsColumnsInfo()).Count;
     182        int count = Content.RowsWithMissingValuesGreater(GetRowsColumnsInfo()).Count;
    222183        int rowCount = Content.PreprocessingData.Rows;
    223184        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.";
     
    230191        lblPreviewRowsInfo.Text = "Preview not possible yet - please input the limit above.";
    231192      }
    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;
    275193    }
    276194
     
    299217          lblPreviewRowsInfo.Text = "rows successfully deleted.";
    300218          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;
    309219      }
    310220    }
     
    331241      ValidateDeleteRowsInfo();
    332242    }
    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     }
    344243  }
    345244}
Note: See TracChangeset for help on using the changeset viewer.