[6134] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[9615] | 3 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6134] | 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 |
|
---|
[6133] | 22 | using System.Collections.Generic;
|
---|
| 23 | using System.Linq;
|
---|
| 24 | using HeuristicLab.DataImporter.Data;
|
---|
| 25 | using HeuristicLab.DataImporter.Data.CommandBase;
|
---|
| 26 | using HeuristicLab.DataImporter.Data.Model;
|
---|
| 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.DataImporter.Command {
|
---|
| 30 | [StorableClass]
|
---|
| 31 | [ViewableCommandInfoAttribute("Delete Rows", 1, ColumnGroupState.AnySelectedColumnContainsNull,
|
---|
| 32 | "Handle Missing Values", Position = 4)]
|
---|
| 33 | public class DeleteRowsWithMissingValuesCommand : ColumnGroupCommandWithAffectedColumnsBase {
|
---|
| 34 | private List<ColumnBase> oldColumns;
|
---|
| 35 | private ICollection<int> oldSortedColumnIndices;
|
---|
| 36 |
|
---|
[9614] | 37 | [StorableConstructor]
|
---|
| 38 | protected DeleteRowsWithMissingValuesCommand(bool deserializing)
|
---|
| 39 | : base(deserializing) {
|
---|
[6133] | 40 | oldColumns = new List<ColumnBase>();
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | public DeleteRowsWithMissingValuesCommand(DataSet dataSet, string columnGroupName, int[] affectedColumns)
|
---|
| 44 | : base(dataSet, columnGroupName, affectedColumns) {
|
---|
| 45 | oldColumns = new List<ColumnBase>();
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | public override void Execute() {
|
---|
| 49 | base.Execute();
|
---|
| 50 | ColumnGroup tempColumnGroup = new ColumnGroup();
|
---|
[7968] | 51 | HashSet<int> positions = new HashSet<int>();
|
---|
[6133] | 52 | ColumnBase column;
|
---|
| 53 |
|
---|
| 54 | for (int col = 0; col < AffectedColumns.Length; col++) {
|
---|
| 55 | column = ColumnGroup.GetColumn(AffectedColumns[col]);
|
---|
| 56 | for (int row = 0; row < ColumnGroup.RowCount; row++) {
|
---|
[7968] | 57 | if (column.GetValue(row) == null && !positions.Contains(row))
|
---|
| 58 | positions.Add(row);
|
---|
[6133] | 59 | }
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | foreach (ColumnBase x in ColumnGroup.Columns) {
|
---|
| 63 | oldColumns.Add(x);
|
---|
| 64 | tempColumnGroup.AddColumn(x.CreateCopyOfColumnWithoutValues());
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | for (int i = 0; i < ColumnGroup.RowCount; i++)
|
---|
[7968] | 68 | if (!positions.Contains(i))
|
---|
[6133] | 69 | tempColumnGroup.AddRow(ColumnGroup.GetRow(i));
|
---|
| 70 |
|
---|
| 71 | oldSortedColumnIndices = new List<int>(ColumnGroup.SortedColumnIndexes);
|
---|
| 72 | for (int i = 0; i < ColumnGroup.Columns.Count(); i++) {
|
---|
| 73 | tempColumnGroup.Columns.ElementAt(i).SortOrder = ColumnGroup.GetColumn(i).SortOrder;
|
---|
| 74 | ColumnGroup.ReplaceColumn(i, tempColumnGroup.Columns.ElementAt(i));
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | ColumnGroup.SortedColumnIndexes = oldSortedColumnIndices;
|
---|
| 78 | ColumnGroup.FireChanged();
|
---|
| 79 | ColumnGroup = null;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | public override void UndoExecute() {
|
---|
| 83 | base.UndoExecute();
|
---|
| 84 | for (int i = 0; i < ColumnGroup.Columns.Count(); i++)
|
---|
| 85 | ColumnGroup.ReplaceColumn(i, oldColumns[i]);
|
---|
| 86 | ColumnGroup.SortedColumnIndexes = oldSortedColumnIndices;
|
---|
| 87 | oldColumns.Clear();
|
---|
| 88 | oldSortedColumnIndices = null;
|
---|
| 89 | ColumnGroup.FireChanged();
|
---|
| 90 | ColumnGroup = null;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | public override string Description {
|
---|
| 94 | get { return "Delete rows with missing values"; }
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
| 97 | }
|
---|