#region License Information /* HeuristicLab * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using HeuristicLab.DataImporter.Command.View; using HeuristicLab.DataImporter.Data; using HeuristicLab.DataImporter.Data.CommandBase; using HeuristicLab.DataImporter.Data.Model; using HEAL.Attic; namespace HeuristicLab.DataImporter.Command { [StorableType("EBD5BEAE-D8B0-42BB-B153-BFF2A58CA169")] [ViewableCommandInfoAttribute("Delete Columns beneath Threshold", 1, ColumnGroupState.AnySelectedColumnContainsNull, "Handle Missing Values", Position = 6, OptionsView = typeof(DeleteWithThresholdView))] public class DeleteColumnsWithMissingValuesThresholdCommand : ColumnGroupCommandWithAffectedColumnsBase, IThresholdCommand { private ColumnBase oldColumn; private int oldColumnIndex; [Storable] private double threshold = 0.8; public double Threshold { get { return threshold; } set { threshold = value; } } [StorableConstructor] protected DeleteColumnsWithMissingValuesThresholdCommand(StorableConstructorFlag _) : base(_) { } public DeleteColumnsWithMissingValuesThresholdCommand(DataSet dataSet, string columnGroupName, int[] affectedColumns) : base(dataSet, columnGroupName, affectedColumns) { } public override void Execute() { base.Execute(); oldColumnIndex = AffectedColumns[0]; oldColumn = ColumnGroup.GetColumn(oldColumnIndex); if ((double)oldColumn.NonNullValuesCount / (double)oldColumn.TotalValuesCount < Threshold) { ColumnGroup.RemoveColumn(oldColumn); } else { oldColumn = null; } ColumnGroup.FireChanged(); ColumnGroup = null; } public override void UndoExecute() { base.UndoExecute(); if (oldColumn != null) { ColumnGroup.InsertColumn(oldColumnIndex, oldColumn); } oldColumn = null; oldColumnIndex = -1; ColumnGroup.FireChanged(); ColumnGroup = null; } public override string Description { get { return "Delete columns with a missing value percentage beneath a certain threshold"; } } } }