source: branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisTransformation.cs @ 15865

Last change on this file since 15865 was 15865, checked in by pfleck, 15 months ago

#2906 Added PreprocessingTransformation as a custom view-model for transformations in preprocessing.

File size: 4.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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 HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Problems.DataAnalysis {
30  [Item("Transformation", "A transformation applied to a DataAnalysisProblemData")]
31  [StorableClass]
32  public class DataAnalysisTransformation : ParameterizedNamedItem, IDataAnalysisTransformation {
33    #region Parameter Properties
34    private IFixedValueParameter<StringValue> OriginalVariableParameter {
35      get { return (IFixedValueParameter<StringValue>)Parameters["Original Variable"]; }
36    }
37
38    private IFixedValueParameter<StringValue> TransformedVariableParameter {
39      get { return (IFixedValueParameter<StringValue>)Parameters["Transformed Variable"]; }
40    }
41
42    private IValueParameter<ITransformation> TransformationParameter {
43      get { return (IValueParameter<ITransformation>)Parameters["Transformation"]; }
44    }
45    #endregion
46
47    #region Properties
48    public string OriginalVariable {
49      get { return OriginalVariableParameter.Value.Value; }
50      set { OriginalVariableParameter.Value.Value = value; }
51    }
52
53    public string TransformedVariable {
54      get { return TransformedVariableParameter.Value.Value; }
55      set { TransformedVariableParameter.Value.Value = value; }
56    }
57
58    public ITransformation Transformation {
59      get { return TransformationParameter.Value; }
60      set { TransformationParameter.Value = value; }
61    }
62    #endregion
63
64    #region Constructor, Cloning & Persistence
65    public DataAnalysisTransformation()
66      : this("", "", new IdentityTransformation()) {
67    }
68    public DataAnalysisTransformation(string originalVariable, string transformedVariable, ITransformation transformation)
69      : base() {
70      Parameters.Add(new FixedValueParameter<StringValue>("Original Variable", new StringValue(originalVariable)));
71      Parameters.Add(new FixedValueParameter<StringValue>("Transformed Variable", new StringValue(transformedVariable)));
72      Parameters.Add(new ValueParameter<ITransformation>("Transformation", transformation));
73
74      RegisterEventHandlers();
75    }
76
77    protected DataAnalysisTransformation(DataAnalysisTransformation original, Cloner cloner)
78      : base(original, cloner) {
79      RegisterEventHandlers();
80    }
81
82    public override IDeepCloneable Clone(Cloner cloner) {
83      return new DataAnalysisTransformation(this, cloner);
84    }
85
86    [StorableConstructor]
87    protected DataAnalysisTransformation(bool deserializing)
88      : base(deserializing) { }
89
90    [StorableHook(HookType.AfterDeserialization)]
91    private void AfterDeserialization() {
92      RegisterEventHandlers();
93    }
94    #endregion
95
96    #region Event-Handling
97    private void RegisterEventHandlers() {
98      OriginalVariableParameter.Value.ValueChanged += OriginalVariableParameterValue_ValueChanged;
99      TransformedVariableParameter.Value.ValueChanged += TransformedVariableParameterValue_ValueChanged;
100      TransformationParameter.ValueChanged += TransformationParameter_ValueChanged;
101    }
102
103    private void OriginalVariableParameterValue_ValueChanged(object sender, EventArgs e) {
104      OnToStringChanged();
105    }
106    private void TransformedVariableParameterValue_ValueChanged(object sender, EventArgs e) {
107      OnToStringChanged();
108    }
109    private void TransformationParameter_ValueChanged(object sender, EventArgs e) {
110      OnToStringChanged();
111    }
112    #endregion
113
114    public override string ToString() {
115      return $"{Transformation} ({OriginalVariable} -> {TransformedVariable})";
116    }
117  }
118}
Note: See TracBrowser for help on using the repository browser.