1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2016 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 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Windows.Forms;
|
---|
25 | using HeuristicLab.Core.Views;
|
---|
26 | using HeuristicLab.Data;
|
---|
27 | using HeuristicLab.MainForm;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
30 |
|
---|
31 | [View("Statistics View")]
|
---|
32 | [Content(typeof(StatisticsContent), true)]
|
---|
33 | public partial class StatisticsView : ItemView {
|
---|
34 |
|
---|
35 | private StringMatrix statisticsMatrix;
|
---|
36 |
|
---|
37 | private static readonly string[] RowNames = new[] {
|
---|
38 | "Type",
|
---|
39 | "Missing Values",
|
---|
40 | "Min",
|
---|
41 | "Max",
|
---|
42 | "Median",
|
---|
43 | "Average",
|
---|
44 | "std. Deviation",
|
---|
45 | "Variance",
|
---|
46 | "25th Percentile",
|
---|
47 | "75th Percentile",
|
---|
48 | "Most Common Value",
|
---|
49 | "Num. diff. Values"
|
---|
50 | };
|
---|
51 |
|
---|
52 | public new StatisticsContent Content {
|
---|
53 | get { return (StatisticsContent)base.Content; }
|
---|
54 | set { base.Content = value; }
|
---|
55 | }
|
---|
56 |
|
---|
57 | public StatisticsView() {
|
---|
58 | InitializeComponent();
|
---|
59 | }
|
---|
60 |
|
---|
61 | protected override void OnContentChanged() {
|
---|
62 | base.OnContentChanged();
|
---|
63 | if (Content == null) {
|
---|
64 | txtRows.Text = "";
|
---|
65 | txtColumns.Text = "";
|
---|
66 | txtNumericColumns.Text = "";
|
---|
67 | txtNominalColumns.Text = "";
|
---|
68 | txtMissingValuesTotal.Text = "";
|
---|
69 | stringMatrixView.Content = null;
|
---|
70 | statisticsMatrix = null;
|
---|
71 | } else {
|
---|
72 | UpdateData();
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | protected override void RegisterContentEvents() {
|
---|
77 | base.RegisterContentEvents();
|
---|
78 | Content.Changed += Content_Changed;
|
---|
79 | }
|
---|
80 |
|
---|
81 | protected override void DeregisterContentEvents() {
|
---|
82 | Content.Changed -= Content_Changed;
|
---|
83 | base.DeregisterContentEvents();
|
---|
84 | }
|
---|
85 |
|
---|
86 | private void UpdateData() {
|
---|
87 | var logic = Content.StatisticsLogic;
|
---|
88 | var rowCount = logic.GetRowCount();
|
---|
89 | txtRows.Text = logic.GetColumnCount().ToString();
|
---|
90 | txtColumns.Text = rowCount.ToString();
|
---|
91 | txtNumericColumns.Text = logic.GetNumericColumnCount().ToString();
|
---|
92 | txtNominalColumns.Text = logic.GetNominalColumnCount().ToString();
|
---|
93 | txtMissingValuesTotal.Text = logic.GetMissingValueCount().ToString();
|
---|
94 |
|
---|
95 | statisticsMatrix = new StringMatrix(RowNames.Length, Content.PreprocessingData.Columns) {
|
---|
96 | RowNames = StatisticsView.RowNames,
|
---|
97 | ColumnNames = Content.PreprocessingData.VariableNames
|
---|
98 | };
|
---|
99 |
|
---|
100 | if (rowCount > 0) {
|
---|
101 | for (int i = 0; i < logic.GetColumnCount(); ++i) {
|
---|
102 | var data = GetList(i);
|
---|
103 | for (int j = 0; j < data.Count; j++) {
|
---|
104 | statisticsMatrix[j, i] = data[j];
|
---|
105 | }
|
---|
106 | }
|
---|
107 | }
|
---|
108 | stringMatrixView.Content = statisticsMatrix;
|
---|
109 |
|
---|
110 | foreach (DataGridViewColumn column in stringMatrixView.DataGridView.Columns) {
|
---|
111 | var variable = column.HeaderText;
|
---|
112 | bool isInputTarget = Content.PreprocessingData.InputVariables.Contains(variable)
|
---|
113 | || Content.PreprocessingData.TargetVariable == variable;
|
---|
114 | column.Visible = isInputTarget;
|
---|
115 | }
|
---|
116 | stringMatrixView.DataGridView.AutoResizeColumns();
|
---|
117 |
|
---|
118 | //foreach (DataGridViewRow row in stringMatrixView.DataGridView.Rows) {
|
---|
119 | // var variable = (string)row.HeaderCell.Value;
|
---|
120 | // bool isInputTarget = Content.PreprocessingData.InputVariables.Contains(variable)
|
---|
121 | // || Content.PreprocessingData.TargetVariable == variable;
|
---|
122 | // row.Visible = isInputTarget;
|
---|
123 | //}
|
---|
124 | }
|
---|
125 |
|
---|
126 | private List<string> GetList(int i) {
|
---|
127 | List<string> list;
|
---|
128 | var logic = Content.StatisticsLogic;
|
---|
129 | if (logic.VariableHasType<double>(i)) {
|
---|
130 | list = GetDoubleColumns(i);
|
---|
131 | } else if (logic.VariableHasType<string>(i)) {
|
---|
132 | list = GetStringColumns(i);
|
---|
133 | } else if (logic.VariableHasType<DateTime>(i)) {
|
---|
134 | list = GetDateTimeColumns(i);
|
---|
135 | } else {
|
---|
136 | list = new List<string>();
|
---|
137 | for (int j = 0; j < RowNames.Length; ++j) {
|
---|
138 | list.Add("unknown column type");
|
---|
139 | }
|
---|
140 | }
|
---|
141 | return list;
|
---|
142 | }
|
---|
143 |
|
---|
144 | private List<string> GetDoubleColumns(int columnIndex) {
|
---|
145 | var logic = Content.StatisticsLogic;
|
---|
146 | return new List<string> {
|
---|
147 | logic.GetColumnTypeAsString(columnIndex),
|
---|
148 | logic.GetMissingValueCount(columnIndex).ToString(),
|
---|
149 | logic.GetMin<double>(columnIndex,double.NaN).ToString(),
|
---|
150 | logic.GetMax<double>(columnIndex,double.NaN).ToString(),
|
---|
151 | logic.GetMedian(columnIndex).ToString(),
|
---|
152 | logic.GetAverage(columnIndex).ToString(),
|
---|
153 | logic.GetStandardDeviation(columnIndex).ToString(),
|
---|
154 | logic.GetVariance(columnIndex).ToString(),
|
---|
155 | logic.GetOneQuarterPercentile(columnIndex).ToString(),
|
---|
156 | logic.GetThreeQuarterPercentile(columnIndex).ToString(),
|
---|
157 | logic.GetMostCommonValue<double>(columnIndex,double.NaN).ToString(),
|
---|
158 | logic.GetDifferentValuesCount<double>(columnIndex).ToString()
|
---|
159 | };
|
---|
160 | }
|
---|
161 |
|
---|
162 | private List<string> GetStringColumns(int columnIndex) {
|
---|
163 | var logic = Content.StatisticsLogic;
|
---|
164 | return new List<string> {
|
---|
165 | logic.GetColumnTypeAsString(columnIndex),
|
---|
166 | logic.GetMissingValueCount(columnIndex).ToString(),
|
---|
167 | "", //min
|
---|
168 | "", //max
|
---|
169 | "", //median
|
---|
170 | "", //average
|
---|
171 | "", //standard deviation
|
---|
172 | "", //variance
|
---|
173 | "", //quarter percentile
|
---|
174 | "", //three quarter percentile
|
---|
175 | logic.GetMostCommonValue<string>(columnIndex,string.Empty) ?? "",
|
---|
176 | logic.GetDifferentValuesCount<string>(columnIndex).ToString()
|
---|
177 | };
|
---|
178 | }
|
---|
179 |
|
---|
180 | private List<string> GetDateTimeColumns(int columnIndex) {
|
---|
181 | var logic = Content.StatisticsLogic;
|
---|
182 | return new List<string> {
|
---|
183 | logic.GetColumnTypeAsString(columnIndex),
|
---|
184 | logic.GetMissingValueCount(columnIndex).ToString(),
|
---|
185 | logic.GetMin<DateTime>(columnIndex,DateTime.MinValue).ToString(),
|
---|
186 | logic.GetMax<DateTime>(columnIndex,DateTime.MinValue).ToString(),
|
---|
187 | logic.GetMedianDateTime(columnIndex).ToString(),
|
---|
188 | logic.GetAverageDateTime(columnIndex).ToString(),
|
---|
189 | logic.GetStandardDeviation(columnIndex).ToString(),
|
---|
190 | logic.GetVariance(columnIndex).ToString(), //variance
|
---|
191 | logic.GetOneQuarterPercentile(columnIndex).ToString(),
|
---|
192 | logic.GetThreeQuarterPercentile(columnIndex).ToString(),
|
---|
193 | logic.GetMostCommonValue<DateTime>(columnIndex,DateTime.MinValue).ToString(),
|
---|
194 | logic.GetDifferentValuesCount<DateTime>(columnIndex).ToString()
|
---|
195 | };
|
---|
196 | }
|
---|
197 |
|
---|
198 | private void Content_Changed(object sender, DataPreprocessingChangedEventArgs e) {
|
---|
199 | UpdateData();
|
---|
200 | }
|
---|
201 |
|
---|
202 | private void checkInputsTargetButton_Click(object sender, EventArgs e) {
|
---|
203 | foreach (DataGridViewColumn column in stringMatrixView.DataGridView.Columns) {
|
---|
204 | var variable = column.HeaderText;
|
---|
205 | bool isInputTarget = Content.PreprocessingData.InputVariables.Contains(variable)
|
---|
206 | || Content.PreprocessingData.TargetVariable == variable;
|
---|
207 | column.Visible = isInputTarget;
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|
211 | private void checkAllButton_Click(object sender, EventArgs e) {
|
---|
212 | foreach (DataGridViewColumn column in stringMatrixView.DataGridView.Columns) {
|
---|
213 | column.Visible = true;
|
---|
214 | }
|
---|
215 | }
|
---|
216 |
|
---|
217 | private void uncheckAllButton_Click(object sender, EventArgs e) {
|
---|
218 | foreach (DataGridViewColumn column in stringMatrixView.DataGridView.Columns) {
|
---|
219 | column.Visible = false;
|
---|
220 | }
|
---|
221 | }
|
---|
222 | }
|
---|
223 | }
|
---|