Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Views/StatisticsView.cs @ 10539

Last change on this file since 10539 was 10539, checked in by rstoll, 10 years ago

Added License notice

File size: 6.3 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.Windows.Forms;
25using HeuristicLab.Core.Views;
26using HeuristicLab.MainForm;
27using HeuristicLab.MainForm.WindowsForms;
28
29namespace HeuristicLab.DataPreprocessing {
30
31  [View("Statistics View")]
32  [Content(typeof(StatisticsContent), false)]
33  public partial class StatisticsView : ItemView {
34
35    private List<List<string>> columnsRowsMatrix;
36    private readonly int COLUMNS = 10;
37
38    public new StatisticsContent Content {
39      get { return (StatisticsContent)base.Content; }
40      set { base.Content = value; }
41    }
42
43    public StatisticsView() {
44      InitializeComponent();
45    }
46
47    protected override void OnContentChanged() {
48      base.OnContentChanged();
49      if (Content == null) {
50        txtRows.Text = "";
51        txtColumns.Text = "";
52        txtNumericColumns.Text = "";
53        txtNominalColumns.Text = "";
54        txtMissingValuesTotal.Text = "";
55        dataGridView.Columns.Clear();
56      } else {
57        UpdateData();
58      }
59    }
60    private void UpdateData() {
61      var logic = Content.StatisticsLogic;
62      txtRows.Text = logic.GetRowCount().ToString();
63      txtColumns.Text = logic.GetColumnCount().ToString();
64      txtNumericColumns.Text = logic.GetNumericColumnCount().ToString();
65      txtNominalColumns.Text = logic.GetNominalColumnCount().ToString();
66      txtMissingValuesTotal.Text = logic.GetMissingValueCount().ToString();
67
68      columnsRowsMatrix = new List<List<string>>();
69      DataGridViewColumn[] columns = new DataGridViewColumn[10];
70      for (int i = 0; i < COLUMNS; ++i) {
71        var column = new DataGridViewTextBoxColumn();
72        column.FillWeight = 1;
73        columns[i] = column;
74      }
75
76      columns[0].HeaderCell.Value = "Type";
77      columns[1].HeaderCell.Value = "Missing Values";
78      columns[2].HeaderCell.Value = "Min";
79      columns[3].HeaderCell.Value = "Max";
80      columns[4].HeaderCell.Value = "Median";
81      columns[5].HeaderCell.Value = "Average";
82      columns[6].HeaderCell.Value = "std. Deviation";
83      columns[7].HeaderCell.Value = "Variance";
84      columns[8].HeaderCell.Value = "Most Common Value";
85      columns[9].HeaderCell.Value = "Num. diff. Values";
86
87      for (int i = 0; i < logic.GetColumnCount(); ++i) {
88        List<string> list;
89        if (logic.IsType<double>(i)) {
90          list = GetDoubleColumns(i);
91        } else if (logic.IsType<string>(i)) {
92          list = GetStringColumns(i);
93        } else if (logic.IsType<DateTime>(i)) {
94          list = GetDateTimeColumns(i);
95        } else {
96          list = new List<string>();
97          for (int j = 0; j < COLUMNS; ++j) {
98            list.Add("unknown column type");
99          }
100        }
101        columnsRowsMatrix.Add(list);
102      }
103
104      dataGridView.Columns.Clear();
105      dataGridView.Columns.AddRange(columns);
106      dataGridView.RowCount = columnsRowsMatrix.Count;
107
108      for (int i = 0; i < columnsRowsMatrix.Count; ++i) {
109        dataGridView.Rows[i].HeaderCell.Value = logic.GetVariableName(i);
110      }
111      dataGridView.AllowUserToResizeColumns = true;
112    }
113
114    private List<string> GetDoubleColumns(int columnIndex) {
115      var logic = Content.StatisticsLogic;
116      return new List<string> {
117        logic.GetColumnTypeAsString(columnIndex),
118        logic.GetMissingValueCount(columnIndex).ToString(),
119        logic.GetMin<double>(columnIndex).ToString(),
120        logic.GetMax<double>(columnIndex).ToString(),
121        logic.GetMedian(columnIndex).ToString(),
122        logic.GetAverage(columnIndex).ToString(),
123        logic.GetStandardDeviation(columnIndex).ToString(),
124        logic.GetVariance(columnIndex).ToString(),
125        logic.GetMostCommonValue<double>(columnIndex).ToString(),
126        logic.GetDifferentValuesCount<double>(columnIndex).ToString()
127      };
128    }
129
130    private List<string> GetStringColumns(int columnIndex) {
131      var logic = Content.StatisticsLogic;
132      return new List<string> {
133        logic.GetColumnTypeAsString(columnIndex),
134        logic.GetMissingValueCount(columnIndex).ToString(),
135        "", //min
136        "", //max
137        "", //median
138        "", //average
139        "", //standard deviation
140        "", //variance
141        logic.GetMostCommonValue<string>(columnIndex).ToString(),
142        logic.GetDifferentValuesCount<string>(columnIndex).ToString()
143      };
144    }
145
146    private List<string> GetDateTimeColumns(int columnIndex) {
147      var logic = Content.StatisticsLogic;
148      return new List<string> {
149        logic.GetColumnTypeAsString(columnIndex),
150        logic.GetMissingValueCount(columnIndex).ToString(),
151        logic.GetMin<DateTime>(columnIndex).ToString(),
152        logic.GetMax<DateTime>(columnIndex).ToString(),
153        logic.GetMedianDateTime(columnIndex).ToString(),
154        logic.GetAverageDateTime(columnIndex).ToString(),
155        logic.GetStandardDeviation(columnIndex).ToString(),
156        logic.GetVariance(columnIndex).ToString(), //variance
157        logic.GetMostCommonValue<DateTime>(columnIndex).ToString(),
158        logic.GetDifferentValuesCount<DateTime>(columnIndex).ToString()
159      };
160    }
161
162    private List<string> GetDoubleColums(int i) {
163      throw new NotImplementedException();
164    }
165
166    private void dataGridView_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e) {
167      if (Content != null && e.RowIndex < columnsRowsMatrix.Count && e.ColumnIndex < columnsRowsMatrix[0].Count) {
168        e.Value = columnsRowsMatrix[e.RowIndex][e.ColumnIndex];
169      }
170    }
171  }
172}
Note: See TracBrowser for help on using the repository browser.