[10783] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using HeuristicLab.Common;
|
---|
| 4 | using HeuristicLab.Core;
|
---|
| 5 | using HeuristicLab.Data;
|
---|
[10804] | 6 | using HeuristicLab.DataPreprocessing.Interfaces;
|
---|
[10783] | 7 | using HeuristicLab.Problems.DataAnalysis;
|
---|
| 8 | using HeuristicLab.Problems.DataAnalysis.Transformations;
|
---|
| 9 |
|
---|
[10804] | 10 | namespace HeuristicLab.DataPreprocessing.Implementations {
|
---|
| 11 | public class FilteredPreprocessingData : NamedItem, IFilteredPreprocessingData {
|
---|
[10783] | 12 | protected ITransactionalPreprocessingData originalData;
|
---|
| 13 | protected ITransactionalPreprocessingData filteredData;
|
---|
| 14 |
|
---|
| 15 | protected FilteredPreprocessingData(FilteredPreprocessingData original, Cloner cloner)
|
---|
| 16 | : base(original, cloner) {
|
---|
[10804] | 17 | originalData = (ITransactionalPreprocessingData)original.originalData;
|
---|
| 18 | filteredData = (ITransactionalPreprocessingData)original.filteredData;
|
---|
[10783] | 19 | }
|
---|
| 20 |
|
---|
| 21 | public FilteredPreprocessingData(ITransactionalPreprocessingData preporcessingData)
|
---|
| 22 | : base() {
|
---|
[10804] | 23 | originalData = preporcessingData;
|
---|
| 24 | filteredData = null;
|
---|
[10783] | 25 | }
|
---|
| 26 |
|
---|
[10804] | 27 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 28 | return new FilteredPreprocessingData(this, cloner);
|
---|
| 29 | }
|
---|
[10783] | 30 |
|
---|
[10804] | 31 | public T GetCell<T>(int columnIndex, int rowIndex) {
|
---|
| 32 | return ActiveData.GetCell<T>(columnIndex, rowIndex);
|
---|
| 33 | }
|
---|
[10783] | 34 |
|
---|
[10804] | 35 | public void SetCell<T>(int columnIndex, int rowIndex, T value) {
|
---|
| 36 | ReadOnlyOnFilterData.SetCell<T>(columnIndex, rowIndex, value);
|
---|
| 37 | }
|
---|
[10783] | 38 |
|
---|
[10804] | 39 | public string GetCellAsString(int columnIndex, int rowIndex) {
|
---|
| 40 | return ActiveData.GetCellAsString(columnIndex, rowIndex);
|
---|
| 41 | }
|
---|
[10783] | 42 |
|
---|
[10809] | 43 | public IList<T> GetValues<T>(string variableName, bool considerSelection) {
|
---|
| 44 | return ActiveData.GetValues<T>(variableName, considerSelection);
|
---|
[10804] | 45 | }
|
---|
[10783] | 46 |
|
---|
[10809] | 47 | public IList<T> GetValues<T>(int columnIndex, bool considerSelection) {
|
---|
| 48 | return ActiveData.GetValues<T>(columnIndex, considerSelection);
|
---|
[10804] | 49 | }
|
---|
[10783] | 50 |
|
---|
[10804] | 51 | public void SetValues<T>(int columnIndex, IList<T> values) {
|
---|
| 52 | ReadOnlyOnFilterData.SetValues<T>(columnIndex, values);
|
---|
| 53 | }
|
---|
[10783] | 54 |
|
---|
[10804] | 55 | public void InsertRow(int rowIndex) {
|
---|
| 56 | ReadOnlyOnFilterData.InsertRow(rowIndex);
|
---|
| 57 | }
|
---|
[10783] | 58 |
|
---|
[10804] | 59 | public void DeleteRow(int rowIndex) {
|
---|
| 60 | ReadOnlyOnFilterData.DeleteRow(rowIndex);
|
---|
| 61 | }
|
---|
[10783] | 62 |
|
---|
[10804] | 63 | public void InsertColumn<T>(string variableName, int columnIndex) {
|
---|
| 64 | ReadOnlyOnFilterData.InsertColumn<T>(variableName, columnIndex);
|
---|
| 65 | }
|
---|
[10783] | 66 |
|
---|
[10804] | 67 | public void DeleteColumn(int columnIndex) {
|
---|
| 68 | ReadOnlyOnFilterData.DeleteColumn(columnIndex);
|
---|
| 69 | }
|
---|
[10783] | 70 |
|
---|
[10804] | 71 | public IntRange TrainingPartition {
|
---|
| 72 | get { return originalData.TrainingPartition; }
|
---|
| 73 | }
|
---|
[10783] | 74 |
|
---|
[10804] | 75 | public IntRange TestPartition {
|
---|
| 76 | get { return originalData.TestPartition; }
|
---|
| 77 | }
|
---|
[10783] | 78 |
|
---|
[10804] | 79 | public IList<ITransformation> Transformations {
|
---|
| 80 | get { return originalData.Transformations; }
|
---|
| 81 | }
|
---|
[10783] | 82 |
|
---|
[10804] | 83 | public IEnumerable<string> VariableNames {
|
---|
| 84 | get { return ActiveData.VariableNames; }
|
---|
| 85 | }
|
---|
[10783] | 86 |
|
---|
[10804] | 87 | public string GetVariableName(int columnIndex) {
|
---|
| 88 | return ActiveData.GetVariableName(columnIndex);
|
---|
| 89 | }
|
---|
[10783] | 90 |
|
---|
[10804] | 91 | public int GetColumnIndex(string variableName) {
|
---|
| 92 | return ActiveData.GetColumnIndex(variableName);
|
---|
| 93 | }
|
---|
[10783] | 94 |
|
---|
[10804] | 95 | public bool IsType<T>(int columnIndex) {
|
---|
| 96 | return originalData.IsType<T>(columnIndex);
|
---|
| 97 | }
|
---|
[10783] | 98 |
|
---|
[10804] | 99 | public int Columns {
|
---|
| 100 | get { return ActiveData.Columns; }
|
---|
| 101 | }
|
---|
[10783] | 102 |
|
---|
[10804] | 103 | public int Rows {
|
---|
| 104 | get { return ActiveData.Rows; }
|
---|
| 105 | }
|
---|
[10783] | 106 |
|
---|
[10804] | 107 | public Dataset ExportToDataset() {
|
---|
| 108 | return originalData.ExportToDataset();
|
---|
| 109 | }
|
---|
[10783] | 110 |
|
---|
[10804] | 111 | public void SetFilter(bool[] rowFilters) {
|
---|
[10783] | 112 |
|
---|
[10804] | 113 | filteredData = (ITransactionalPreprocessingData)originalData.Clone();
|
---|
[10783] | 114 |
|
---|
[10804] | 115 | for (int row = (rowFilters.Length - 1); row >= 0; --row) {
|
---|
| 116 | if (rowFilters[row]) {
|
---|
| 117 | filteredData.DeleteRow(row);
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
[10783] | 121 |
|
---|
[10804] | 122 | public void PersistFilter() {
|
---|
| 123 | originalData = (ITransactionalPreprocessingData)filteredData.Clone();
|
---|
| 124 | ResetFilter();
|
---|
| 125 | }
|
---|
[10783] | 126 |
|
---|
[10804] | 127 | public void ResetFilter() {
|
---|
| 128 | filteredData = null;
|
---|
| 129 | }
|
---|
[10783] | 130 |
|
---|
[10804] | 131 | public ITransactionalPreprocessingData ActiveData {
|
---|
| 132 | get { return IsFiltered ? filteredData : originalData; }
|
---|
| 133 | }
|
---|
[10783] | 134 |
|
---|
[10804] | 135 | public ITransactionalPreprocessingData ReadOnlyOnFilterData {
|
---|
| 136 | get {
|
---|
| 137 | if (IsFiltered)
|
---|
| 138 | throw new InvalidOperationException();
|
---|
[10783] | 139 |
|
---|
[10804] | 140 | return originalData;
|
---|
| 141 | }
|
---|
| 142 | }
|
---|
[10783] | 143 |
|
---|
[10804] | 144 | public bool IsFiltered {
|
---|
| 145 | get { return filteredData != null; }
|
---|
| 146 | }
|
---|
[10783] | 147 |
|
---|
[10810] | 148 | public event DataPreprocessingChangedEventHandler Changed {
|
---|
| 149 | add { originalData.Changed += value; }
|
---|
| 150 | remove { originalData.Changed -= value; }
|
---|
| 151 | }
|
---|
[10783] | 152 |
|
---|
[10804] | 153 | public bool IsUndoAvailable {
|
---|
| 154 | get { return IsFiltered ? false : originalData.IsUndoAvailable; }
|
---|
| 155 | }
|
---|
[10783] | 156 |
|
---|
[10804] | 157 | public void Undo() {
|
---|
| 158 | ReadOnlyOnFilterData.Undo();
|
---|
| 159 | }
|
---|
[10783] | 160 |
|
---|
[10804] | 161 | public void InTransaction(Action action, DataPreprocessingChangedEventType type = DataPreprocessingChangedEventType.Any) {
|
---|
| 162 | ReadOnlyOnFilterData.InTransaction(action, type);
|
---|
| 163 | }
|
---|
[10783] | 164 |
|
---|
[10804] | 165 | public void BeginTransaction(DataPreprocessingChangedEventType type) {
|
---|
| 166 | ReadOnlyOnFilterData.BeginTransaction(type);
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | public void EndTransaction() {
|
---|
| 170 | originalData.EndTransaction();
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | #region IPreprocessingData Members
|
---|
| 174 |
|
---|
| 175 |
|
---|
| 176 | public void SetSelection(IDictionary<int, IList<int>> selection) {
|
---|
| 177 | originalData.SetSelection(selection);
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | public IDictionary<int, IList<int>> GetSelection() {
|
---|
| 181 | return originalData.GetSelection();
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | public void ClearSelection() {
|
---|
| 185 | originalData.ClearSelection();
|
---|
| 186 | }
|
---|
| 187 |
|
---|
[10847] | 188 | public event EventHandler SelectionChanged {
|
---|
| 189 | add { originalData.SelectionChanged += value; }
|
---|
| 190 | remove { originalData.SelectionChanged -= value; }
|
---|
| 191 | }
|
---|
[10804] | 192 |
|
---|
| 193 | #endregion
|
---|
[10783] | 194 | }
|
---|
| 195 | }
|
---|