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