[10539] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 3 | * Copyright (C) 2002-2016 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 |
|
---|
| 22 | using System;
|
---|
[10369] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Windows.Forms;
|
---|
[10303] | 25 | using HeuristicLab.Core.Views;
|
---|
| 26 | using HeuristicLab.MainForm;
|
---|
| 27 |
|
---|
[10558] | 28 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
[10303] | 29 |
|
---|
| 30 | [View("Statistics View")]
|
---|
[10712] | 31 | [Content(typeof(StatisticsContent), true)]
|
---|
[10303] | 32 | public partial class StatisticsView : ItemView {
|
---|
| 33 |
|
---|
[10369] | 34 | private List<List<string>> columnsRowsMatrix;
|
---|
[12889] | 35 | private readonly int COLUMNS = 12;
|
---|
[10369] | 36 |
|
---|
[10303] | 37 | public new StatisticsContent Content {
|
---|
| 38 | get { return (StatisticsContent)base.Content; }
|
---|
| 39 | set { base.Content = value; }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | public StatisticsView() {
|
---|
| 43 | InitializeComponent();
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | protected override void OnContentChanged() {
|
---|
| 47 | base.OnContentChanged();
|
---|
[10369] | 48 | if (Content == null) {
|
---|
| 49 | txtRows.Text = "";
|
---|
| 50 | txtColumns.Text = "";
|
---|
| 51 | txtNumericColumns.Text = "";
|
---|
| 52 | txtNominalColumns.Text = "";
|
---|
| 53 | txtMissingValuesTotal.Text = "";
|
---|
| 54 | dataGridView.Columns.Clear();
|
---|
| 55 | } else {
|
---|
| 56 | UpdateData();
|
---|
[10320] | 57 | }
|
---|
[10303] | 58 | }
|
---|
[10551] | 59 |
|
---|
| 60 | /// <summary>
|
---|
| 61 | /// Adds eventhandlers to the current instance.
|
---|
| 62 | /// </summary>
|
---|
| 63 | protected override void RegisterContentEvents() {
|
---|
| 64 | Content.Changed += Content_Changed;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | /// <summary>
|
---|
| 69 | /// Removes the eventhandlers from the current instance.
|
---|
| 70 | /// </summary>
|
---|
| 71 | protected override void DeregisterContentEvents() {
|
---|
| 72 | Content.Changed -= Content_Changed;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[10369] | 75 | private void UpdateData() {
|
---|
[10370] | 76 | var logic = Content.StatisticsLogic;
|
---|
[10971] | 77 | var rowCount = logic.GetRowCount();
|
---|
| 78 | txtRows.Text = rowCount.ToString();
|
---|
[10370] | 79 | txtColumns.Text = logic.GetColumnCount().ToString();
|
---|
| 80 | txtNumericColumns.Text = logic.GetNumericColumnCount().ToString();
|
---|
| 81 | txtNominalColumns.Text = logic.GetNominalColumnCount().ToString();
|
---|
| 82 | txtMissingValuesTotal.Text = logic.GetMissingValueCount().ToString();
|
---|
[10369] | 83 |
|
---|
| 84 | columnsRowsMatrix = new List<List<string>>();
|
---|
[12889] | 85 | DataGridViewColumn[] columns = new DataGridViewColumn[COLUMNS];
|
---|
[10374] | 86 | for (int i = 0; i < COLUMNS; ++i) {
|
---|
[10369] | 87 | var column = new DataGridViewTextBoxColumn();
|
---|
[10740] | 88 | column.SortMode = DataGridViewColumnSortMode.Automatic;
|
---|
[10369] | 89 | column.FillWeight = 1;
|
---|
| 90 | columns[i] = column;
|
---|
[10374] | 91 | }
|
---|
[10369] | 92 |
|
---|
[10534] | 93 | columns[0].HeaderCell.Value = "Type";
|
---|
| 94 | columns[1].HeaderCell.Value = "Missing Values";
|
---|
| 95 | columns[2].HeaderCell.Value = "Min";
|
---|
| 96 | columns[3].HeaderCell.Value = "Max";
|
---|
| 97 | columns[4].HeaderCell.Value = "Median";
|
---|
| 98 | columns[5].HeaderCell.Value = "Average";
|
---|
| 99 | columns[6].HeaderCell.Value = "std. Deviation";
|
---|
| 100 | columns[7].HeaderCell.Value = "Variance";
|
---|
[12889] | 101 | columns[8].HeaderCell.Value = "25th Percentile";
|
---|
| 102 | columns[9].HeaderCell.Value = "75th Percentile";
|
---|
| 103 | columns[10].HeaderCell.Value = "Most Common Value";
|
---|
| 104 | columns[11].HeaderCell.Value = "Num. diff. Values";
|
---|
[10534] | 105 |
|
---|
[10971] | 106 | if (rowCount > 0) {
|
---|
| 107 | for (int i = 0; i < logic.GetColumnCount(); ++i) {
|
---|
| 108 | columnsRowsMatrix.Add(GetList(i));
|
---|
| 109 | }
|
---|
[10369] | 110 | }
|
---|
| 111 |
|
---|
| 112 | dataGridView.Columns.Clear();
|
---|
| 113 | dataGridView.Columns.AddRange(columns);
|
---|
[10534] | 114 | dataGridView.RowCount = columnsRowsMatrix.Count;
|
---|
[10369] | 115 |
|
---|
[10534] | 116 | for (int i = 0; i < columnsRowsMatrix.Count; ++i) {
|
---|
| 117 | dataGridView.Rows[i].HeaderCell.Value = logic.GetVariableName(i);
|
---|
| 118 | }
|
---|
[10691] | 119 |
|
---|
| 120 | dataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
|
---|
| 121 | dataGridView.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders);
|
---|
[10534] | 122 | dataGridView.AllowUserToResizeColumns = true;
|
---|
[10369] | 123 | }
|
---|
| 124 |
|
---|
[10551] | 125 | private List<string> GetList(int i) {
|
---|
| 126 | List<string> list;
|
---|
| 127 | var logic = Content.StatisticsLogic;
|
---|
[11156] | 128 | if (logic.VariableHasType<double>(i)) {
|
---|
[10551] | 129 | list = GetDoubleColumns(i);
|
---|
[11156] | 130 | } else if (logic.VariableHasType<string>(i)) {
|
---|
[10551] | 131 | list = GetStringColumns(i);
|
---|
[11156] | 132 | } else if (logic.VariableHasType<DateTime>(i)) {
|
---|
[10551] | 133 | list = GetDateTimeColumns(i);
|
---|
| 134 | } else {
|
---|
| 135 | list = new List<string>();
|
---|
| 136 | for (int j = 0; j < COLUMNS; ++j) {
|
---|
| 137 | list.Add("unknown column type");
|
---|
| 138 | }
|
---|
| 139 | }
|
---|
| 140 | return list;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
[10369] | 143 | private List<string> GetDoubleColumns(int columnIndex) {
|
---|
| 144 | var logic = Content.StatisticsLogic;
|
---|
| 145 | return new List<string> {
|
---|
[10371] | 146 | logic.GetColumnTypeAsString(columnIndex),
|
---|
| 147 | logic.GetMissingValueCount(columnIndex).ToString(),
|
---|
[13935] | 148 | logic.GetMin<double>(columnIndex,double.NaN).ToString(),
|
---|
| 149 | logic.GetMax<double>(columnIndex,double.NaN).ToString(),
|
---|
[10811] | 150 | logic.GetMedian(columnIndex).ToString(),
|
---|
| 151 | logic.GetAverage(columnIndex).ToString(),
|
---|
[10371] | 152 | logic.GetStandardDeviation(columnIndex).ToString(),
|
---|
| 153 | logic.GetVariance(columnIndex).ToString(),
|
---|
[12889] | 154 | logic.GetOneQuarterPercentile(columnIndex).ToString(),
|
---|
| 155 | logic.GetThreeQuarterPercentile(columnIndex).ToString(),
|
---|
[13935] | 156 | logic.GetMostCommonValue<double>(columnIndex,double.NaN).ToString(),
|
---|
[10371] | 157 | logic.GetDifferentValuesCount<double>(columnIndex).ToString()
|
---|
[10369] | 158 | };
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | private List<string> GetStringColumns(int columnIndex) {
|
---|
[10374] | 162 | var logic = Content.StatisticsLogic;
|
---|
| 163 | return new List<string> {
|
---|
| 164 | logic.GetColumnTypeAsString(columnIndex),
|
---|
| 165 | logic.GetMissingValueCount(columnIndex).ToString(),
|
---|
| 166 | "", //min
|
---|
| 167 | "", //max
|
---|
| 168 | "", //median
|
---|
| 169 | "", //average
|
---|
| 170 | "", //standard deviation
|
---|
| 171 | "", //variance
|
---|
[12889] | 172 | "", //quarter percentile
|
---|
| 173 | "", //three quarter percentile
|
---|
[13935] | 174 | logic.GetMostCommonValue<string>(columnIndex,string.Empty) ?? "",
|
---|
[10374] | 175 | logic.GetDifferentValuesCount<string>(columnIndex).ToString()
|
---|
| 176 | };
|
---|
[10369] | 177 | }
|
---|
[10374] | 178 |
|
---|
| 179 | private List<string> GetDateTimeColumns(int columnIndex) {
|
---|
| 180 | var logic = Content.StatisticsLogic;
|
---|
| 181 | return new List<string> {
|
---|
| 182 | logic.GetColumnTypeAsString(columnIndex),
|
---|
| 183 | logic.GetMissingValueCount(columnIndex).ToString(),
|
---|
[13935] | 184 | logic.GetMin<DateTime>(columnIndex,DateTime.MinValue).ToString(),
|
---|
| 185 | logic.GetMax<DateTime>(columnIndex,DateTime.MinValue).ToString(),
|
---|
[12889] | 186 | logic.GetMedianDateTime(columnIndex).ToString(),
|
---|
[10811] | 187 | logic.GetAverageDateTime(columnIndex).ToString(),
|
---|
[10534] | 188 | logic.GetStandardDeviation(columnIndex).ToString(),
|
---|
| 189 | logic.GetVariance(columnIndex).ToString(), //variance
|
---|
[12889] | 190 | logic.GetOneQuarterPercentile(columnIndex).ToString(),
|
---|
| 191 | logic.GetThreeQuarterPercentile(columnIndex).ToString(),
|
---|
[13935] | 192 | logic.GetMostCommonValue<DateTime>(columnIndex,DateTime.MinValue).ToString(),
|
---|
[10534] | 193 | logic.GetDifferentValuesCount<DateTime>(columnIndex).ToString()
|
---|
[10374] | 194 | };
|
---|
[10369] | 195 | }
|
---|
| 196 |
|
---|
| 197 | private void dataGridView_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e) {
|
---|
[10534] | 198 | if (Content != null && e.RowIndex < columnsRowsMatrix.Count && e.ColumnIndex < columnsRowsMatrix[0].Count) {
|
---|
| 199 | e.Value = columnsRowsMatrix[e.RowIndex][e.ColumnIndex];
|
---|
[10369] | 200 | }
|
---|
| 201 | }
|
---|
[10551] | 202 |
|
---|
| 203 | private void Content_Changed(object sender, DataPreprocessingChangedEventArgs e) {
|
---|
| 204 | switch (e.Type) {
|
---|
| 205 | case DataPreprocessingChangedEventType.DeleteColumn:
|
---|
| 206 | columnsRowsMatrix.RemoveAt(e.Column);
|
---|
| 207 | break;
|
---|
| 208 | case DataPreprocessingChangedEventType.AddColumn:
|
---|
| 209 | columnsRowsMatrix.Insert(e.Row, GetList(e.Column));
|
---|
| 210 | dataGridView.RowCount++;
|
---|
| 211 | break;
|
---|
| 212 | case DataPreprocessingChangedEventType.ChangeItem:
|
---|
| 213 | columnsRowsMatrix[e.Column] = GetList(e.Column);
|
---|
| 214 | break;
|
---|
| 215 | case DataPreprocessingChangedEventType.DeleteRow:
|
---|
| 216 | case DataPreprocessingChangedEventType.AddRow:
|
---|
[10817] | 217 | default:
|
---|
[10551] | 218 | for (int i = 0; i < columnsRowsMatrix.Count; ++i) {
|
---|
| 219 | columnsRowsMatrix[i] = GetList(e.Column);
|
---|
| 220 | }
|
---|
| 221 | break;
|
---|
| 222 | }
|
---|
| 223 | dataGridView.Refresh();
|
---|
| 224 | }
|
---|
[10303] | 225 | }
|
---|
| 226 | }
|
---|