- Timestamp:
- 03/19/18 10:25:45 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2906_Transformations/HeuristicLab.DataPreprocessing/3.4/Content/TransformationContent.cs
r15583 r15846 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using System.Drawing; 24 using System.Linq; 23 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Core; … … 35 37 36 38 [Storable] 37 public ICheckedItemList<I Transformation> CheckedTransformationList { get; private set; }39 public ICheckedItemList<IDataAnalysisTransformation> CheckedTransformationList { get; private set; } 38 40 39 41 #region Constructor, Cloning & Persistence 40 42 public TransformationContent(IFilteredPreprocessingData preprocessingData) 41 43 : base(preprocessingData) { 42 CheckedTransformationList = new CheckedItemList<I Transformation>();44 CheckedTransformationList = new CheckedItemList<IDataAnalysisTransformation>(); 43 45 } 44 46 … … 55 57 : base(deserializing) { } 56 58 #endregion 59 60 public bool ApplyTransformations(out IEnumerable<string> errorMessages) { 61 var transformations = CheckedTransformationList.CheckedItems.Select(x => x.Value); 62 63 bool success = true; 64 var errors = new List<string>(); 65 errorMessages = errors; 66 67 foreach (var transformation in transformations) { 68 var sourceVariable = transformation.OriginalVariable; 69 var targetVariable = transformation.TransformedVariable ?? sourceVariable + " Transformed"; 70 var sourceIdx = PreprocessingData.GetColumnIndex(sourceVariable); 71 72 if (transformation.Transformation is ITransformation<double> trans && PreprocessingData.VariableHasType<double>(sourceIdx)) { 73 if (!PreprocessingData.VariableNames.Contains(targetVariable)) 74 PreprocessingData.InsertColumn<double>(targetVariable, PreprocessingData.Columns); 75 var targetIdx = PreprocessingData.GetColumnIndex(targetVariable); 76 77 if (!PreprocessingData.VariableHasType<double>(targetIdx)) { success = false; errors.Add("Target column is not double."); continue; } 78 79 var sourceData = PreprocessingData.GetValues<double>(sourceIdx); 80 if (!trans.Check(sourceData, out string msg)) { success = false; errors.Add(msg); continue; } 81 82 trans.Configure(sourceData); 83 var transformedData = trans.Apply(sourceData).ToList(); 84 85 PreprocessingData.SetValues(targetIdx, transformedData); 86 87 PreprocessingData.Transformations.Add(transformation); 88 CheckedTransformationList.SetItemCheckedState(transformation, false); 89 } else { 90 success = false; 91 errors.Add("Transformation datatype is not supported."); 92 } 93 } 94 95 return success; 96 } 57 97 } 58 98 }
Note: See TracChangeset
for help on using the changeset viewer.