source: branches/2839_HiveProjectManagement/HeuristicLab.DataPreprocessing/3.4/Content/FilterContent.cs @ 16057

Last change on this file since 16057 was 16057, checked in by jkarder, 16 months ago

#2839:

File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Collections.Generic;
23using System.Drawing;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.DataPreprocessing.Filter;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.DataPreprocessing {
31  [Item("Filter", "Represents the filter grid.")]
32  [StorableClass]
33  public class FilterContent : PreprocessingContent, IViewShortcut {
34    public static new Image StaticItemImage {
35      get { return HeuristicLab.Common.Resources.VSImageLibrary.Filter; }
36    }
37    [Storable]
38    public ICheckedItemCollection<IFilter> Filters { get; private set; }
39
40    [Storable]
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    }
67
68    #region Constructor, Cloning & Persistence
69    public FilterContent(IFilteredPreprocessingData preprocessingData)
70      : base(preprocessingData) {
71      Filters = new CheckedItemCollection<IFilter>();
72      IsAndCombination = true;
73    }
74
75    protected FilterContent(FilterContent original, Cloner cloner)
76      : base(original, cloner) {
77      Filters = cloner.Clone(original.Filters);
78      IsAndCombination = original.IsAndCombination;
79    }
80    public override IDeepCloneable Clone(Cloner cloner) {
81      return new FilterContent(this, cloner);
82    }
83
84    [StorableConstructor]
85    protected FilterContent(bool deserializing)
86      : base(deserializing) { }
87    #endregion
88  }
89}
Note: See TracBrowser for help on using the repository browser.