Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Command/MissingValues/FillMissingValuesWithMeanCommand.cs @ 6133

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

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

File size: 2.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows.Forms;
6using HeuristicLab.DataImporter.Data;
7using HeuristicLab.DataImporter.Data.CommandBase;
8using HeuristicLab.DataImporter.Data.Model;
9using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
10
11namespace HeuristicLab.DataImporter.Command {
12  [StorableClass]
13  [ViewableCommandInfoAttribute("Mean", 1, ColumnGroupState.DoubleColumnSelected | ColumnGroupState.AnySelectedColumnContainsNull,
14    "Handle Missing Values", Position = 0)]
15  public class FillMissingValuesWithMeanCommand : FillMissingValueCommandBase {
16    private FillMissingValuesWithMeanCommand()
17      : base(null, string.Empty, null) {
18    }
19
20    public FillMissingValuesWithMeanCommand(DataSet dataSet, string columnGroupName, int[] affectedColumns) :
21      base(dataSet, columnGroupName, affectedColumns) {
22    }
23
24    public override void Execute() {
25      base.Execute();
26      DoubleColumn column;
27      double? mean;
28      oldSortOrder = ColumnGroup.SortOrdersForColumns.ToList();
29      oldSortedColumnIndexes = new List<int>(ColumnGroup.SortedColumnIndexes);
30      foreach (int col in AffectedColumns) {
31        if (ColumnGroup.GetColumn(col) is DoubleColumn && ColumnGroup.GetColumn(col).ContainsNullValues) {
32          column = (DoubleColumn)ColumnGroup.Columns.ElementAt(col);
33          if (column.SortOrder != SortOrder.None)
34            ColumnGroup.ResetSorting();
35          nullValues.Add(col, new List<int>());
36          mean = column.Mean;
37          for (int j = 0; j < column.TotalValuesCount; j++) {
38            if (column.GetValue(j) == null) {
39              column.ChangeValue(j, mean);
40              this.nullValues[col].Add(j);
41            }
42          }
43        }
44      }
45      ColumnGroup.FireChanged();
46      ColumnGroup = null;
47    }
48
49    public override string Description {
50      get { return "Fill missing values with mean"; }
51    }
52  }
53}
Note: See TracBrowser for help on using the repository browser.