Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Command/ChangeDataset/DeleteColumnsWithTooFewValuesCommand.cs @ 6133

Last change on this file since 6133 was 6133, checked in by gkronber, 13 years ago

#1471: imported generic parts of DataImporter from private code base

File size: 2.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Xml;
6using HeuristicLab.DataImporter.Data;
7using HeuristicLab.DataImporter.Data.CommandBase;
8using HeuristicLab.DataImporter.Data.Model;
9using HeuristicLab.DataImporter.Command.View;
10using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
11
12namespace 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}
Note: See TracBrowser for help on using the repository browser.