Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/26/14 16:11:08 (10 years ago)
Author:
sbreuer
Message:
  • change function headers in manipulationlogic to interface datatypes
  • implemented find and replace logic
Location:
branches/DataPreprocessing
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/DataGridContentView.cs

    r10668 r10672  
    2525using System.Linq;
    2626using System.Windows.Forms;
     27using HeuristicLab.Data;
    2728using HeuristicLab.MainForm;
    2829
     
    3435    private bool notOwnEvent = true;
    3536    private FindAndReplaceDialog findAndReplaceDialog;
     37    private IDictionary<int, IList<int>> foundCells;
     38    private Tuple<int, int> currentCell;
     39    private string currentSearchText;
    3640
    3741    public new IDataGridContent Content {
     
    146150      findAndReplaceDialog.FindNextEvent += findAndReplaceDialog_FindNextEvent;
    147151      findAndReplaceDialog.ReplaceAllEvent += findAndReplaceDialog_ReplaceAllEvent;
    148       findAndReplaceDialog.ReplaceNextEvent += findAndReplaceDialog_ReplaceNextEvent;
    149     }
    150 
    151     void findAndReplaceDialog_ReplaceNextEvent(object sender, EventArgs e) {
    152       throw new NotImplementedException();
     152      findAndReplaceDialog.ReplaceNextEvent += findAndReplaceDialog_ReplaceEvent;
     153      foundCells = null;
     154      currentCell = null;
     155    }
     156
     157    void findAndReplaceDialog_ReplaceEvent(object sender, EventArgs e) {
     158      if (foundCells != null)
     159      {
     160        Replace(GetIndexOfCurrentSelectedCell());
     161      }
    153162    }
    154163
    155164    void findAndReplaceDialog_ReplaceAllEvent(object sender, EventArgs e) {
    156       throw new NotImplementedException();
     165      Replace(FindAll(findAndReplaceDialog.GetSearchText()));
    157166    }
    158167
    159168    void findAndReplaceDialog_FindNextEvent(object sender, EventArgs e) {
    160       throw new NotImplementedException();
     169      IDictionary<int, IList<int>> highlightCell;
     170      do {
     171        if (foundCells == null || currentSearchText != findAndReplaceDialog.GetSearchText()) {
     172          currentSearchText = findAndReplaceDialog.GetSearchText();
     173          foundCells = FindAll(findAndReplaceDialog.GetSearchText());
     174          currentCell = new Tuple<int, int>(0, 0);
     175        } else {
     176          if (currentCell.Item2 < foundCells[currentCell.Item1].Count - 1) {
     177            currentCell = new Tuple<int, int>(currentCell.Item1, currentCell.Item2 + 1);
     178          } else if (currentCell.Item1 < foundCells.Count - 1) {
     179            currentCell = new Tuple<int, int>(currentCell.Item1 + 1, 0);
     180          } else {
     181            currentCell = new Tuple<int, int>(0, 0);
     182          }
     183        }
     184
     185        highlightCell = GetIndexOfCurrentSelectedCell();
     186
     187      } while (!Content.GetValue(currentCell.Item1, highlightCell[currentCell.Item1].ElementAt(0)).Equals(currentSearchText));
     188      HightlightedCells = highlightCell;
    161189    }
    162190
    163191    void findAndReplaceDialog_FindAllEvent(object sender, EventArgs e) {
    164       throw new NotImplementedException();
     192      HightlightedCells = FindAll(findAndReplaceDialog.GetSearchText());
     193    }
     194
     195    private IDictionary<int, IList<int>> FindAll(string match) {
     196      var comparisonFilter = new Filter.ComparisonFilter(Content.FilterLogic.PreprocessingData, Core.ConstraintOperation.Equal, new StringValue(match), true);
     197      var filters = new List<Filter.IFilter>() { comparisonFilter };
     198      var foundCells = new Dictionary<int, IList<int>>();
     199      for (int i = 0; i < Content.FilterLogic.PreprocessingData.Columns; i++) {
     200        comparisonFilter.ConstraintColumn = i;
     201        bool[] filteredRows = Content.FilterLogic.Preview(filters);
     202        foundCells[i] = filteredRows.Select((value, index) => new { Index = index, Value = value })
     203          .Where(pair => pair.Value)
     204          .Select(pair => pair.Index)
     205          .ToList();
     206      }
     207      return foundCells;
     208    }
     209
     210    private void Replace(IDictionary<int, IList<int>> cells) {
     211      if (findAndReplaceDialog != null) {
     212        switch (findAndReplaceDialog.GetReplaceAction()) {
     213          case ReplaceAction.Value:
     214            Content.PreprocessingDataManipulation.ReplaceIndicesByValue(cells, findAndReplaceDialog.GetReplaceText());
     215            break;
     216          case ReplaceAction.Average:
     217            Content.PreprocessingDataManipulation.ReplaceIndicesByAverageValue(cells);
     218            break;
     219          case ReplaceAction.Median:
     220            Content.PreprocessingDataManipulation.ReplaceIndicesByMedianValue(cells);
     221            break;
     222          case ReplaceAction.Random:
     223            Content.PreprocessingDataManipulation.ReplaceIndicesByRandomValue(cells);
     224            break;
     225          case ReplaceAction.MostCommon:
     226            Content.PreprocessingDataManipulation.ReplaceIndicesByMostCommonValue(cells);
     227            break;
     228          case ReplaceAction.Interpolation:
     229            Content.PreprocessingDataManipulation.ReplaceIndicesByLinearInterpolationOfNeighbours(cells);
     230            break;
     231        }
     232      }
     233    }
     234
     235    private IDictionary<int, IList<int>> GetIndexOfCurrentSelectedCell() {
     236      var highlightCells = new Dictionary<int, IList<int>>();
     237      int highlightCell = foundCells[currentCell.Item1].ElementAt(currentCell.Item2);
     238      highlightCells.Add(currentCell.Item1, new List<int>() { highlightCell });
     239      return highlightCells;
    165240    }
    166241
     
    254329    }
    255330
    256     private Dictionary<int, List<int>> GetSelectedCells() {
    257       var selectedCells = new Dictionary<int, List<int>>();
     331    private IDictionary<int, IList<int>> GetSelectedCells() {
     332      IDictionary<int, IList<int>> selectedCells = new Dictionary<int, IList<int>>();
    258333      for (int i = 0; i < dataGridView.SelectedCells.Count; i++) {
    259334        var columnIndex = dataGridView.SelectedCells[i].ColumnIndex;
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/DataPreprocessingView.cs

    r10658 r10672  
    4848        var dataGridLogic = new DataGridLogic(data);
    4949        var statisticsLogic = new StatisticsLogic(data, searchLogic);
    50         var manipulationLogic = new ManipulationLogic(data, searchLogic, statisticsLogic);
     50        var manipulationLogic = new ManipulationLogic(data, searchLogic, statisticsLogic, dataGridLogic);
    5151        var transformationLogic = new TransformationLogic(data, searchLogic, statisticsLogic);
    5252        var lineChartLogic = new ChartLogic(data);
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/FindAndReplaceDialog.Designer.cs

    r10636 r10672  
    2626      this.tabSearchReplace = new System.Windows.Forms.TabControl();
    2727      this.tabSearch = new System.Windows.Forms.TabPage();
     28      this.tabReplace = new System.Windows.Forms.TabPage();
    2829      this.txtSearchString = new System.Windows.Forms.TextBox();
    2930      this.lblSearch = new System.Windows.Forms.Label();
    3031      this.btnFindAll = new System.Windows.Forms.Button();
    3132      this.btnFindNext = new System.Windows.Forms.Button();
    32       this.tabReplace = new System.Windows.Forms.TabPage();
    3333      this.lblValue = new System.Windows.Forms.Label();
    3434      this.btnReplaceAll = new System.Windows.Forms.Button();
    35       this.btnReplaceNext = new System.Windows.Forms.Button();
     35      this.btnReplace = new System.Windows.Forms.Button();
    3636      this.cmbReplaceWith = new System.Windows.Forms.ComboBox();
    3737      this.txtValue = new System.Windows.Forms.TextBox();
     
    5353      this.tabSearchReplace.Size = new System.Drawing.Size(564, 135);
    5454      this.tabSearchReplace.TabIndex = 0;
     55      this.tabSearchReplace.SelectedIndexChanged += new System.EventHandler(this.tabSearchReplace_SelectedIndexChanged);
    5556      //
    5657      // tabSearch
     
    5960      this.tabSearch.Name = "tabSearch";
    6061      this.tabSearch.Padding = new System.Windows.Forms.Padding(3);
    61       this.tabSearch.Size = new System.Drawing.Size(556, 148);
     62      this.tabSearch.Size = new System.Drawing.Size(556, 109);
    6263      this.tabSearch.TabIndex = 0;
    6364      this.tabSearch.Text = "Search";
    6465      this.tabSearch.UseVisualStyleBackColor = true;
    65       //
    66       // txtSearchString
    67       //
    68       this.txtSearchString.Location = new System.Drawing.Point(103, 20);
    69       this.txtSearchString.Name = "txtSearchString";
    70       this.txtSearchString.Size = new System.Drawing.Size(254, 20);
    71       this.txtSearchString.TabIndex = 23;
    72       //
    73       // lblSearch
    74       //
    75       this.lblSearch.AutoSize = true;
    76       this.lblSearch.Location = new System.Drawing.Point(41, 26);
    77       this.lblSearch.Name = "lblSearch";
    78       this.lblSearch.Size = new System.Drawing.Size(56, 13);
    79       this.lblSearch.TabIndex = 22;
    80       this.lblSearch.Text = "Search for";
    81       //
    82       // btnFindAll
    83       //
    84       this.btnFindAll.Location = new System.Drawing.Point(458, 20);
    85       this.btnFindAll.Name = "btnFindAll";
    86       this.btnFindAll.Size = new System.Drawing.Size(80, 23);
    87       this.btnFindAll.TabIndex = 21;
    88       this.btnFindAll.Text = "Find All";
    89       this.btnFindAll.UseVisualStyleBackColor = true;
    90       //
    91       // btnFindNext
    92       //
    93       this.btnFindNext.Location = new System.Drawing.Point(372, 20);
    94       this.btnFindNext.Name = "btnFindNext";
    95       this.btnFindNext.Size = new System.Drawing.Size(80, 23);
    96       this.btnFindNext.TabIndex = 20;
    97       this.btnFindNext.Text = "Find Next";
    98       this.btnFindNext.UseVisualStyleBackColor = true;
    9966      //
    10067      // tabReplace
     
    10673      this.tabReplace.Controls.Add(this.lblValue);
    10774      this.tabReplace.Controls.Add(this.btnReplaceAll);
    108       this.tabReplace.Controls.Add(this.btnReplaceNext);
     75      this.tabReplace.Controls.Add(this.btnReplace);
    10976      this.tabReplace.Controls.Add(this.cmbReplaceWith);
    11077      this.tabReplace.Controls.Add(this.txtValue);
     
    11885      this.tabReplace.UseVisualStyleBackColor = true;
    11986      //
     87      // txtSearchString
     88      //
     89      this.txtSearchString.Location = new System.Drawing.Point(103, 20);
     90      this.txtSearchString.Name = "txtSearchString";
     91      this.txtSearchString.Size = new System.Drawing.Size(254, 20);
     92      this.txtSearchString.TabIndex = 23;
     93      //
     94      // lblSearch
     95      //
     96      this.lblSearch.AutoSize = true;
     97      this.lblSearch.Location = new System.Drawing.Point(41, 26);
     98      this.lblSearch.Name = "lblSearch";
     99      this.lblSearch.Size = new System.Drawing.Size(56, 13);
     100      this.lblSearch.TabIndex = 22;
     101      this.lblSearch.Text = "Search for";
     102      //
     103      // btnFindAll
     104      //
     105      this.btnFindAll.Location = new System.Drawing.Point(458, 20);
     106      this.btnFindAll.Name = "btnFindAll";
     107      this.btnFindAll.Size = new System.Drawing.Size(80, 23);
     108      this.btnFindAll.TabIndex = 21;
     109      this.btnFindAll.Text = "Find All";
     110      this.btnFindAll.UseVisualStyleBackColor = true;
     111      //
     112      // btnFindNext
     113      //
     114      this.btnFindNext.Location = new System.Drawing.Point(372, 20);
     115      this.btnFindNext.Name = "btnFindNext";
     116      this.btnFindNext.Size = new System.Drawing.Size(80, 23);
     117      this.btnFindNext.TabIndex = 20;
     118      this.btnFindNext.Text = "Find Next";
     119      this.btnFindNext.UseVisualStyleBackColor = true;
     120      //
    120121      // lblValue
    121122      //
     
    136137      this.btnReplaceAll.UseVisualStyleBackColor = true;
    137138      //
    138       // btnReplaceNext
    139       //
    140       this.btnReplaceNext.Location = new System.Drawing.Point(372, 47);
    141       this.btnReplaceNext.Name = "btnReplaceNext";
    142       this.btnReplaceNext.Size = new System.Drawing.Size(80, 23);
    143       this.btnReplaceNext.TabIndex = 17;
    144       this.btnReplaceNext.Text = "Replace Next";
    145       this.btnReplaceNext.UseVisualStyleBackColor = true;
     139      // btnReplace
     140      //
     141      this.btnReplace.Location = new System.Drawing.Point(372, 47);
     142      this.btnReplace.Name = "btnReplace";
     143      this.btnReplace.Size = new System.Drawing.Size(80, 23);
     144      this.btnReplace.TabIndex = 17;
     145      this.btnReplace.Text = "Replace";
     146      this.btnReplace.UseVisualStyleBackColor = true;
    146147      //
    147148      // cmbReplaceWith
    148149      //
     150      this.cmbReplaceWith.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    149151      this.cmbReplaceWith.FormattingEnabled = true;
    150152      this.cmbReplaceWith.Location = new System.Drawing.Point(103, 46);
     
    152154      this.cmbReplaceWith.Size = new System.Drawing.Size(254, 21);
    153155      this.cmbReplaceWith.TabIndex = 16;
     156      this.cmbReplaceWith.SelectedIndexChanged += new System.EventHandler(this.cmbReplaceWith_SelectedIndexChanged);
    154157      //
    155158      // txtValue
     
    195198    private System.Windows.Forms.Label lblValue;
    196199    private System.Windows.Forms.Button btnReplaceAll;
    197     private System.Windows.Forms.Button btnReplaceNext;
     200    private System.Windows.Forms.Button btnReplace;
    198201    private System.Windows.Forms.ComboBox cmbReplaceWith;
    199202    private System.Windows.Forms.TextBox txtValue;
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/FindAndReplaceDialog.cs

    r10636 r10672  
    11using System;
     2using System.Collections.Generic;
    23using System.Windows.Forms;
    34
    45namespace HeuristicLab.DataPreprocessing.Views {
     6  public enum ReplaceAction {
     7    Value,
     8    Average,
     9    Median,
     10    Random,
     11    MostCommon,
     12    Interpolation
     13  }
     14
    515  public partial class FindAndReplaceDialog : Form {
     16    private string[] cmbItemsText = { "Value", "Average", "Median", "Random", "Most Common", "Interpolation" };
     17
    618    public FindAndReplaceDialog() {
    719      InitializeComponent();
    8       string[] cmbItems = { "Value", "Average", "Median", "Random", "Most Common", "Interpolation" };
    9       cmbReplaceWith.Items.AddRange(cmbItems);
     20      cmbReplaceWith.Items.AddRange(cmbItemsText);
     21      cmbReplaceWith.SelectedIndex = (int)ReplaceAction.Value;
    1022    }
    1123
     
    2436    }
    2537
     38    private void cmbReplaceWith_SelectedIndexChanged(object sender, System.EventArgs e) {
     39      lblValue.Visible = txtValue.Visible = cmbReplaceWith.SelectedIndex == (int)ReplaceAction.Value;
     40    }
     41
    2642    private void AddControlsToCurrentTab() {
    2743      tabSearchReplace.SelectedTab.Controls.Add(btnFindAll);
     
    3147    }
    3248
    33     public string GetSearchText() {
     49    public String GetSearchText() {
    3450      return txtSearchString.Text;
    3551    }
     
    3955    }
    4056
    41     public string GetReplaceAction() {
    42       return cmbReplaceWith.SelectedText;
     57    public ReplaceAction GetReplaceAction() {
     58      return (ReplaceAction)cmbReplaceWith.SelectedIndex;
    4359    }
    4460
     
    5975
    6076    public event EventHandler ReplaceNextEvent {
    61       add { btnReplaceNext.Click += value; }
    62       remove { btnReplaceNext.Click -= value; }
     77      add { btnReplace.Click += value; }
     78      remove { btnReplace.Click -= value; }
    6379    }
    6480     
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/ManipulationLogic.cs

    r10621 r10672  
    3030    private IStatisticsLogic statisticsLogic;
    3131    private ISearchLogic searchLogic;
    32 
    33     public ManipulationLogic(ITransactionalPreprocessingData _prepocessingData, ISearchLogic theSearchLogic, IStatisticsLogic theStatisticsLogic) {
     32    private IDataGridLogic dataGridLogic;
     33
     34    public ManipulationLogic(ITransactionalPreprocessingData _prepocessingData, ISearchLogic theSearchLogic, IStatisticsLogic theStatisticsLogic, IDataGridLogic theDataGridLogic) {
    3435      preprocessingData = _prepocessingData;
    3536      searchLogic = theSearchLogic;
    3637      statisticsLogic = theStatisticsLogic;
     38      dataGridLogic = theDataGridLogic;
    3739    }
    3840
     
    4345    }
    4446
    45     public void ReplaceIndicesByAverageValue(Dictionary<int, List<int>> cells) {
     47    public void ReplaceIndicesByAverageValue(IDictionary<int, IList<int>> cells) {
    4648      preprocessingData.InTransaction(() => {
    4749        foreach (var column in cells) {
     
    5759    }
    5860
    59     public void ReplaceIndicesByMedianValue(Dictionary<int, List<int>> cells) {
     61    public void ReplaceIndicesByMedianValue(IDictionary<int, IList<int>> cells) {
    6062      preprocessingData.InTransaction(() => {
    6163        foreach (var column in cells) {
     
    7173    }
    7274
    73     public void ReplaceIndicesByRandomValue(Dictionary<int, List<int>> cells) {
     75    public void ReplaceIndicesByRandomValue(IDictionary<int, IList<int>> cells) {
    7476      preprocessingData.InTransaction(() => {
    7577        Random r = new Random();
     
    9799    }
    98100
    99     public void ReplaceIndicesByLinearInterpolationOfNeighbours(Dictionary<int, List<int>> cells) {
     101    public void ReplaceIndicesByLinearInterpolationOfNeighbours(IDictionary<int, IList<int>> cells) {
    100102      preprocessingData.InTransaction(() => {
    101103        foreach (var column in cells) {
     
    163165    }
    164166
    165     public void ReplaceIndicesByMostCommonValue(Dictionary<int, List<int>> cells) {
     167    public void ReplaceIndicesByMostCommonValue(IDictionary<int, IList<int>> cells) {
    166168      preprocessingData.InTransaction(() => {
    167169        foreach (var column in cells) {
     
    236238      }
    237239    }
     240
     241    public void ReplaceIndicesByValue(IDictionary<int, IList<int>> cells, string value) {
     242      preprocessingData.InTransaction(() => {
     243        foreach (var column in cells) {
     244          foreach (var rowIdx in column.Value) {
     245            dataGridLogic.SetValue(value, column.Key, rowIdx);
     246          }
     247        }
     248      });
     249    }
    238250  }
    239251}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Interfaces/IManipulationLogic.cs

    r10590 r10672  
    2727    void ReOrderToIndices(IEnumerable<int> indices);
    2828    void ReOrderToIndices(IList<Tuple<int, int>> indices);
    29     void ReplaceIndicesByAverageValue(Dictionary<int, List<int>> cells);
    30     void ReplaceIndicesByLinearInterpolationOfNeighbours(Dictionary<int, List<int>> cells);
    31     void ReplaceIndicesByMedianValue(Dictionary<int, List<int>> cells);
    32     void ReplaceIndicesByMostCommonValue(Dictionary<int, List<int>> cells);
    33     void ReplaceIndicesByRandomValue(Dictionary<int, List<int>> cells);
     29    void ReplaceIndicesByAverageValue(IDictionary<int, IList<int>> cells);
     30    void ReplaceIndicesByLinearInterpolationOfNeighbours(IDictionary<int, IList<int>> cells);
     31    void ReplaceIndicesByMedianValue(IDictionary<int, IList<int>> cells);
     32    void ReplaceIndicesByMostCommonValue(IDictionary<int, IList<int>> cells);
     33    void ReplaceIndicesByRandomValue(IDictionary<int, IList<int>> cells);
     34    void ReplaceIndicesByValue(IDictionary<int, IList<int>> cells, string value);
    3435    void ReplaceIndicesByValue<T>(int columnIndex, IEnumerable<int> rowIndices, T value);
    3536    void ShuffleWithRanges(IEnumerable<HeuristicLab.Data.IntRange> ranges);
Note: See TracChangeset for help on using the changeset viewer.