Changeset 10672 for branches/DataPreprocessing
- Timestamp:
- 03/26/14 16:11:08 (11 years ago)
- Location:
- branches/DataPreprocessing
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/DataGridContentView.cs
r10668 r10672 25 25 using System.Linq; 26 26 using System.Windows.Forms; 27 using HeuristicLab.Data; 27 28 using HeuristicLab.MainForm; 28 29 … … 34 35 private bool notOwnEvent = true; 35 36 private FindAndReplaceDialog findAndReplaceDialog; 37 private IDictionary<int, IList<int>> foundCells; 38 private Tuple<int, int> currentCell; 39 private string currentSearchText; 36 40 37 41 public new IDataGridContent Content { … … 146 150 findAndReplaceDialog.FindNextEvent += findAndReplaceDialog_FindNextEvent; 147 151 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 } 153 162 } 154 163 155 164 void findAndReplaceDialog_ReplaceAllEvent(object sender, EventArgs e) { 156 throw new NotImplementedException();165 Replace(FindAll(findAndReplaceDialog.GetSearchText())); 157 166 } 158 167 159 168 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; 161 189 } 162 190 163 191 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; 165 240 } 166 241 … … 254 329 } 255 330 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>>(); 258 333 for (int i = 0; i < dataGridView.SelectedCells.Count; i++) { 259 334 var columnIndex = dataGridView.SelectedCells[i].ColumnIndex; -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/DataPreprocessingView.cs
r10658 r10672 48 48 var dataGridLogic = new DataGridLogic(data); 49 49 var statisticsLogic = new StatisticsLogic(data, searchLogic); 50 var manipulationLogic = new ManipulationLogic(data, searchLogic, statisticsLogic );50 var manipulationLogic = new ManipulationLogic(data, searchLogic, statisticsLogic, dataGridLogic); 51 51 var transformationLogic = new TransformationLogic(data, searchLogic, statisticsLogic); 52 52 var lineChartLogic = new ChartLogic(data); -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/FindAndReplaceDialog.Designer.cs
r10636 r10672 26 26 this.tabSearchReplace = new System.Windows.Forms.TabControl(); 27 27 this.tabSearch = new System.Windows.Forms.TabPage(); 28 this.tabReplace = new System.Windows.Forms.TabPage(); 28 29 this.txtSearchString = new System.Windows.Forms.TextBox(); 29 30 this.lblSearch = new System.Windows.Forms.Label(); 30 31 this.btnFindAll = new System.Windows.Forms.Button(); 31 32 this.btnFindNext = new System.Windows.Forms.Button(); 32 this.tabReplace = new System.Windows.Forms.TabPage();33 33 this.lblValue = new System.Windows.Forms.Label(); 34 34 this.btnReplaceAll = new System.Windows.Forms.Button(); 35 this.btnReplace Next= new System.Windows.Forms.Button();35 this.btnReplace = new System.Windows.Forms.Button(); 36 36 this.cmbReplaceWith = new System.Windows.Forms.ComboBox(); 37 37 this.txtValue = new System.Windows.Forms.TextBox(); … … 53 53 this.tabSearchReplace.Size = new System.Drawing.Size(564, 135); 54 54 this.tabSearchReplace.TabIndex = 0; 55 this.tabSearchReplace.SelectedIndexChanged += new System.EventHandler(this.tabSearchReplace_SelectedIndexChanged); 55 56 // 56 57 // tabSearch … … 59 60 this.tabSearch.Name = "tabSearch"; 60 61 this.tabSearch.Padding = new System.Windows.Forms.Padding(3); 61 this.tabSearch.Size = new System.Drawing.Size(556, 1 48);62 this.tabSearch.Size = new System.Drawing.Size(556, 109); 62 63 this.tabSearch.TabIndex = 0; 63 64 this.tabSearch.Text = "Search"; 64 65 this.tabSearch.UseVisualStyleBackColor = true; 65 //66 // txtSearchString67 //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 // lblSearch74 //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 // btnFindAll83 //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 // btnFindNext92 //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;99 66 // 100 67 // tabReplace … … 106 73 this.tabReplace.Controls.Add(this.lblValue); 107 74 this.tabReplace.Controls.Add(this.btnReplaceAll); 108 this.tabReplace.Controls.Add(this.btnReplace Next);75 this.tabReplace.Controls.Add(this.btnReplace); 109 76 this.tabReplace.Controls.Add(this.cmbReplaceWith); 110 77 this.tabReplace.Controls.Add(this.txtValue); … … 118 85 this.tabReplace.UseVisualStyleBackColor = true; 119 86 // 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 // 120 121 // lblValue 121 122 // … … 136 137 this.btnReplaceAll.UseVisualStyleBackColor = true; 137 138 // 138 // btnReplace Next139 // 140 this.btnReplace Next.Location = new System.Drawing.Point(372, 47);141 this.btnReplace Next.Name = "btnReplaceNext";142 this.btnReplace Next.Size = new System.Drawing.Size(80, 23);143 this.btnReplace Next.TabIndex = 17;144 this.btnReplace Next.Text = "Replace Next";145 this.btnReplace Next.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; 146 147 // 147 148 // cmbReplaceWith 148 149 // 150 this.cmbReplaceWith.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 149 151 this.cmbReplaceWith.FormattingEnabled = true; 150 152 this.cmbReplaceWith.Location = new System.Drawing.Point(103, 46); … … 152 154 this.cmbReplaceWith.Size = new System.Drawing.Size(254, 21); 153 155 this.cmbReplaceWith.TabIndex = 16; 156 this.cmbReplaceWith.SelectedIndexChanged += new System.EventHandler(this.cmbReplaceWith_SelectedIndexChanged); 154 157 // 155 158 // txtValue … … 195 198 private System.Windows.Forms.Label lblValue; 196 199 private System.Windows.Forms.Button btnReplaceAll; 197 private System.Windows.Forms.Button btnReplace Next;200 private System.Windows.Forms.Button btnReplace; 198 201 private System.Windows.Forms.ComboBox cmbReplaceWith; 199 202 private System.Windows.Forms.TextBox txtValue; -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/FindAndReplaceDialog.cs
r10636 r10672 1 1 using System; 2 using System.Collections.Generic; 2 3 using System.Windows.Forms; 3 4 4 5 namespace HeuristicLab.DataPreprocessing.Views { 6 public enum ReplaceAction { 7 Value, 8 Average, 9 Median, 10 Random, 11 MostCommon, 12 Interpolation 13 } 14 5 15 public partial class FindAndReplaceDialog : Form { 16 private string[] cmbItemsText = { "Value", "Average", "Median", "Random", "Most Common", "Interpolation" }; 17 6 18 public FindAndReplaceDialog() { 7 19 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; 10 22 } 11 23 … … 24 36 } 25 37 38 private void cmbReplaceWith_SelectedIndexChanged(object sender, System.EventArgs e) { 39 lblValue.Visible = txtValue.Visible = cmbReplaceWith.SelectedIndex == (int)ReplaceAction.Value; 40 } 41 26 42 private void AddControlsToCurrentTab() { 27 43 tabSearchReplace.SelectedTab.Controls.Add(btnFindAll); … … 31 47 } 32 48 33 public string GetSearchText() {49 public String GetSearchText() { 34 50 return txtSearchString.Text; 35 51 } … … 39 55 } 40 56 41 public stringGetReplaceAction() {42 return cmbReplaceWith.SelectedText;57 public ReplaceAction GetReplaceAction() { 58 return (ReplaceAction)cmbReplaceWith.SelectedIndex; 43 59 } 44 60 … … 59 75 60 76 public event EventHandler ReplaceNextEvent { 61 add { btnReplace Next.Click += value; }62 remove { btnReplace Next.Click -= value; }77 add { btnReplace.Click += value; } 78 remove { btnReplace.Click -= value; } 63 79 } 64 80 -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/ManipulationLogic.cs
r10621 r10672 30 30 private IStatisticsLogic statisticsLogic; 31 31 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) { 34 35 preprocessingData = _prepocessingData; 35 36 searchLogic = theSearchLogic; 36 37 statisticsLogic = theStatisticsLogic; 38 dataGridLogic = theDataGridLogic; 37 39 } 38 40 … … 43 45 } 44 46 45 public void ReplaceIndicesByAverageValue( Dictionary<int,List<int>> cells) {47 public void ReplaceIndicesByAverageValue(IDictionary<int, IList<int>> cells) { 46 48 preprocessingData.InTransaction(() => { 47 49 foreach (var column in cells) { … … 57 59 } 58 60 59 public void ReplaceIndicesByMedianValue( Dictionary<int,List<int>> cells) {61 public void ReplaceIndicesByMedianValue(IDictionary<int, IList<int>> cells) { 60 62 preprocessingData.InTransaction(() => { 61 63 foreach (var column in cells) { … … 71 73 } 72 74 73 public void ReplaceIndicesByRandomValue( Dictionary<int,List<int>> cells) {75 public void ReplaceIndicesByRandomValue(IDictionary<int, IList<int>> cells) { 74 76 preprocessingData.InTransaction(() => { 75 77 Random r = new Random(); … … 97 99 } 98 100 99 public void ReplaceIndicesByLinearInterpolationOfNeighbours( Dictionary<int,List<int>> cells) {101 public void ReplaceIndicesByLinearInterpolationOfNeighbours(IDictionary<int, IList<int>> cells) { 100 102 preprocessingData.InTransaction(() => { 101 103 foreach (var column in cells) { … … 163 165 } 164 166 165 public void ReplaceIndicesByMostCommonValue( Dictionary<int,List<int>> cells) {167 public void ReplaceIndicesByMostCommonValue(IDictionary<int, IList<int>> cells) { 166 168 preprocessingData.InTransaction(() => { 167 169 foreach (var column in cells) { … … 236 238 } 237 239 } 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 } 238 250 } 239 251 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Interfaces/IManipulationLogic.cs
r10590 r10672 27 27 void ReOrderToIndices(IEnumerable<int> indices); 28 28 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); 34 35 void ReplaceIndicesByValue<T>(int columnIndex, IEnumerable<int> rowIndices, T value); 35 36 void ShuffleWithRanges(IEnumerable<HeuristicLab.Data.IntRange> ranges);
Note: See TracChangeset
for help on using the changeset viewer.