Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10550


Ignore:
Timestamp:
03/05/14 17:14:26 (10 years ago)
Author:
tsteinre
Message:

implemented Undo-feature of PreprocessingData

Location:
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/HeuristicLab.DataPreprocessing-3.3.csproj

    r10549 r10550  
    247247    </ProjectReference>
    248248  </ItemGroup>
     249  <ItemGroup>
     250    <EmbeddedResource Include="Views\DataPreprocessingView.resx">
     251      <DependentUpon>DataPreprocessingView.cs</DependentUpon>
     252    </EmbeddedResource>
     253  </ItemGroup>
    249254  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    250255  <PropertyGroup>
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/PreprocessingData.cs

    r10548 r10550  
    3030
    3131namespace 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
    3247  [Item("PreprocessingData", "Represents data used for preprocessing.")]
    3348  public class PreprocessingData : NamedItem, IPreprocessingData {
    3449
     50    private const int MAX_UNDO_DEPTH = 5;
     51
    3552    private IDictionary<int, IList> variableValues;
    3653
     
    3855
    3956    private double trainingToTestRatio;
     57
     58    private IList<PDSnapshot> undoHistory;
    4059
    4160    private PreprocessingData(PreprocessingData original, Cloner cloner)
    4261      : 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);
    4663      variableNames = new List<string>(original.variableNames);
    4764      trainingToTestRatio = original.trainingToTestRatio;
     65      undoHistory = new List<PDSnapshot>();
    4866    }
    4967
     
    7189
    7290      trainingToTestRatio = (double)problemData.TrainingPartition.Size / Math.Max(problemData.Dataset.Rows, double.Epsilon);
     91      undoHistory = new List<PDSnapshot>();
    7392    }
    7493
     
    81100    }
    82101
     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
    83133    #region NamedItem abstract Member Implementations
    84134
     
    96146
    97147
    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);
    99150      variableValues[columnIndex][rowIndex] = value;
    100151      OnChanged(DataPreprocessingChangedEventType.ChangeItem, columnIndex, rowIndex);
     
    116167    }
    117168
    118     public void SetValues<T>(int columnIndex, IList<T> values) {    // Undo-sensitive
     169    public void SetValues<T>(int columnIndex, IList<T> values) {
    119170      if (IsType<T>(columnIndex)) {
     171        SaveSnapshot(DataPreprocessingChangedEventType.ChangeColumn, columnIndex, -1);
    120172        variableValues[columnIndex] = (IList)values;
    121173      } else {
     
    125177    }
    126178
    127     public void InsertRow(int rowIndex) {    // Undo-sensitive
     179    public void InsertRow(int rowIndex) {
     180      SaveSnapshot(DataPreprocessingChangedEventType.DeleteRow, -1, rowIndex);
    128181      foreach (IList column in variableValues.Values) {
    129182        Type type = column.GetType().GetGenericArguments()[0];
     
    133186    }
    134187
    135     public void DeleteRow(int rowIndex) {    // Undo-sensitive
     188    public void DeleteRow(int rowIndex) {
     189      SaveSnapshot(DataPreprocessingChangedEventType.AddRow, -1, rowIndex);
    136190      foreach (IList column in variableValues.Values) {
    137191        column.RemoveAt(rowIndex);
     
    140194    }
    141195
    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);
    143198      variableValues.Add(columnIndex, new List<T>(Rows));
    144199      variableNames.Insert(columnIndex, variableName);
     
    146201    }
    147202
    148     public void DeleteColumn(int columnIndex) {    // Undo-sensitive
     203    public void DeleteColumn(int columnIndex) {
     204      SaveSnapshot(DataPreprocessingChangedEventType.AddColumn, columnIndex, -1);
    149205      variableValues.Remove(columnIndex);
    150206      variableNames.RemoveAt(columnIndex);
     
    203259
    204260    public bool IsUndoAvailable {
    205       get { throw new NotImplementedException(); }
     261      get { return undoHistory.Count > 0; }
    206262    }
    207263
    208264    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      }
    210275    }
    211276
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Views/DataPreprocessingView.cs

    r10539 r10550  
    140140      MainFormManager.MainForm.ShowContent(item);
    141141    }
     142
     143    private void undoButton_Click(object sender, EventArgs e) {
     144      Content.Data.Undo();
     145    }
    142146  }
    143147}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Views/DataPreprocessingView.designer.cs

    r10539 r10550  
    4545    private void InitializeComponent() {
    4646      this.components = new System.ComponentModel.Container();
     47      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DataPreprocessingView));
    4748      this.splitContainer1 = new System.Windows.Forms.SplitContainer();
    4849      this.undoButton = new System.Windows.Forms.Button();
     
    8182      // undoButton
    8283      //
    83       this.undoButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Undo;
     84      this.undoButton.Image = ((System.Drawing.Image)(resources.GetObject("undoButton.Image")));
    8485      this.undoButton.Location = new System.Drawing.Point(72, 14);
    8586      this.undoButton.Name = "undoButton";
     
    8889      this.toolTip.SetToolTip(this.undoButton, "Undo");
    8990      this.undoButton.UseVisualStyleBackColor = true;
     91      this.undoButton.Click += new System.EventHandler(this.undoButton_Click);
    9092      //
    9193      // applyInNewTabButton
    9294      //
    93       this.applyInNewTabButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Play;
     95      this.applyInNewTabButton.Image = ((System.Drawing.Image)(resources.GetObject("applyInNewTabButton.Image")));
    9496      this.applyInNewTabButton.Location = new System.Drawing.Point(42, 14);
    9597      this.applyInNewTabButton.Name = "applyInNewTabButton";
     
    102104      // exportProblemButton
    103105      //
    104       this.exportProblemButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Save;
     106      this.exportProblemButton.Image = ((System.Drawing.Image)(resources.GetObject("exportProblemButton.Image")));
    105107      this.exportProblemButton.Location = new System.Drawing.Point(12, 14);
    106108      this.exportProblemButton.Name = "exportProblemButton";
     
    113115      // contentListView
    114116      //
    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) 
    117119            | System.Windows.Forms.AnchorStyles.Right)));
    118120      this.contentListView.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     
    128130      // viewHost
    129131      //
    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) 
    132134            | System.Windows.Forms.AnchorStyles.Right)));
    133135      this.viewHost.Caption = "View";
Note: See TracChangeset for help on using the changeset viewer.