Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/StatisticsView.cs @ 14792

Last change on this file since 14792 was 14546, checked in by pfleck, 8 years ago

#2709 Added shortcuts for select input/all/none variables in datagrid and statistics.

File size: 8.1 KB
RevLine 
[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
22using System;
[10369]23using System.Collections.Generic;
24using System.Windows.Forms;
[10303]25using HeuristicLab.Core.Views;
[14545]26using HeuristicLab.Data;
[10303]27using HeuristicLab.MainForm;
28
[10558]29namespace HeuristicLab.DataPreprocessing.Views {
[10303]30
31  [View("Statistics View")]
[10712]32  [Content(typeof(StatisticsContent), true)]
[10303]33  public partial class StatisticsView : ItemView {
34
[14545]35    private StringMatrix statisticsMatrix;
[10369]36
[14545]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
[10303]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();
[10369]63      if (Content == null) {
64        txtRows.Text = "";
65        txtColumns.Text = "";
66        txtNumericColumns.Text = "";
67        txtNominalColumns.Text = "";
68        txtMissingValuesTotal.Text = "";
[14545]69        stringMatrixView.Content = null;
70        statisticsMatrix = null;
[10369]71      } else {
72        UpdateData();
[10320]73      }
[10303]74    }
[10551]75
76    protected override void RegisterContentEvents() {
[14545]77      base.RegisterContentEvents();
[10551]78      Content.Changed += Content_Changed;
79    }
80
81    protected override void DeregisterContentEvents() {
82      Content.Changed -= Content_Changed;
[14545]83      base.DeregisterContentEvents();
[10551]84    }
85
[10369]86    private void UpdateData() {
[10370]87      var logic = Content.StatisticsLogic;
[10971]88      var rowCount = logic.GetRowCount();
[14545]89      txtRows.Text = logic.GetColumnCount().ToString();
90      txtColumns.Text = rowCount.ToString();
[10370]91      txtNumericColumns.Text = logic.GetNumericColumnCount().ToString();
92      txtNominalColumns.Text = logic.GetNominalColumnCount().ToString();
93      txtMissingValuesTotal.Text = logic.GetMissingValueCount().ToString();
[10369]94
[14545]95      statisticsMatrix = new StringMatrix(RowNames.Length, Content.PreprocessingData.Columns) {
96        RowNames = StatisticsView.RowNames,
97        ColumnNames = Content.PreprocessingData.VariableNames
98      };
[10369]99
[10971]100      if (rowCount > 0) {
101        for (int i = 0; i < logic.GetColumnCount(); ++i) {
[14545]102          var data = GetList(i);
103          for (int j = 0; j < data.Count; j++) {
104            statisticsMatrix[j, i] = data[j];
105          }
[10971]106        }
[10369]107      }
[14545]108      stringMatrixView.Content = statisticsMatrix;
[10369]109
[14545]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;
[10534]115      }
[14545]116      stringMatrixView.DataGridView.AutoResizeColumns();
[10691]117
[14545]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      //}
[10369]124    }
125
[10551]126    private List<string> GetList(int i) {
127      List<string> list;
128      var logic = Content.StatisticsLogic;
[11156]129      if (logic.VariableHasType<double>(i)) {
[10551]130        list = GetDoubleColumns(i);
[11156]131      } else if (logic.VariableHasType<string>(i)) {
[10551]132        list = GetStringColumns(i);
[11156]133      } else if (logic.VariableHasType<DateTime>(i)) {
[10551]134        list = GetDateTimeColumns(i);
135      } else {
136        list = new List<string>();
[14545]137        for (int j = 0; j < RowNames.Length; ++j) {
[10551]138          list.Add("unknown column type");
139        }
140      }
141      return list;
142    }
143
[10369]144    private List<string> GetDoubleColumns(int columnIndex) {
145      var logic = Content.StatisticsLogic;
146      return new List<string> {
[10371]147        logic.GetColumnTypeAsString(columnIndex),
148        logic.GetMissingValueCount(columnIndex).ToString(),
[13935]149        logic.GetMin<double>(columnIndex,double.NaN).ToString(),
150        logic.GetMax<double>(columnIndex,double.NaN).ToString(),
[10811]151        logic.GetMedian(columnIndex).ToString(),
152        logic.GetAverage(columnIndex).ToString(),
[10371]153        logic.GetStandardDeviation(columnIndex).ToString(),
154        logic.GetVariance(columnIndex).ToString(),
[12889]155        logic.GetOneQuarterPercentile(columnIndex).ToString(),
156        logic.GetThreeQuarterPercentile(columnIndex).ToString(),
[13935]157        logic.GetMostCommonValue<double>(columnIndex,double.NaN).ToString(),
[10371]158        logic.GetDifferentValuesCount<double>(columnIndex).ToString()
[10369]159      };
160    }
161
162    private List<string> GetStringColumns(int columnIndex) {
[10374]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
[12889]173        "", //quarter percentile
174        "", //three quarter percentile
[13935]175        logic.GetMostCommonValue<string>(columnIndex,string.Empty) ?? "",
[10374]176        logic.GetDifferentValuesCount<string>(columnIndex).ToString()
177      };
[10369]178    }
[10374]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(),
[13935]185        logic.GetMin<DateTime>(columnIndex,DateTime.MinValue).ToString(),
186        logic.GetMax<DateTime>(columnIndex,DateTime.MinValue).ToString(),
[12889]187        logic.GetMedianDateTime(columnIndex).ToString(),
[10811]188        logic.GetAverageDateTime(columnIndex).ToString(),
[10534]189        logic.GetStandardDeviation(columnIndex).ToString(),
190        logic.GetVariance(columnIndex).ToString(), //variance
[12889]191        logic.GetOneQuarterPercentile(columnIndex).ToString(),
192        logic.GetThreeQuarterPercentile(columnIndex).ToString(),
[13935]193        logic.GetMostCommonValue<DateTime>(columnIndex,DateTime.MinValue).ToString(),
[10534]194        logic.GetDifferentValuesCount<DateTime>(columnIndex).ToString()
[10374]195      };
[10369]196    }
197
[10551]198    private void Content_Changed(object sender, DataPreprocessingChangedEventArgs e) {
[14545]199      UpdateData();
[10551]200    }
[14546]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    }
[10303]222  }
223}
Note: See TracBrowser for help on using the repository browser.