Changeset 15466
- Timestamp:
- 11/09/17 11:51:37 (7 years ago)
- Location:
- branches/DataPreprocessing Cleanup
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing Cleanup/HeuristicLab.DataPreprocessing.Views/3.4/FilterView.Designer.cs
r15210 r15466 46 46 private void InitializeComponent() { 47 47 this.groupBoxFilter = new System.Windows.Forms.GroupBox(); 48 this.checkedFilterView = new HeuristicLab.DataPreprocessing.Views.CheckedFilterCollectionView();49 48 this.groupBoxFilterInfo = new System.Windows.Forms.GroupBox(); 50 49 this.lblPercentage = new System.Windows.Forms.Label(); … … 63 62 this.label3 = new System.Windows.Forms.Label(); 64 63 this.bottomPanel = new System.Windows.Forms.Panel(); 64 this.checkedFilterView = new HeuristicLab.DataPreprocessing.Views.CheckedFilterCollectionView(); 65 65 this.groupBoxFilter.SuspendLayout(); 66 66 this.groupBoxFilterInfo.SuspendLayout(); … … 80 80 this.groupBoxFilter.TabStop = false; 81 81 this.groupBoxFilter.Text = "Filter"; 82 //83 // checkedFilterView84 //85 this.checkedFilterView.Caption = "filterView";86 this.checkedFilterView.Content = null;87 this.checkedFilterView.Dock = System.Windows.Forms.DockStyle.Fill;88 this.checkedFilterView.Location = new System.Drawing.Point(3, 16);89 this.checkedFilterView.Name = "checkedFilterView";90 this.checkedFilterView.ReadOnly = false;91 this.checkedFilterView.ShowDetails = true;92 this.checkedFilterView.Size = new System.Drawing.Size(652, 308);93 this.checkedFilterView.TabIndex = 0;94 82 // 95 83 // groupBoxFilterInfo … … 185 173 this.rBtnOr.AutoSize = true; 186 174 this.rBtnOr.Cursor = System.Windows.Forms.Cursors.Default; 187 this.rBtnOr.Enabled = false;188 175 this.rBtnOr.Location = new System.Drawing.Point(53, 6); 189 176 this.rBtnOr.Name = "rBtnOr"; … … 199 186 this.rBtnAnd.Checked = true; 200 187 this.rBtnAnd.Cursor = System.Windows.Forms.Cursors.Default; 201 this.rBtnAnd.Enabled = false;202 188 this.rBtnAnd.Location = new System.Drawing.Point(3, 6); 203 189 this.rBtnAnd.Name = "rBtnAnd"; … … 273 259 this.bottomPanel.Size = new System.Drawing.Size(670, 30); 274 260 this.bottomPanel.TabIndex = 13; 261 // 262 // checkedFilterView 263 // 264 this.checkedFilterView.Caption = "filterView"; 265 this.checkedFilterView.Content = null; 266 this.checkedFilterView.Dock = System.Windows.Forms.DockStyle.Fill; 267 this.checkedFilterView.Location = new System.Drawing.Point(3, 16); 268 this.checkedFilterView.Name = "checkedFilterView"; 269 this.checkedFilterView.ReadOnly = false; 270 this.checkedFilterView.ShowDetails = true; 271 this.checkedFilterView.Size = new System.Drawing.Size(652, 308); 272 this.checkedFilterView.TabIndex = 0; 275 273 // 276 274 // FilterView -
branches/DataPreprocessing Cleanup/HeuristicLab.DataPreprocessing.Views/3.4/FilterView.cs
r15274 r15466 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using System.Linq; 25 24 using HeuristicLab.Collections; … … 44 43 } 45 44 46 private void InitData() {47 checkedFilterView.Content = Content.Filters;48 checkedFilterView.Content.ItemsAdded += Content_ItemsAdded;49 checkedFilterView.Content.ItemsRemoved += Content_ItemsRemoved;50 checkedFilterView.Content.CheckedItemsChanged += Content_CheckedItemsChanged;51 }52 53 45 protected override void OnContentChanged() { 54 46 base.OnContentChanged(); 55 47 if (Content != null) { 56 InitData(); 57 UpdateFilterInfo(); 48 checkedFilterView.Content = Content.Filters; 49 rBtnAnd.Checked = Content.IsAndCombination; 50 rBtnOr.Checked = !Content.IsAndCombination; 51 UpdateFilter(); 52 } else { 53 checkedFilterView.Content = null; 58 54 } 59 55 } 60 61 private void Content_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) { 62 if (Content != null) { 63 foreach (IFilter filter in e.Items) { 64 filter.Active = checkedFilterView.Content.ItemChecked(filter); 65 } 66 UpdateFilterInfo(); 67 } 56 protected override void RegisterContentEvents() { 57 base.RegisterContentEvents(); 58 Content.Filters.ItemsAdded += Content_ItemsAdded; 59 Content.Filters.ItemsRemoved += Content_ItemsRemoved; 60 Content.Filters.CheckedItemsChanged += Content_CheckedItemsChanged; 61 } 62 protected override void DeregisterContentEvents() { 63 Content.Filters.ItemsAdded -= Content_ItemsAdded; 64 Content.Filters.ItemsRemoved -= Content_ItemsRemoved; 65 Content.Filters.CheckedItemsChanged -= Content_CheckedItemsChanged; 66 base.DeregisterContentEvents(); 68 67 } 69 68 70 private void UpdateFilterInfo() { 71 List<IFilter> filters = Content.Filters.ToList(); 72 int activeFilters = filters.Count(c => c.Active); 73 applyFilterButton.Enabled = (activeFilters > 0); 74 rBtnAnd.Enabled = (activeFilters > 0); 75 rBtnOr.Enabled = (activeFilters > 0); 69 private void UpdateFilter() { 70 bool activeFilters = Content.ActiveFilters.Any(); 71 applyFilterButton.Enabled = activeFilters; 72 73 int numTotal = Content.PreprocessingData.Rows; 74 int numRemaining = numTotal; 75 76 76 Content.PreprocessingData.ResetFilter(); 77 bool isAndCombination = rBtnAnd.Checked;78 bool[] ret;79 IList<IFilter> activeFilters1 = filters.Where(f => f.Active && f.ConstraintData != null).ToList();80 if (activeFilters1.Count > 0) {81 var result1 = Enumerable.Repeat(!isAndCombination, Content.PreprocessingData.Rows).ToArray();77 if (activeFilters) { 78 var remainingRows = Content.GetRemainingRows(); 79 Content.PreprocessingData.SetFilter(remainingRows); 80 numRemaining = remainingRows.Count(x => x); 81 } 82 82 83 foreach (IFilter filter in activeFilters1) { 84 bool[] filterResult = filter.Check(); 85 for (int row = 0; row < result1.Length; ++row) { 86 result1[row] = isAndCombination ? result1[row] || filterResult[row] : result1[row] && filterResult[row]; 87 } 88 } 89 Content.PreprocessingData.SetFilter(result1); 90 ret = result1; 91 } else { 92 ret = Enumerable.Repeat(false, Content.PreprocessingData.Rows).ToArray(); 93 } 94 bool[] result = ret; 95 96 int filteredCnt = result.Count(c => !c); 97 98 tbRemaining.Text = filteredCnt.ToString(); 99 double percentage = result.Length == 0 ? 0.0 : filteredCnt * 100 / (double)result.Length; 100 tbPercentage.Text = String.Format("{0:0.0000}%", percentage); 101 tbTotal.Text = result.Length.ToString(); 83 tbRemaining.Text = numRemaining.ToString(); 84 double ratio = numTotal > 0 ? numRemaining / (double)numTotal : 0.0; 85 tbPercentage.Text = ratio.ToString("P4"); 86 tbTotal.Text = numTotal.ToString(); 102 87 } 103 88 104 private void applyFilterButton_Click(object sender, EventArgs e) {105 if (Content != null) {106 List<IFilter> filters = Content.Filters.ToList();107 //apply filters108 bool isAndCombination = rBtnAnd.Checked;109 Content.PreprocessingData.PersistFilter();110 Content.PreprocessingData.ResetFilter();111 //deactivate checked filters112 filters = checkedFilterView.Content.CheckedItems.ToList();113 foreach (IFilter filter in filters) {114 checkedFilterView.Content.SetItemCheckedState(filter, false);115 filter.Active = false;116 }117 UpdateFilterInfo();118 }119 }120 89 90 #region Content Events 121 91 //whenever a new filter is added the preprocessing data is set to the filter 122 92 private void Content_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) { … … 127 97 } 128 98 } 129 130 99 private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IFilter> e) { 131 100 if (Content != null) { 132 UpdateFilter Info();101 UpdateFilter(); 133 102 } 134 103 } 104 private void Content_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) { 105 if (Content != null) { 106 foreach (IFilter filter in e.Items) { 107 filter.Active = checkedFilterView.Content.ItemChecked(filter); 108 } 109 UpdateFilter(); 110 } 111 } 112 #endregion 135 113 114 #region Controls Events 136 115 private void rBtnAnd_CheckedChanged(object sender, EventArgs e) { 137 116 if (Content != null) { 138 UpdateFilterInfo();139 117 Content.IsAndCombination = rBtnAnd.Checked; 118 UpdateFilter(); 140 119 } 141 120 } 121 private void applyFilterButton_Click(object sender, EventArgs e) { 122 if (Content != null) { 123 //apply filters 124 Content.PreprocessingData.PersistFilter(); 125 Content.PreprocessingData.ResetFilter(); 126 //deactivate checked filters 127 foreach (var filter in Content.Filters.CheckedItems) { 128 checkedFilterView.Content.SetItemCheckedState(filter, false); 129 filter.Active = false; 130 } 131 UpdateFilter(); 132 } 133 } 134 #endregion 142 135 } 143 136 } -
branches/DataPreprocessing Cleanup/HeuristicLab.DataPreprocessing/3.4/Content/FilterContent.cs
r15274 r15466 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using System.Drawing; 24 using System.Linq; 23 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Core; … … 38 40 [Storable] 39 41 public bool IsAndCombination { get; set; } 42 43 public IEnumerable<IFilter> ActiveFilters { 44 get { return Filters.Where(f => f.Active && f.ConstraintData != null); } 45 } 46 47 public bool[] GetRemainingRows() { 48 var remainingRows = new bool[PreprocessingData.Rows]; 49 if (ActiveFilters.Any()) { 50 var filterResults = ActiveFilters.Select(f => f.Check()).ToList(); 51 var rowFilterResults = new bool[filterResults.Count]; 52 for (int row = 0; row < remainingRows.Length; row++) { 53 for (int i = 0; i < filterResults.Count; i++) 54 rowFilterResults[i] = filterResults[i][row]; 55 56 remainingRows[row] = IsAndCombination 57 ? rowFilterResults.All(x => x) 58 : rowFilterResults.Any(x => x); 59 } 60 } else { 61 // if not filters active => all rows are remaining 62 for (int i = 0; i < remainingRows.Length; i++) 63 remainingRows[i] = true; 64 } 65 return remainingRows; 66 } 40 67 41 68 #region Constructor, Cloning & Persistence -
branches/DataPreprocessing Cleanup/HeuristicLab.DataPreprocessing/3.4/Data/FilteredPreprocessingData.cs
r15431 r15466 43 43 44 44 #region Constructor, Cloning & Persistence 45 public FilteredPreprocessingData(IPreprocessingData prep orcessingData)45 public FilteredPreprocessingData(IPreprocessingData preprocessingData) 46 46 : base() { 47 originalData = prep orcessingData;47 originalData = preprocessingData; 48 48 filteredData = null; 49 49 } … … 317 317 318 318 #region Filters 319 public void SetFilter(bool[] r owFilters) {319 public void SetFilter(bool[] remainingRows) { 320 320 filteredData = (IPreprocessingData)originalData.Clone(); 321 321 filteredData.InTransaction(() => { 322 for (int row = (r owFilters.Length - 1); row >= 0; --row) {323 if ( rowFilters[row]) {322 for (int row = (remainingRows.Length - 1); row >= 0; --row) { 323 if (!remainingRows[row]) { 324 324 filteredData.DeleteRow(row); 325 325 } -
branches/DataPreprocessing Cleanup/HeuristicLab.DataPreprocessing/3.4/Data/IFilteredPreprocessingData.cs
r15270 r15466 25 25 public interface IFilteredPreprocessingData : IPreprocessingData { 26 26 #region Filters 27 void SetFilter(bool[] r owFilters);27 void SetFilter(bool[] remainingRows); 28 28 void PersistFilter(); 29 29 void ResetFilter(); -
branches/DataPreprocessing Cleanup/HeuristicLab.DataPreprocessing/3.4/Filter/ComparisonFilter.cs
r15110 r15466 86 86 } 87 87 88 // return remaining rows 88 89 public new bool[] Check() { 89 90 bool[] result = new bool[ConstrainedValue.Rows]; … … 102 103 } 103 104 104 result[row] = !base.Check(item);105 result[row] = base.Check(item); 105 106 } 106 107
Note: See TracChangeset
for help on using the changeset viewer.