1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using HeuristicLab.DataImporter.Command.View;
|
---|
23 | using HeuristicLab.DataImporter.Data;
|
---|
24 | using HeuristicLab.DataImporter.Data.CommandBase;
|
---|
25 | using HeuristicLab.DataImporter.Data.Model;
|
---|
26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
27 | using HEAL.Attic;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.DataImporter.Command {
|
---|
30 | [StorableType("424BD4DD-1055-4DFF-96B3-69FF9846BB0D")]
|
---|
31 | [ViewableCommandInfoAttribute("Linear Transformation", 1, ColumnGroupState.DoubleColumnSelected, "Change Values",
|
---|
32 | Position = 6, OptionsView = typeof(LinearTransformationCommandView))]
|
---|
33 | public class LinearTransformationCommand : ColumnGroupCommandWithAffectedColumnsBase {
|
---|
34 | [StorableConstructor]
|
---|
35 | protected LinearTransformationCommand(bool deserializing) : base(deserializing) { }
|
---|
36 |
|
---|
37 | public LinearTransformationCommand(DataSet dataSet, string columnGroupName, int[] affectedColumns)
|
---|
38 | : base(dataSet, columnGroupName, affectedColumns) {
|
---|
39 | }
|
---|
40 |
|
---|
41 | [Storable]
|
---|
42 | private double slope;
|
---|
43 | public double Slope {
|
---|
44 | get { return this.slope; }
|
---|
45 | set { this.slope = value; }
|
---|
46 | }
|
---|
47 |
|
---|
48 | [Storable]
|
---|
49 | private double offset;
|
---|
50 | public double Offset {
|
---|
51 | get { return this.offset; }
|
---|
52 | set { this.offset = value; }
|
---|
53 | }
|
---|
54 |
|
---|
55 | public override string Description {
|
---|
56 | get { return "Lineare Transformation"; }
|
---|
57 | }
|
---|
58 |
|
---|
59 | public override void Execute() {
|
---|
60 | base.Execute();
|
---|
61 | DoubleColumn column;
|
---|
62 | foreach (int col in AffectedColumns) {
|
---|
63 | if (ColumnGroup.GetColumn(col) is DoubleColumn) {
|
---|
64 | column = (DoubleColumn)ColumnGroup.GetColumn(col);
|
---|
65 | for (int i = 0; i < column.TotalValuesCount; i++)
|
---|
66 | if (column.GetValue(i) != null)
|
---|
67 | column.ChangeValue(i, (double)column.GetValue(i) * slope + offset);
|
---|
68 | }
|
---|
69 | }
|
---|
70 | ColumnGroup.FireChanged();
|
---|
71 | ColumnGroup = null;
|
---|
72 | }
|
---|
73 |
|
---|
74 | public override void UndoExecute() {
|
---|
75 | base.UndoExecute();
|
---|
76 | DoubleColumn column;
|
---|
77 | foreach (int col in AffectedColumns) {
|
---|
78 | if (ColumnGroup.GetColumn(col) is DoubleColumn) {
|
---|
79 | column = (DoubleColumn)ColumnGroup.GetColumn(col);
|
---|
80 | for (int i = 0; i < column.TotalValuesCount; i++)
|
---|
81 | if (column.GetValue(i) != null)
|
---|
82 | column.ChangeValue(i, ((double)column.GetValue(i) - offset) / slope);
|
---|
83 | }
|
---|
84 | }
|
---|
85 | ColumnGroup.FireChanged();
|
---|
86 | ColumnGroup = null;
|
---|
87 | }
|
---|
88 | }
|
---|
89 | }
|
---|