Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/ChartLogic.cs @ 10811

Last change on this file since 10811 was 10811, checked in by sbreuer, 10 years ago
  • provide default value (false) for considerSelection parameter
File size: 3.7 KB
RevLine 
[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
21
[10544]22using System;
[10244]23using System.Collections.Generic;
[10377]24using HeuristicLab.Analysis;
[10628]25using HeuristicLab.Core;
26using HeuristicLab.Data;
[10244]27
[10539]28namespace HeuristicLab.DataPreprocessing {
[10658]29
30  public class ChartLogic : IChartLogic {
[10628]31 
[10586]32    private ITransactionalPreprocessingData preprocessingData;
[10377]33
[10658]34    public ChartLogic(ITransactionalPreprocessingData preprocessingData) {
[10377]35      this.preprocessingData = preprocessingData;
36    }
37
[10658]38    public DataRow CreateDataRow(string variableName, DataRowVisualProperties.DataRowChartType chartType) {
[10811]39      IList<double> values = preprocessingData.GetValues<double>(variableName);
[10628]40      DataRow row = new DataRow(variableName, "", values);
[10658]41      row.VisualProperties.ChartType = chartType;
[10628]42      return row;
[10377]43    }
[10382]44
[10803]45    public DataRow CreateDataRowRange(string variableName,int start, int end, DataRowVisualProperties.DataRowChartType chartType) {
[10811]46      IList<double> values = preprocessingData.GetValues<double>(variableName);
[10803]47      IList<double> valuesRange = new List<double>();
[10736]48      for (int i = 0; i < values.Count; i++) {
[10803]49        if (i >= start && i <= end)
50          valuesRange.Add(values[i]);
51        else
52          valuesRange.Add(Double.NaN);
53      }
54
55      DataRow row = new DataRow(variableName, "", valuesRange);
56      row.VisualProperties.ChartType = chartType;
57      return row;
58    }
59
60    private void ReplaceNANwithZero(IList<double> values) {
61      for (int i = 0; i < values.Count; i++) {
[10736]62        if (Double.IsNaN(values[i]))
63          values[i] = 0;
64      }
65    }
66
67
68
[10628]69    private IEnumerable<string> GetVariableNames() {
[10552]70      List<string> doubleVariableNames = new List<string>();
71
72      //only return variable names from type double
73      foreach (string variableName in preprocessingData.VariableNames) {
74        if (preprocessingData.IsType<double>(preprocessingData.GetColumnIndex(variableName)))
75          doubleVariableNames.Add(variableName);
76      }
77
78      return doubleVariableNames;
[10382]79    }
80
[10628]81    public ICheckedItemList<StringValue> CreateVariableItemList() {
82      ICheckedItemList<StringValue> itemList = new CheckedItemList<StringValue>();
83      foreach (string name in GetVariableNames()) {
84        itemList.Add(new StringValue(name), true);
[10382]85      }
[10628]86      return new ReadOnlyCheckedItemList<StringValue>(itemList);
[10382]87    }
88
[10573]89    public event DataPreprocessingChangedEventHandler Changed {
90      add { preprocessingData.Changed += value; }
91      remove { preprocessingData.Changed -= value; }
92    }
[10628]93
94    public string GetVariableNameByIndex(int index) {
95      return preprocessingData.GetVariableName(index);
96    }
97
[10733]98
99    public List<DataRow> CreateAllDataRows(DataRowVisualProperties.DataRowChartType chartType) {
100      List<DataRow> dataRows = new List<DataRow>();
101      foreach (var name in GetVariableNames())
102        dataRows.Add(CreateDataRow(name, chartType));
103      return dataRows;
104    }
105
[10244]106  }
107}
Note: See TracBrowser for help on using the repository browser.