Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Command/ChangeDataset/DeleteColumnsWithTooFewValuesCommand.cs @ 16567

Last change on this file since 16567 was 9614, checked in by mkommend, 11 years ago

#1734: Added StorableConstructor to all storable DataImporter classes.

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    [StorableConstructor]
20    protected DeleteColumnsWithTooFewValuesCommand(bool deserializing)
21      : base(deserializing) {
22      deletedColumns = new SortedDictionary<int, ColumnBase>();
23    }
24
25    public DeleteColumnsWithTooFewValuesCommand(DataSet dataSet, string columnGroupName)
26      : base(dataSet, columnGroupName) {
27      deletedColumns = new SortedDictionary<int, ColumnBase>();
28    }
29
30    [Storable]
31    private double threshold;
32    public double Threshold {
33      get { return this.threshold; }
34      set { this.threshold = value; }
35    }
36
37    public override string Description {
38      get { return "Delete Columns with too few values"; }
39    }
40
41    public override void Execute() {
42      base.Execute();
43      ColumnBase column;
44      for (int i = 0; i < ColumnGroup.Columns.Count(); i++) {
45        column = ColumnGroup.GetColumn(i);
46        if ((1 - ((double)column.NullValuesCount) / column.TotalValuesCount) < threshold)
47          deletedColumns.Add(i, column);
48      }
49      oldSortedColumnIndices = new List<int>(ColumnGroup.SortedColumnIndexes);
50      foreach (ColumnBase col in deletedColumns.Values)
51        ColumnGroup.RemoveColumn(col);
52      ColumnGroup.FireChanged();
53      ColumnGroup = null;
54    }
55
56    public override void UndoExecute() {
57      base.UndoExecute();
58      foreach (KeyValuePair<int, ColumnBase> pair in deletedColumns)
59        ColumnGroup.InsertColumn(pair.Key, pair.Value);
60      ColumnGroup.SortedColumnIndexes = oldSortedColumnIndices;
61      oldSortedColumnIndices = null;
62      deletedColumns.Clear();
63      ColumnGroup.FireChanged();
64      ColumnGroup = null;
65    }
66  }
67}
Note: See TracBrowser for help on using the repository browser.