[6133] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using System.Xml;
|
---|
| 6 | using HeuristicLab.DataImporter.Data;
|
---|
| 7 | using HeuristicLab.DataImporter.Data.CommandBase;
|
---|
| 8 | using HeuristicLab.DataImporter.Data.Model;
|
---|
| 9 | using HeuristicLab.DataImporter.Command.View;
|
---|
| 10 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 11 |
|
---|
| 12 | namespace HeuristicLab.DataImporter.Command {
|
---|
| 13 | [StorableClass]
|
---|
| 14 | [ViewableCommandInfoAttribute("Delete Columns with too few Values", 1, ColumnGroupState.Active, "ColumnGroup Commands",
|
---|
| 15 | Position = 14, OptionsView = typeof(ThresholdCommandView))]
|
---|
| 16 | public class DeleteColumnsWithTooFewValuesCommand : ColumnGroupCommandBase {
|
---|
| 17 | private SortedDictionary<int, ColumnBase> deletedColumns;
|
---|
| 18 | private ICollection<int> oldSortedColumnIndices;
|
---|
| 19 | private DeleteColumnsWithTooFewValuesCommand()
|
---|
| 20 | : base(null, string.Empty) {
|
---|
| 21 | deletedColumns = new SortedDictionary<int, ColumnBase>();
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | public DeleteColumnsWithTooFewValuesCommand(DataSet dataSet, string columnGroupName)
|
---|
| 25 | : base(dataSet, columnGroupName) {
|
---|
| 26 | deletedColumns = new SortedDictionary<int, ColumnBase>();
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | [Storable]
|
---|
| 30 | private double threshold;
|
---|
| 31 | public double Threshold {
|
---|
| 32 | get { return this.threshold; }
|
---|
| 33 | set { this.threshold = value; }
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | public override string Description {
|
---|
| 37 | get { return "Delete Columns with too few values"; }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | public override void Execute() {
|
---|
| 41 | base.Execute();
|
---|
| 42 | ColumnBase column;
|
---|
| 43 | for (int i = 0; i < ColumnGroup.Columns.Count(); i++) {
|
---|
| 44 | column = ColumnGroup.GetColumn(i);
|
---|
| 45 | if ((1 - ((double)column.NullValuesCount) / column.TotalValuesCount) < threshold)
|
---|
| 46 | deletedColumns.Add(i, column);
|
---|
| 47 | }
|
---|
| 48 | oldSortedColumnIndices = new List<int>(ColumnGroup.SortedColumnIndexes);
|
---|
| 49 | foreach (ColumnBase col in deletedColumns.Values)
|
---|
| 50 | ColumnGroup.RemoveColumn(col);
|
---|
| 51 | ColumnGroup.FireChanged();
|
---|
| 52 | ColumnGroup = null;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | public override void UndoExecute() {
|
---|
| 56 | base.UndoExecute();
|
---|
| 57 | foreach (KeyValuePair<int, ColumnBase> pair in deletedColumns)
|
---|
| 58 | ColumnGroup.InsertColumn(pair.Key, pair.Value);
|
---|
| 59 | ColumnGroup.SortedColumnIndexes = oldSortedColumnIndices;
|
---|
| 60 | oldSortedColumnIndices = null;
|
---|
| 61 | deletedColumns.Clear();
|
---|
| 62 | ColumnGroup.FireChanged();
|
---|
| 63 | ColumnGroup = null;
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 | }
|
---|