- Timestamp:
- 03/05/14 17:14:26 (11 years ago)
- Location:
- branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/HeuristicLab.DataPreprocessing-3.3.csproj ¶
r10549 r10550 247 247 </ProjectReference> 248 248 </ItemGroup> 249 <ItemGroup> 250 <EmbeddedResource Include="Views\DataPreprocessingView.resx"> 251 <DependentUpon>DataPreprocessingView.cs</DependentUpon> 252 </EmbeddedResource> 253 </ItemGroup> 249 254 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 250 255 <PropertyGroup> -
TabularUnified branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/PreprocessingData.cs ¶
r10548 r10550 30 30 31 31 namespace HeuristicLab.DataPreprocessing { 32 33 internal class PDSnapshot { 34 public IDictionary<int, IList> VariableValues { get; set; } 35 36 public IList<string> VariableNames { get; set; } 37 38 public double TrainingToTestRatio { get; set; } 39 40 public DataPreprocessingChangedEventType ChangedType { get; set; } 41 42 public int ChangedColumn { get; set; } 43 44 public int ChangedRow { get; set; } 45 } 46 32 47 [Item("PreprocessingData", "Represents data used for preprocessing.")] 33 48 public class PreprocessingData : NamedItem, IPreprocessingData { 34 49 50 private const int MAX_UNDO_DEPTH = 5; 51 35 52 private IDictionary<int, IList> variableValues; 36 53 … … 38 55 39 56 private double trainingToTestRatio; 57 58 private IList<PDSnapshot> undoHistory; 40 59 41 60 private PreprocessingData(PreprocessingData original, Cloner cloner) 42 61 : base(original, cloner) { 43 variableValues = new Dictionary<int, IList>(original.variableValues); 44 for (int i = 0; i < variableValues.Count; i++) 45 variableValues[i] = new ArrayList(original.variableValues[i]); 62 variableValues = CopyVariableValues(original.variableValues); 46 63 variableNames = new List<string>(original.variableNames); 47 64 trainingToTestRatio = original.trainingToTestRatio; 65 undoHistory = new List<PDSnapshot>(); 48 66 } 49 67 … … 71 89 72 90 trainingToTestRatio = (double)problemData.TrainingPartition.Size / Math.Max(problemData.Dataset.Rows, double.Epsilon); 91 undoHistory = new List<PDSnapshot>(); 73 92 } 74 93 … … 81 100 } 82 101 102 private IDictionary<int, IList> CopyVariableValues(IDictionary<int, IList> original) { 103 var copy = new Dictionary<int, IList>(variableValues); 104 for (int i = 0; i < original.Count; i++) { 105 if (variableValues[i] is IList<double>) { 106 copy[i] = new List<double>((IList<double>)variableValues[i]); 107 } else if (variableValues[i] is IList<DateTime>) { 108 copy[i] = new List<DateTime>((IList<DateTime>)variableValues[i]); 109 } else if (variableValues[i] is IList<string>) { 110 copy[i] = new List<string>((IList<string>)variableValues[i]); 111 } else { 112 throw new NotImplementedException("The Type is not Supported"); 113 } 114 } 115 return copy; 116 } 117 118 private void SaveSnapshot(DataPreprocessingChangedEventType changedType, int column, int row) { 119 PDSnapshot currentSnapshot = new PDSnapshot(); 120 currentSnapshot.VariableValues = CopyVariableValues(variableValues); 121 currentSnapshot.VariableNames = new List<string>(variableNames); 122 currentSnapshot.TrainingToTestRatio = trainingToTestRatio; 123 currentSnapshot.ChangedType = changedType; 124 currentSnapshot.ChangedColumn = column; 125 currentSnapshot.ChangedRow = row; 126 127 if (undoHistory.Count >= MAX_UNDO_DEPTH) 128 undoHistory.RemoveAt(0); 129 130 undoHistory.Add(currentSnapshot); 131 } 132 83 133 #region NamedItem abstract Member Implementations 84 134 … … 96 146 97 147 98 public void SetCell<T>(int columnIndex, int rowIndex, T value) { // Undo-sensitive 148 public void SetCell<T>(int columnIndex, int rowIndex, T value) { 149 SaveSnapshot(DataPreprocessingChangedEventType.ChangeItem, columnIndex, rowIndex); 99 150 variableValues[columnIndex][rowIndex] = value; 100 151 OnChanged(DataPreprocessingChangedEventType.ChangeItem, columnIndex, rowIndex); … … 116 167 } 117 168 118 public void SetValues<T>(int columnIndex, IList<T> values) { // Undo-sensitive169 public void SetValues<T>(int columnIndex, IList<T> values) { 119 170 if (IsType<T>(columnIndex)) { 171 SaveSnapshot(DataPreprocessingChangedEventType.ChangeColumn, columnIndex, -1); 120 172 variableValues[columnIndex] = (IList)values; 121 173 } else { … … 125 177 } 126 178 127 public void InsertRow(int rowIndex) { // Undo-sensitive 179 public void InsertRow(int rowIndex) { 180 SaveSnapshot(DataPreprocessingChangedEventType.DeleteRow, -1, rowIndex); 128 181 foreach (IList column in variableValues.Values) { 129 182 Type type = column.GetType().GetGenericArguments()[0]; … … 133 186 } 134 187 135 public void DeleteRow(int rowIndex) { // Undo-sensitive 188 public void DeleteRow(int rowIndex) { 189 SaveSnapshot(DataPreprocessingChangedEventType.AddRow, -1, rowIndex); 136 190 foreach (IList column in variableValues.Values) { 137 191 column.RemoveAt(rowIndex); … … 140 194 } 141 195 142 public void InsertColumn<T>(string variableName, int columnIndex) { // Undo-sensitive 196 public void InsertColumn<T>(string variableName, int columnIndex) { 197 SaveSnapshot(DataPreprocessingChangedEventType.DeleteColumn, columnIndex, -1); 143 198 variableValues.Add(columnIndex, new List<T>(Rows)); 144 199 variableNames.Insert(columnIndex, variableName); … … 146 201 } 147 202 148 public void DeleteColumn(int columnIndex) { // Undo-sensitive 203 public void DeleteColumn(int columnIndex) { 204 SaveSnapshot(DataPreprocessingChangedEventType.AddColumn, columnIndex, -1); 149 205 variableValues.Remove(columnIndex); 150 206 variableNames.RemoveAt(columnIndex); … … 203 259 204 260 public bool IsUndoAvailable { 205 get { throw new NotImplementedException(); }261 get { return undoHistory.Count > 0; } 206 262 } 207 263 208 264 public void Undo() { 209 throw new NotImplementedException(); 265 if (IsUndoAvailable) { 266 PDSnapshot previousSnapshot = undoHistory[undoHistory.Count - 1]; 267 variableValues = previousSnapshot.VariableValues; 268 variableNames = previousSnapshot.VariableNames; 269 trainingToTestRatio = previousSnapshot.TrainingToTestRatio; 270 undoHistory.Remove(previousSnapshot); 271 OnChanged(previousSnapshot.ChangedType, 272 previousSnapshot.ChangedColumn, 273 previousSnapshot.ChangedRow); 274 } 210 275 } 211 276 -
TabularUnified branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Views/DataPreprocessingView.cs ¶
r10539 r10550 140 140 MainFormManager.MainForm.ShowContent(item); 141 141 } 142 143 private void undoButton_Click(object sender, EventArgs e) { 144 Content.Data.Undo(); 145 } 142 146 } 143 147 } -
TabularUnified branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Views/DataPreprocessingView.designer.cs ¶
r10539 r10550 45 45 private void InitializeComponent() { 46 46 this.components = new System.ComponentModel.Container(); 47 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DataPreprocessingView)); 47 48 this.splitContainer1 = new System.Windows.Forms.SplitContainer(); 48 49 this.undoButton = new System.Windows.Forms.Button(); … … 81 82 // undoButton 82 83 // 83 this.undoButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Undo;84 this.undoButton.Image = ((System.Drawing.Image)(resources.GetObject("undoButton.Image"))); 84 85 this.undoButton.Location = new System.Drawing.Point(72, 14); 85 86 this.undoButton.Name = "undoButton"; … … 88 89 this.toolTip.SetToolTip(this.undoButton, "Undo"); 89 90 this.undoButton.UseVisualStyleBackColor = true; 91 this.undoButton.Click += new System.EventHandler(this.undoButton_Click); 90 92 // 91 93 // applyInNewTabButton 92 94 // 93 this.applyInNewTabButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Play;95 this.applyInNewTabButton.Image = ((System.Drawing.Image)(resources.GetObject("applyInNewTabButton.Image"))); 94 96 this.applyInNewTabButton.Location = new System.Drawing.Point(42, 14); 95 97 this.applyInNewTabButton.Name = "applyInNewTabButton"; … … 102 104 // exportProblemButton 103 105 // 104 this.exportProblemButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Save;106 this.exportProblemButton.Image = ((System.Drawing.Image)(resources.GetObject("exportProblemButton.Image"))); 105 107 this.exportProblemButton.Location = new System.Drawing.Point(12, 14); 106 108 this.exportProblemButton.Name = "exportProblemButton"; … … 113 115 // contentListView 114 116 // 115 this.contentListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 116 | System.Windows.Forms.AnchorStyles.Left) 117 this.contentListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 118 | System.Windows.Forms.AnchorStyles.Left) 117 119 | System.Windows.Forms.AnchorStyles.Right))); 118 120 this.contentListView.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); … … 128 130 // viewHost 129 131 // 130 this.viewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 131 | System.Windows.Forms.AnchorStyles.Left) 132 this.viewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 133 | System.Windows.Forms.AnchorStyles.Left) 132 134 | System.Windows.Forms.AnchorStyles.Right))); 133 135 this.viewHost.Caption = "View";
Note: See TracChangeset
for help on using the changeset viewer.