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