- Timestamp:
- 01/14/16 17:51:48 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.DataPreprocessing/3.4/PreprocessingContext.cs
r13507 r13508 35 35 public string Filename { get; set; } 36 36 37 public IEnumerable<KeyValuePair<string, Func<IItem>>> ExportPossibilities {38 get {39 var algorithm = Source as IAlgorithm;40 if (algorithm != null)41 yield return new KeyValuePair<string, Func<IItem>>(algorithm.GetType().GetPrettyName(), () => ExportAlgorithm(algorithm));42 43 var problem = algorithm != null ? algorithm.Problem as IDataAnalysisProblem : Source as IDataAnalysisProblem;44 if (problem != null)45 yield return new KeyValuePair<string, Func<IItem>>(problem.GetType().GetPrettyName(), () => ExportProblem(problem));46 47 var problemData = problem != null ? problem.ProblemData : Source as IDataAnalysisProblemData;48 if (problemData != null)49 yield return new KeyValuePair<string, Func<IItem>>(problemData.GetType().GetPrettyName(), () => ExportProblemData(problemData));50 51 // ToDo: Export CSV52 }53 }54 public bool CanExport {55 get { return Source is IAlgorithm || Source is IDataAnalysisProblem || Source is IDataAnalysisProblemData; }56 }57 58 37 [Storable] 59 38 public IFilteredPreprocessingData Data { get; private set; } … … 62 41 private IItem Source { get; set; } 63 42 43 public event EventHandler Reset; 64 44 65 public PreprocessingContext() : this(new RegressionProblemData()) { 66 Name = "Data Preprocessing"; 45 #region Constructors 46 public PreprocessingContext() 47 : this(new RegressionProblemData()) { 67 48 } 68 public PreprocessingContext(I Item source)49 public PreprocessingContext(IDataAnalysisProblemData problemData, IItem source = null) 69 50 : base("Data Preprocessing") { 70 Import(source); 51 if (problemData == null) throw new ArgumentNullException("problemData"); 52 Import(problemData, source); 71 53 } 72 54 … … 79 61 Data = cloner.Clone(original.Data); 80 62 } 81 82 63 public override IDeepCloneable Clone(Cloner cloner) { 83 64 return new PreprocessingContext(this, cloner); 84 65 } 66 #endregion 85 67 86 68 #region Import 87 public void Import(IItem source) { 88 Source = source; 89 var namedSource = source as INamedItem; 90 if (namedSource != null) Name = "Preprocessing: " + namedSource.Name; 91 92 var dataSource = ExtractProblemData(source); 93 Data = new FilteredPreprocessingData(new TransactionalPreprocessingData(dataSource)); 69 public void Import(IDataAnalysisProblemData problemData, IItem source = null) { 70 if (problemData == null) throw new ArgumentNullException("problemData"); 71 if (source != null && ExtractProblemData(source) != problemData) 72 throw new ArgumentException("The ProblemData extracted from the Source is different than the given ProblemData."); 73 Source = source ?? problemData; 74 var namedSource = Source as INamedItem; 75 if (namedSource != null) 76 Name = "Preprocessing " + namedSource.Name; 77 Data = new FilteredPreprocessingData(new TransactionalPreprocessingData(problemData)); 78 OnReset(); 79 // Reset GUI: 80 // - OnContentChanged for PreprocessingView! 81 // event? task(async import)? 94 82 } 95 96 83 private IDataAnalysisProblemData ExtractProblemData(IItem source) { 97 84 var algorithm = source as Algorithm; … … 103 90 104 91 #region Export 105 public IItem Export() { 106 if (Source is IAlgorithm) 107 return ExportAlgorithm((IAlgorithm)Source); 108 if (Source is IDataAnalysisProblem) 109 return ExportProblem((IDataAnalysisProblem)Source); 110 if (Source is IDataAnalysisProblemData) 111 return ExportProblemData((IDataAnalysisProblemData)Source); 112 return null; 92 public bool CanExport { 93 get { return Source is IAlgorithm || Source is IDataAnalysisProblem || Source is IDataAnalysisProblemData; } 113 94 } 95 public IEnumerable<KeyValuePair<string, Func<IItem>>> GetSourceExportOptions() { 96 var algorithm = Source as IAlgorithm; 97 if (algorithm != null) 98 yield return new KeyValuePair<string, Func<IItem>>( 99 algorithm.GetType().GetPrettyName(), 100 () => ExportAlgorithm(algorithm)); 101 102 var problem = algorithm != null ? algorithm.Problem as IDataAnalysisProblem : Source as IDataAnalysisProblem; 103 if (problem != null) 104 yield return new KeyValuePair<string, Func<IItem>>( 105 problem.GetType().GetPrettyName(), 106 () => ExportProblem(problem)); 107 108 var problemData = problem != null ? problem.ProblemData : Source as IDataAnalysisProblemData; 109 if (problemData != null) 110 yield return new KeyValuePair<string, Func<IItem>>( 111 problemData.GetType().GetPrettyName(), 112 () => ExportProblemData(problemData)); 113 } 114 114 115 private IAlgorithm ExportAlgorithm(IAlgorithm source) { 115 116 var preprocessedAlgorithm = (IAlgorithm)source.Clone(); … … 117 118 preprocessedAlgorithm.Runs.Clear(); 118 119 var problem = (IDataAnalysisProblem)preprocessedAlgorithm.Problem; 119 SetNewProblemData(problem);120 problem.ProblemDataParameter.ActualValue = CreateNewProblemData(); 120 121 return preprocessedAlgorithm; 121 122 } 122 123 private IDataAnalysisProblem ExportProblem(IDataAnalysisProblem source) { 123 124 var preprocessedProblem = (IDataAnalysisProblem)source.Clone(); 124 SetNewProblemData(preprocessedProblem);125 preprocessedProblem.ProblemDataParameter.ActualValue = CreateNewProblemData(); 125 126 return preprocessedProblem; 126 127 } 127 128 private IDataAnalysisProblemData ExportProblemData(IDataAnalysisProblemData source) { 129 return CreateNewProblemData(); 130 } 131 132 public IDataAnalysisProblemData CreateNewProblemData() { 128 133 var creator = new ProblemDataCreator(this); 129 var preprocessedProblemData = creator.CreateProblemData(source); 130 preprocessedProblemData.Name = "Preprocessed " + source.Name; 131 return preprocessedProblemData; 132 } 133 private void SetNewProblemData(IDataAnalysisProblem problem) { 134 var data = ExtractProblemData(problem.ProblemData); 135 problem.ProblemDataParameter.ActualValue = data; 136 problem.Name = "Preprocessed " + problem.Name; 134 var oldProblemData = ExtractProblemData(Source); 135 var newProblemData = creator.CreateProblemData(oldProblemData); 136 newProblemData.Name = "Preprocessed " + oldProblemData.Name; 137 return newProblemData; 137 138 } 138 139 #endregion 140 141 protected virtual void OnReset() { 142 if (Reset != null) 143 Reset(this, EventArgs.Empty); 144 } 139 145 } 140 146 }
Note: See TracChangeset
for help on using the changeset viewer.