Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/18/17 16:17:39 (6 years ago)
Author:
pfleck
Message:

#2809: merged r15518,r15534 to stable

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.DataPreprocessing.Views

  • stable/HeuristicLab.DataPreprocessing.Views/3.4/DataGridContentView.cs

    r15242 r15535  
    8585      base.RegisterContentEvents();
    8686      Content.Changed += Content_Changed;
    87       Content.FilterLogic.FilterChanged += FilterLogic_FilterChanged;
     87      Content.PreprocessingData.FilterChanged += FilterLogic_FilterChanged;
    8888    }
    8989
     
    9191      base.DeregisterContentEvents();
    9292      Content.Changed -= Content_Changed;
    93       Content.FilterLogic.FilterChanged -= FilterLogic_FilterChanged;
     93      Content.PreprocessingData.FilterChanged -= FilterLogic_FilterChanged;
    9494    }
    9595
     
    9898      searchIterator = null;
    9999      if (findAndReplaceDialog != null && !findAndReplaceDialog.IsDisposed) {
    100         if (Content.FilterLogic.IsFiltered) {
     100        if (Content.PreprocessingData.IsFiltered) {
    101101          findAndReplaceDialog.DisableReplace();
    102102        } else {
     
    104104        }
    105105      }
    106       btnReplace.Enabled = !Content.FilterLogic.IsFiltered;
     106      btnReplace.Enabled = !Content.PreprocessingData.IsFiltered;
    107107    }
    108108
     
    126126      string errorMessage;
    127127      if (!String.IsNullOrEmpty(e.FormattedValue.ToString())) {
    128         if (dataGridView.IsCurrentCellInEditMode && Content.FilterLogic.IsFiltered) {
     128        if (dataGridView.IsCurrentCellInEditMode && Content.PreprocessingData.IsFiltered) {
    129129          errorMessage = "A filter is active, you cannot modify data. Press ESC to exit edit mode.";
    130130        } else {
     
    167167
    168168      ReplaceTransaction(() => {
    169         Content.PreProcessingData.InTransaction(() => {
     169        Content.PreprocessingData.InTransaction(() => {
    170170          for (int row = containsHeader ? 1 : 0; row < values.GetLength(1); row++) {
    171171            for (int col = 0; col < values.GetLength(0); col++) {
     
    177177              if (string.IsNullOrWhiteSpace(firstRow[i]))
    178178                firstRow[i] = string.Format("<{0}>", i);
    179             Content.PreProcessingData.RenameColumns(firstRow);
     179            Content.PreprocessingData.RenameColumns(firstRow);
    180180          }
    181181        });
     
    224224      if (e.Button == MouseButtons.Middle) {
    225225        int newIndex = e.ColumnIndex >= 0 ? e.ColumnIndex : 0;
    226         Content.PreProcessingData.InsertColumn<double>(newIndex.ToString(), newIndex);
     226        Content.PreprocessingData.InsertColumn<double>(newIndex.ToString(), newIndex);
    227227      } else if (e.Button == MouseButtons.Right && Content.SortableView) {
    228228        SortColumn(e.ColumnIndex);
     
    235235        if (e.Button == MouseButtons.Middle) {
    236236          int newIndex = e.RowIndex >= 0 ? e.RowIndex : 0;
    237           Content.PreProcessingData.InsertRow(newIndex);
     237          Content.PreprocessingData.InsertRow(newIndex);
    238238        }
    239239      }
     
    248248    }
    249249
    250     private void btnApplySort_Click(object sender, System.EventArgs e) {
    251       Content.ManipulationLogic.ReOrderToIndices(virtualRowIndices);
     250    private void btnApplySort_Click(object sender, EventArgs e) {
     251      Content.ReOrderToIndices(virtualRowIndices);
    252252      OnContentChanged();
    253253    }
     
    271271        searchIterator = null;
    272272        DataGridView.SelectionChanged += DataGridView_SelectionChanged_FindAndReplace;
    273         if (Content.FilterLogic.IsFiltered) {
     273        if (Content.PreprocessingData.IsFiltered) {
    274274          findAndReplaceDialog.DisableReplace();
    275275        }
     
    405405      ComparisonOperation comparisonOperation = findAndReplaceDialog.GetComparisonOperation();
    406406      var foundCells = new Dictionary<int, IList<int>>();
    407       for (int i = 0; i < Content.FilterLogic.PreprocessingData.Columns; i++) {
     407      for (int i = 0; i < Content.PreprocessingData.Columns; i++) {
    408408        var filters = CreateFilters(match, comparisonOperation, i);
    409409
    410         bool[] filteredRows = Content.FilterLogic.GetFilterResult(filters, true);
     410        bool[] filteredRows = GetFilterResult(filters, true);
    411411        var foundIndices = new List<int>();
    412412        for (int idx = 0; idx < filteredRows.Length; ++idx) {
     
    427427    }
    428428
     429    private bool[] GetFilterResult(IList<IFilter> filters, bool isAndCombination) {
     430      IList<IFilter> activeFilters = filters.Where(f => f.Active && f.ConstraintData != null).ToList();
     431
     432      if (activeFilters.Count == 0) {
     433        return Enumerable.Repeat(false, Content.PreprocessingData.Rows).ToArray(); ;
     434      }
     435
     436      var result = Enumerable.Repeat(!isAndCombination, Content.PreprocessingData.Rows).ToArray();
     437      foreach (IFilter filter in activeFilters) {
     438        bool[] filterResult = filter.Check();
     439        for (int row = 0; row < result.Length; ++row) {
     440          result[row] = isAndCombination ? result[row] || filterResult[row] : result[row] && filterResult[row];
     441        }
     442      }
     443      return result;
     444    }
     445
    429446    private List<IFilter> CreateFilters(string match, ComparisonOperation comparisonOperation, int columnIndex) {
    430       IPreprocessingData preprocessingData = Content.FilterLogic.PreprocessingData;
     447      IPreprocessingData preprocessingData = Content.PreprocessingData;
    431448      IStringConvertibleValue value;
    432449      if (preprocessingData.VariableHasType<double>(columnIndex)) {
     
    473490          switch (findAndReplaceDialog.GetReplaceAction()) {
    474491            case ReplaceAction.Value:
    475               Content.ManipulationLogic.ReplaceIndicesByValue(cells, findAndReplaceDialog.GetReplaceText());
     492              Content.ReplaceIndicesByString(cells, findAndReplaceDialog.GetReplaceText());
    476493              break;
    477494            case ReplaceAction.Average:
    478               Content.ManipulationLogic.ReplaceIndicesByAverageValue(cells, false);
     495              Content.ReplaceIndicesByMean(cells, false);
    479496              break;
    480497            case ReplaceAction.Median:
    481               Content.ManipulationLogic.ReplaceIndicesByMedianValue(cells, false);
     498              Content.ReplaceIndicesByMedianValue(cells, false);
    482499              break;
    483500            case ReplaceAction.Random:
    484               Content.ManipulationLogic.ReplaceIndicesByRandomValue(cells, false);
     501              Content.ReplaceIndicesByRandomValue(cells, false);
    485502              break;
    486503            case ReplaceAction.MostCommon:
    487               Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(cells, false);
     504              Content.ReplaceIndicesByMode(cells, false);
    488505              break;
    489506            case ReplaceAction.Interpolation:
    490               Content.ManipulationLogic.ReplaceIndicesByLinearInterpolationOfNeighbours(cells);
     507              Content.ReplaceIndicesByLinearInterpolationOfNeighbours(cells);
    491508              break;
    492509          }
     
    506523
    507524    #endregion FindAndReplaceDialog
    508 
    509525    private void dataGridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) {
    510526      if (Content == null) return;
     
    531547            medianToolStripMenuItem_Selection.Enabled =
    532548            randomToolStripMenuItem_Column.Enabled =
    533             randomToolStripMenuItem_Selection.Enabled = !Content.PreProcessingData.AreAllStringColumns(columnIndices);
    534 
    535           smoothingToolStripMenuItem_Column.Enabled =
    536             interpolationToolStripMenuItem_Column.Enabled = !dataGridView.SelectedCells.Contains(dataGridView[e.ColumnIndex, 0])
    537             && !dataGridView.SelectedCells.Contains(dataGridView[e.ColumnIndex, Content.Rows - 1])
    538             && !Content.PreProcessingData.AreAllStringColumns(columnIndices);
     549            randomToolStripMenuItem_Selection.Enabled = !Content.PreprocessingData.AreAllStringColumns(columnIndices);
    539550
    540551          replaceValueOverColumnToolStripMenuItem.Visible = true;
     
    547558      base.dataGridView_KeyDown(sender, e);
    548559      //data is in read only mode....
    549       if (Content.FilterLogic.IsFiltered) return;
     560      if (Content.PreprocessingData.IsFiltered) return;
    550561
    551562      if (e.KeyCode == Keys.Delete) {
     
    581592      }
    582593
    583       foreach (var selectedCell in dataGridView.SelectedCells) {
    584         var cell = (DataGridViewCell)selectedCell;
     594      foreach (DataGridViewCell cell in dataGridView.SelectedCells) {
    585595        if (!selectedCells.ContainsKey(cell.ColumnIndex))
    586           selectedCells.Add(cell.ColumnIndex, new List<int>(1024));
     596          selectedCells.Add(cell.ColumnIndex, new List<int>());
    587597        selectedCells[cell.ColumnIndex].Add(cell.RowIndex);
    588598      }
     
    591601    }
    592602
    593     private void StartReplacing() {
     603    private void ReplaceTransaction(Action action) {
    594604      SuspendRepaint();
    595     }
    596 
    597     private void StopReplacing() {
     605      action();
    598606      ResumeRepaint(true);
    599     }
    600 
    601     private void ReplaceTransaction(Action action) {
    602       StartReplacing();
    603       action();
    604       StopReplacing();
    605607    }
    606608
     
    616618
    617619    #region ContextMenu Events
    618 
    619620    private void ReplaceWithAverage_Column_Click(object sender, EventArgs e) {
    620621      ReplaceTransaction(() => {
    621         Content.ManipulationLogic.ReplaceIndicesByAverageValue(GetSelectedCells(), false);
     622        Content.ReplaceIndicesByMean(GetSelectedCells(), false);
    622623      });
    623624    }
    624625    private void ReplaceWithAverage_Selection_Click(object sender, EventArgs e) {
    625626      ReplaceTransaction(() => {
    626         Content.ManipulationLogic.ReplaceIndicesByAverageValue(GetSelectedCells(), true);
     627        Content.ReplaceIndicesByMean(GetSelectedCells(), true);
    627628      });
    628629    }
     
    630631    private void ReplaceWithMedian_Column_Click(object sender, EventArgs e) {
    631632      ReplaceTransaction(() => {
    632         Content.ManipulationLogic.ReplaceIndicesByMedianValue(GetSelectedCells(), false);
     633        Content.ReplaceIndicesByMedianValue(GetSelectedCells(), false);
    633634      });
    634635    }
    635636    private void ReplaceWithMedian_Selection_Click(object sender, EventArgs e) {
    636637      ReplaceTransaction(() => {
    637         Content.ManipulationLogic.ReplaceIndicesByMedianValue(GetSelectedCells(), true);
     638        Content.ReplaceIndicesByMedianValue(GetSelectedCells(), true);
    638639      });
    639640    }
     
    641642    private void ReplaceWithRandom_Column_Click(object sender, EventArgs e) {
    642643      ReplaceTransaction(() => {
    643         Content.ManipulationLogic.ReplaceIndicesByRandomValue(GetSelectedCells(), false);
     644        Content.ReplaceIndicesByRandomValue(GetSelectedCells(), false);
    644645      });
    645646    }
    646647    private void ReplaceWithRandom_Selection_Click(object sender, EventArgs e) {
    647648      ReplaceTransaction(() => {
    648         Content.ManipulationLogic.ReplaceIndicesByRandomValue(GetSelectedCells(), true);
     649        Content.ReplaceIndicesByRandomValue(GetSelectedCells(), true);
    649650      });
    650651    }
     
    652653    private void ReplaceWithMostCommon_Column_Click(object sender, EventArgs e) {
    653654      ReplaceTransaction(() => {
    654         Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(GetSelectedCells(), false);
     655        Content.ReplaceIndicesByMode(GetSelectedCells(), false);
    655656      });
    656657    }
    657658    private void ReplaceWithMostCommon_Selection_Click(object sender, EventArgs e) {
    658659      ReplaceTransaction(() => {
    659         Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(GetSelectedCells(), true);
     660        Content.ReplaceIndicesByMode(GetSelectedCells(), true);
    660661      });
    661662    }
     
    663664    private void ReplaceWithInterpolation_Column_Click(object sender, EventArgs e) {
    664665      ReplaceTransaction(() => {
    665         Content.ManipulationLogic.ReplaceIndicesByLinearInterpolationOfNeighbours(GetSelectedCells());
    666       });
    667     }
    668 
    669     private void ReplaceWithSmoothing_Selection_Click(object sender, EventArgs e) {
    670       ReplaceTransaction(() => {
    671         Content.ManipulationLogic.ReplaceIndicesBySmoothing(GetSelectedCells());
     666        Content.ReplaceIndicesByLinearInterpolationOfNeighbours(GetSelectedCells());
    672667      });
    673668    }
     
    675670
    676671    private void addRowButton_Click(object sender, EventArgs e) {
    677       Content.PreProcessingData.InsertRow(Content.Rows);
     672      Content.PreprocessingData.InsertRow(Content.Rows);
    678673    }
    679674
    680675    private void addColumnButton_Click(object sender, EventArgs e) {
    681       Content.PreProcessingData.InsertColumn<double>(Content.Columns.ToString(), Content.Columns);
     676      Content.PreprocessingData.InsertColumn<double>(Content.Columns.ToString(), Content.Columns);
    682677    }
    683678
     
    686681
    687682      if (renameDialog.ShowDialog(this) == DialogResult.OK) {
    688         Content.PreProcessingData.RenameColumns(renameDialog.ColumnNames);
     683        Content.PreprocessingData.RenameColumns(renameDialog.ColumnNames);
    689684      }
    690685    }
     
    693688      foreach (DataGridViewColumn column in DataGridView.Columns) {
    694689        var variable = column.HeaderText;
    695         bool isInputTarget = Content.PreProcessingData.InputVariables.Contains(variable)
    696           || Content.PreProcessingData.TargetVariable == variable;
     690        bool isInputTarget = Content.PreprocessingData.InputVariables.Contains(variable)
     691          || Content.PreprocessingData.TargetVariable == variable;
    697692        column.Visible = isInputTarget;
    698693      }
     
    710705      }
    711706    }
     707
     708    private void shuffleAllButton_Click(object sender, EventArgs e) {
     709      Content.Shuffle(shuffleWithinPartitionsCheckBox.Checked);
     710    }
    712711  }
    713712}
Note: See TracChangeset for help on using the changeset viewer.