Ignore:
Timestamp:
03/27/18 15:46:12 (3 years ago)
Author:
pfleck
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2906_Transformations/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisTransformation.cs

    r15858 r15865  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Runtime.CompilerServices;
    2623using HeuristicLab.Common;
    2724using HeuristicLab.Core;
     
    3431  [StorableClass]
    3532  public class DataAnalysisTransformation : ParameterizedNamedItem, IDataAnalysisTransformation {
    36     #region Parameters
    37     public IConstrainedValueParameter<StringValue> OriginalVariableParameter {
    38       get { return (IConstrainedValueParameter<StringValue>)Parameters["Original Variable"]; }
     33    #region Parameter Properties
     34    private IFixedValueParameter<StringValue> OriginalVariableParameter {
     35      get { return (IFixedValueParameter<StringValue>)Parameters["Original Variable"]; }
    3936    }
    4037
    41     public IConstrainedValueParameter<StringValue> TransformedVariableParameter {
    42       get { return (IConstrainedValueParameter<StringValue>)Parameters["Transformed Variable"]; }
     38    private IFixedValueParameter<StringValue> TransformedVariableParameter {
     39      get { return (IFixedValueParameter<StringValue>)Parameters["Transformed Variable"]; }
    4340    }
    4441
    45     public IValueParameter<ITransformation> TransformationParameter {
     42    private IValueParameter<ITransformation> TransformationParameter {
    4643      get { return (IValueParameter<ITransformation>)Parameters["Transformation"]; }
    4744    }
     
    5148    public string OriginalVariable {
    5249      get { return OriginalVariableParameter.Value.Value; }
    53       set { SetConstrainedValue(OriginalVariableParameter, value); }
     50      set { OriginalVariableParameter.Value.Value = value; }
    5451    }
    5552
    5653    public string TransformedVariable {
    5754      get { return TransformedVariableParameter.Value.Value; }
    58       set { SetConstrainedValue(TransformedVariableParameter, value); }
     55      set { TransformedVariableParameter.Value.Value = value; }
    5956    }
    6057
     
    6360      set { TransformationParameter.Value = value; }
    6461    }
    65 
    66     private static void SetConstrainedValue(IConstrainedValueParameter<StringValue> parameter, string value, [CallerMemberName] string caller = null) {
    67       if (value == null) throw new ArgumentNullException(caller);
    68       if (value == parameter.Value.Value) return;
    69 
    70       var matchingValue = parameter.ValidValues.SingleOrDefault(v => v.Value == value);
    71       if (matchingValue == null) throw new ArgumentException("The provided value is not valid.", caller);
    72       parameter.Value = matchingValue;
    73     }
    7462    #endregion
    7563
    7664    #region Constructor, Cloning & Persistence
    77     public DataAnalysisTransformation(IEnumerable<StringValue> variableNames)
     65    public DataAnalysisTransformation()
     66      : this("", "", new IdentityTransformation()) {
     67    }
     68    public DataAnalysisTransformation(string originalVariable, string transformedVariable, ITransformation transformation)
    7869      : base() {
    79       var originalVariables = new ItemSet<StringValue>(variableNames.Select(x => x.AsReadOnly()));
    80       var transformedVariables = new ItemSet<StringValue>(variableNames.Select(x => x.AsReadOnly()));
    81       Parameters.Add(new ConstrainedValueParameter<StringValue>("Original Variable", new ItemSet<StringValue>(originalVariables), originalVariables.FirstOrDefault()));
    82       Parameters.Add(new ConstrainedValueParameter<StringValue>("Transformed Variable", new ItemSet<StringValue>(transformedVariables), transformedVariables.FirstOrDefault()));
    83 
    84       //var transformations = new ItemSet<ITransformation>(ApplicationManager.Manager.GetInstances<ITransformation>());
    85       Parameters.Add(new ValueParameter<ITransformation>("Transformation", new IdentityTransformation()));
     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));
    8673
    8774      RegisterEventHandlers();
     
    10996    #region Event-Handling
    11097    private void RegisterEventHandlers() {
    111       OriginalVariableParameter.ValueChanged += OriginalVariableParameter_ValueChanged;
    112       TransformedVariableParameter.ValueChanged += TransformedVariableParameter_ValueChanged;
     98      OriginalVariableParameter.Value.ValueChanged += OriginalVariableParameterValue_ValueChanged;
     99      TransformedVariableParameter.Value.ValueChanged += TransformedVariableParameterValue_ValueChanged;
    113100      TransformationParameter.ValueChanged += TransformationParameter_ValueChanged;
    114101    }
    115102
    116     private void OriginalVariableParameter_ValueChanged(object sender, EventArgs e) {
    117       OriginalVariableParameter.Value.ValueChanged += OriginalVariableParameterValue_ValueChanged;
    118       OnToStringChanged();
    119     }
    120103    private void OriginalVariableParameterValue_ValueChanged(object sender, EventArgs e) {
    121       OnToStringChanged();
    122     }
    123 
    124     private void TransformedVariableParameter_ValueChanged(object sender, EventArgs e) {
    125       TransformedVariableParameter.Value.ValueChanged += TransformedVariableParameterValue_ValueChanged;
    126104      OnToStringChanged();
    127105    }
     
    129107      OnToStringChanged();
    130108    }
    131 
    132109    private void TransformationParameter_ValueChanged(object sender, EventArgs e) {
    133110      OnToStringChanged();
    134111    }
    135112    #endregion
    136 
    137113
    138114    public override string ToString() {
Note: See TracChangeset for help on using the changeset viewer.