1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2013 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 |
|
---|
22 |
|
---|
23 | using System;
|
---|
24 | using System.Collections.Generic;
|
---|
25 | using HeuristicLab.Analysis;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.DataPreprocessing {
|
---|
28 | public class HistogramLogic : IHistogramLogic {
|
---|
29 | private IPreprocessingData preprocessingData;
|
---|
30 | private DataTable dataTable;
|
---|
31 |
|
---|
32 | public HistogramLogic(IPreprocessingData preprocessingData) {
|
---|
33 | this.preprocessingData = preprocessingData;
|
---|
34 | dataTable = new DataTable("Histogram");
|
---|
35 | FillDataTable();
|
---|
36 | preprocessingData.Changed += PreprocessingData_Changed;
|
---|
37 | }
|
---|
38 |
|
---|
39 | private void FillDataTable() {
|
---|
40 | IEnumerable<string> variableNames = preprocessingData.VariableNames;
|
---|
41 |
|
---|
42 | foreach (string variableName in variableNames) {
|
---|
43 | IList<double> values = preprocessingData.GetValues<double>(variableName);
|
---|
44 | DataRow row = new DataRow(variableName, "", values);
|
---|
45 | row.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
|
---|
46 | dataTable.Rows.Add(row);
|
---|
47 | }
|
---|
48 |
|
---|
49 | }
|
---|
50 |
|
---|
51 | public IEnumerable<object> GetVariableNames() {
|
---|
52 | List<string> doubleVariableNames = new List<string>();
|
---|
53 |
|
---|
54 | //only return variable names from type double
|
---|
55 | foreach (string variableName in preprocessingData.VariableNames) {
|
---|
56 | if (preprocessingData.IsType<double>(preprocessingData.GetColumnIndex(variableName)))
|
---|
57 | doubleVariableNames.Add(variableName);
|
---|
58 | }
|
---|
59 |
|
---|
60 | return doubleVariableNames;
|
---|
61 | }
|
---|
62 |
|
---|
63 | public DataTable GetDataTable() {
|
---|
64 | return dataTable;
|
---|
65 | }
|
---|
66 |
|
---|
67 | public void RemoveVariable(string name) {
|
---|
68 | dataTable.Rows.Remove(name);
|
---|
69 | }
|
---|
70 |
|
---|
71 | public void AddVariable(string name) {
|
---|
72 | IList<double> values = preprocessingData.GetValues<double>(name);
|
---|
73 | DataRow row = new DataRow(name, "", values);
|
---|
74 | row.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
|
---|
75 | dataTable.Rows.Add(row);
|
---|
76 | }
|
---|
77 |
|
---|
78 | public bool VariableIsDisplayed(string name) {
|
---|
79 |
|
---|
80 | foreach (var item in dataTable.Rows) {
|
---|
81 | if (item.Name == name)
|
---|
82 | return true;
|
---|
83 | }
|
---|
84 | return false;
|
---|
85 | }
|
---|
86 |
|
---|
87 | void PreprocessingData_Changed(object sender, DataPreprocessingChangedEventArgs e) {
|
---|
88 | var variableName = preprocessingData.GetVariableName(e.Column);
|
---|
89 | switch (e.Type) {
|
---|
90 | case DataPreprocessingChangedEventType.DeleteColumn:
|
---|
91 | dataTable.Rows.Remove(variableName);
|
---|
92 | break;
|
---|
93 | case DataPreprocessingChangedEventType.AddColumn:
|
---|
94 | dataTable.Rows.Add(new DataRow(variableName, String.Empty, preprocessingData.GetValues<double>(e.Column)));
|
---|
95 | break;
|
---|
96 | case DataPreprocessingChangedEventType.ChangeColumn:
|
---|
97 | case DataPreprocessingChangedEventType.ChangeItem:
|
---|
98 | dataTable.Rows.Remove(variableName);
|
---|
99 | dataTable.Rows.Add(new DataRow(variableName, String.Empty, preprocessingData.GetValues<double>(e.Column)));
|
---|
100 | break;
|
---|
101 | case DataPreprocessingChangedEventType.DeleteRow:
|
---|
102 | case DataPreprocessingChangedEventType.AddRow:
|
---|
103 | dataTable.Rows.Clear();
|
---|
104 | FillDataTable();
|
---|
105 | break;
|
---|
106 | }
|
---|
107 | }
|
---|
108 | }
|
---|
109 | }
|
---|