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 | [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 | }
|
---|