Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Command/ChangeValues/LinearTransformationCommand.cs @ 9596

Last change on this file since 9596 was 7267, checked in by gkronber, 13 years ago

#1734 updated copyright year in all files of the DataImporter branch

File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using System.Xml;
27using HeuristicLab.DataImporter.Data;
28using HeuristicLab.DataImporter.Data.CommandBase;
29using HeuristicLab.DataImporter.Data.Model;
30using HeuristicLab.DataImporter.Command.View;
31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
32
33namespace HeuristicLab.DataImporter.Command {
34  [StorableClass]
35  [ViewableCommandInfoAttribute("Linear Transformation", 1, ColumnGroupState.DoubleColumnSelected, "Change Values",
36  Position = 6, OptionsView = typeof(LinearTransformationCommandView))]
37  public class LinearTransformationCommand : ColumnGroupCommandWithAffectedColumnsBase {
38    private LinearTransformationCommand()
39      : base(null, string.Empty, null) {
40    }
41
42    public LinearTransformationCommand(DataSet dataSet, string columnGroupName, int[] affectedColumns)
43      : base(dataSet, columnGroupName, affectedColumns) {
44    }
45
46    [Storable]
47    private double slope;
48    public double Slope {
49      get { return this.slope; }
50      set { this.slope = value; }
51    }
52
53    [Storable]
54    private double offset;
55    public double Offset {
56      get { return this.offset; }
57      set { this.offset = value; }
58    }
59
60    public override string Description {
61      get { return "Lineare Transformation"; }
62    }
63
64    public override void Execute() {
65      base.Execute();
66      DoubleColumn column;
67      foreach (int col in AffectedColumns) {
68        if (ColumnGroup.GetColumn(col) is DoubleColumn) {
69          column = (DoubleColumn)ColumnGroup.GetColumn(col);
70          for (int i = 0; i < column.TotalValuesCount; i++)
71            if (column.GetValue(i) != null)
72              column.ChangeValue(i, (double)column.GetValue(i) * slope + offset);
73        }
74      }
75      ColumnGroup.FireChanged();
76      ColumnGroup = null;
77    }
78
79    public override void UndoExecute() {
80      base.UndoExecute();
81      DoubleColumn column;
82      foreach (int col in AffectedColumns) {
83        if (ColumnGroup.GetColumn(col) is DoubleColumn) {
84          column = (DoubleColumn)ColumnGroup.GetColumn(col);
85          for (int i = 0; i < column.TotalValuesCount; i++)
86            if (column.GetValue(i) != null)
87              column.ChangeValue(i, ((double)column.GetValue(i) - offset) / slope);
88        }
89      }
90      ColumnGroup.FireChanged();
91      ColumnGroup = null;
92    }
93  }
94}
Note: See TracBrowser for help on using the repository browser.