[10539] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16140] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[10539] | 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 |
|
---|
[10992] | 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
[10539] | 24 | using System.Drawing;
|
---|
[15110] | 25 | using System.Linq;
|
---|
[10992] | 26 | using HeuristicLab.Analysis;
|
---|
[10539] | 27 | using HeuristicLab.Common;
|
---|
[15110] | 28 | using HeuristicLab.Common.Resources;
|
---|
[10245] | 29 | using HeuristicLab.Core;
|
---|
[10818] | 30 | using HeuristicLab.Data;
|
---|
[16140] | 31 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[10242] | 32 |
|
---|
[10539] | 33 | namespace HeuristicLab.DataPreprocessing {
|
---|
[10658] | 34 | [Item("PreprocessingChart", "Represents a preprocessing chart.")]
|
---|
[16140] | 35 | [StorableClass]
|
---|
| 36 | public class PreprocessingChartContent : PreprocessingContent, IViewShortcut {
|
---|
[15110] | 37 | public enum LegendOrder {
|
---|
[15210] | 38 | Alphabetically,
|
---|
| 39 | Appearance
|
---|
[10992] | 40 | }
|
---|
[10252] | 41 |
|
---|
[15110] | 42 | public static new Image StaticItemImage {
|
---|
| 43 | get { return VSImageLibrary.PieChart; }
|
---|
[10992] | 44 | }
|
---|
[10818] | 45 |
|
---|
[16140] | 46 | [Storable]
|
---|
| 47 | private ICheckedItemList<StringValue> variableItemList;
|
---|
[10992] | 48 | public ICheckedItemList<StringValue> VariableItemList {
|
---|
[15110] | 49 | get {
|
---|
| 50 | if (variableItemList == null)
|
---|
| 51 | variableItemList = CreateVariableItemList(PreprocessingData);
|
---|
[16140] | 52 | return variableItemList;
|
---|
[15110] | 53 | }
|
---|
[10992] | 54 | }
|
---|
[10818] | 55 |
|
---|
[15110] | 56 | public event DataPreprocessingChangedEventHandler Changed {
|
---|
| 57 | add { PreprocessingData.Changed += value; }
|
---|
| 58 | remove { PreprocessingData.Changed -= value; }
|
---|
| 59 | }
|
---|
[10818] | 60 |
|
---|
[16140] | 61 | #region Constructor, Cloning & Persistence
|
---|
| 62 | public PreprocessingChartContent(IFilteredPreprocessingData preprocessingData)
|
---|
| 63 | : base(preprocessingData) {
|
---|
[10252] | 64 | }
|
---|
| 65 |
|
---|
[16140] | 66 | public PreprocessingChartContent(PreprocessingChartContent original, Cloner cloner)
|
---|
| 67 | : base(original, cloner) {
|
---|
| 68 | variableItemList = cloner.Clone(original.variableItemList);
|
---|
[10245] | 69 | }
|
---|
[10992] | 70 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 71 | return new PreprocessingChartContent(this, cloner);
|
---|
| 72 | }
|
---|
[10245] | 73 |
|
---|
[16140] | 74 | [StorableConstructor]
|
---|
| 75 | protected PreprocessingChartContent(bool deserializing)
|
---|
| 76 | : base(deserializing) { }
|
---|
| 77 | #endregion
|
---|
| 78 |
|
---|
[10992] | 79 | public DataRow CreateDataRow(string variableName, DataRowVisualProperties.DataRowChartType chartType) {
|
---|
[15110] | 80 | return CreateDataRow(PreprocessingData, variableName, chartType);
|
---|
[10252] | 81 | }
|
---|
| 82 |
|
---|
[15110] | 83 | public static DataRow CreateDataRow(IFilteredPreprocessingData preprocessingData, string variableName, DataRowVisualProperties.DataRowChartType chartType) {
|
---|
[16140] | 84 | var values = preprocessingData.GetValues<double>(preprocessingData.GetColumnIndex(variableName));
|
---|
| 85 | var row = new DataRow(variableName, "", values) {
|
---|
| 86 | VisualProperties = {
|
---|
| 87 | ChartType = chartType,
|
---|
| 88 | StartIndexZero = true
|
---|
| 89 | }
|
---|
| 90 | };
|
---|
[10992] | 91 | return row;
|
---|
[10573] | 92 | }
|
---|
[10818] | 93 |
|
---|
[15110] | 94 | private static ICheckedItemList<StringValue> CreateVariableItemList(IPreprocessingData preprocessingData) {
|
---|
[10992] | 95 | ICheckedItemList<StringValue> itemList = new CheckedItemList<StringValue>();
|
---|
[15110] | 96 | foreach (string name in preprocessingData.GetDoubleVariableNames()) {
|
---|
[12676] | 97 | var n = new StringValue(name);
|
---|
[15110] | 98 | bool isInputTarget = preprocessingData.InputVariables.Contains(name) || preprocessingData.TargetVariable == name;
|
---|
| 99 | itemList.Add(n, isInputTarget);
|
---|
[10992] | 100 | }
|
---|
| 101 | return new ReadOnlyCheckedItemList<StringValue>(itemList);
|
---|
[10818] | 102 | }
|
---|
[10992] | 103 |
|
---|
[15210] | 104 | public static IEnumerable<string> GetVariableNamesForGrouping(IPreprocessingData preprocessingData, int maxDistinctValues = 20) {
|
---|
[15110] | 105 | var variableNames = new List<string>();
|
---|
| 106 |
|
---|
| 107 | for (int i = 0; i < preprocessingData.Columns; ++i) {
|
---|
| 108 | int distinctValues = Int32.MaxValue;
|
---|
| 109 | if (preprocessingData.VariableHasType<double>(i))
|
---|
| 110 | distinctValues = preprocessingData.GetValues<double>(i).GroupBy(x => x).Count();
|
---|
| 111 | else if (preprocessingData.VariableHasType<string>(i))
|
---|
| 112 | distinctValues = preprocessingData.GetValues<string>(i).GroupBy(x => x).Count();
|
---|
| 113 | else if (preprocessingData.VariableHasType<DateTime>(i))
|
---|
| 114 | distinctValues = preprocessingData.GetValues<DateTime>(i).GroupBy(x => x).Count();
|
---|
| 115 |
|
---|
[15210] | 116 | if (distinctValues <= maxDistinctValues)
|
---|
[15110] | 117 | variableNames.Add(preprocessingData.GetVariableName(i));
|
---|
| 118 | }
|
---|
| 119 | return variableNames;
|
---|
[10992] | 120 | }
|
---|
[10242] | 121 | }
|
---|
| 122 | }
|
---|