using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; using HeuristicLab.DataImporter.Data; using HeuristicLab.DataImporter.Data.CommandBase; using HeuristicLab.DataImporter.Data.Model; using HeuristicLab.DataImporter.Command.View; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.DataImporter.Command { [StorableClass] [ViewableCommandInfoAttribute("Delete Columns with too few Values", 1, ColumnGroupState.Active, "ColumnGroup Commands", Position = 14, OptionsView = typeof(ThresholdCommandView))] public class DeleteColumnsWithTooFewValuesCommand : ColumnGroupCommandBase { private SortedDictionary deletedColumns; private ICollection oldSortedColumnIndices; [StorableConstructor] protected DeleteColumnsWithTooFewValuesCommand(bool deserializing) : base(deserializing) { deletedColumns = new SortedDictionary(); } public DeleteColumnsWithTooFewValuesCommand(DataSet dataSet, string columnGroupName) : base(dataSet, columnGroupName) { deletedColumns = new SortedDictionary(); } [Storable] private double threshold; public double Threshold { get { return this.threshold; } set { this.threshold = value; } } public override string Description { get { return "Delete Columns with too few values"; } } public override void Execute() { base.Execute(); ColumnBase column; for (int i = 0; i < ColumnGroup.Columns.Count(); i++) { column = ColumnGroup.GetColumn(i); if ((1 - ((double)column.NullValuesCount) / column.TotalValuesCount) < threshold) deletedColumns.Add(i, column); } oldSortedColumnIndices = new List(ColumnGroup.SortedColumnIndexes); foreach (ColumnBase col in deletedColumns.Values) ColumnGroup.RemoveColumn(col); ColumnGroup.FireChanged(); ColumnGroup = null; } public override void UndoExecute() { base.UndoExecute(); foreach (KeyValuePair pair in deletedColumns) ColumnGroup.InsertColumn(pair.Key, pair.Value); ColumnGroup.SortedColumnIndexes = oldSortedColumnIndices; oldSortedColumnIndices = null; deletedColumns.Clear(); ColumnGroup.FireChanged(); ColumnGroup = null; } } }