Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/03/17 10:57:53 (7 years ago)
Author:
pfleck
Message:

#2709: merged branch to trunk

Location:
trunk/sources/HeuristicLab.DataPreprocessing
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.DataPreprocessing

  • trunk/sources/HeuristicLab.DataPreprocessing/3.4

  • trunk/sources/HeuristicLab.DataPreprocessing/3.4/Content/HistogramContent.cs

    r14185 r15110  
    2020#endregion
    2121
    22 using System.Collections.Generic;
     22using System;
    2323using System.Drawing;
    2424using System.Linq;
     25using HeuristicLab.Analysis;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
     
    2930  [Item("Histogram", "Represents the histogram grid.")]
    3031  public class HistogramContent : PreprocessingChartContent {
    31 
    3232    public static new Image StaticItemImage {
    3333      get { return HeuristicLab.Common.Resources.VSImageLibrary.Statistics; }
    3434    }
    35     private const int MAX_DISTINCT_VALUES_FOR_CLASSIFCATION = 20;
    3635
    37     private int classifierVariableIndex = 0;
     36    public string GroupingVariableName { get; set; }
    3837
    39     public int ClassifierVariableIndex {
    40       get { return this.classifierVariableIndex; }
    41       set { this.classifierVariableIndex = value; }
    42     }
    43     public bool IsDetailedChartViewEnabled { get; set; }
     38    public int Bins { get; set; }
     39    public bool ExactBins { get; set; }
    4440
     41    public LegendOrder Order { get; set; }
    4542
    4643    public HistogramContent(IFilteredPreprocessingData preprocessingData)
    4744      : base(preprocessingData) {
    48       AllInOneMode = false;
     45      Bins = 10;
     46      ExactBins = false;
    4947    }
    5048
     
    5654    }
    5755
    58     public IEnumerable<string> GetVariableNamesForHistogramClassification() {
    59       List<string> doubleVariableNames = new List<string>();
     56    public static DataTable CreateHistogram(IFilteredPreprocessingData preprocessingData, string variableName, string groupingVariableName, DataTableVisualProperties.DataTableHistogramAggregation aggregation, LegendOrder legendOrder = LegendOrder.Appearance) {
     57      var dataTable = new DataTable {
     58        VisualProperties = { Title = variableName, HistogramAggregation = aggregation },
     59      };
    6060
    61       //only return variable names from type double
    62       for (int i = 0; i < PreprocessingData.Columns; ++i) {
    63         if (PreprocessingData.VariableHasType<double>(i)) {
    64           double distinctValueCount = PreprocessingData.GetValues<double>(i).GroupBy(x => x).Count();
    65           bool distinctValuesOk = distinctValueCount <= MAX_DISTINCT_VALUES_FOR_CLASSIFCATION;
    66           if (distinctValuesOk)
    67             doubleVariableNames.Add(PreprocessingData.GetVariableName(i));
    68         }
     61      if (string.IsNullOrEmpty(groupingVariableName)) {
     62        var row = PreprocessingChartContent.CreateDataRow(preprocessingData, variableName, DataRowVisualProperties.DataRowChartType.Histogram);
     63        row.VisualProperties.IsVisibleInLegend = false;
     64        dataTable.Rows.Add(row);
     65        return dataTable;
    6966      }
    70       return doubleVariableNames;
     67
     68      int variableIndex = preprocessingData.GetColumnIndex(variableName);
     69      var variableValues = preprocessingData.GetValues<double>(variableIndex);
     70      int groupVariableIndex = preprocessingData.GetColumnIndex(groupingVariableName);
     71      var groupingValues = Enumerable.Empty<string>();
     72
     73      if (preprocessingData.VariableHasType<double>(groupVariableIndex)) {
     74        groupingValues = preprocessingData.GetValues<double>(groupVariableIndex).Select(x => x.ToString());
     75      } else if (preprocessingData.VariableHasType<string>(groupVariableIndex)) {
     76        groupingValues = preprocessingData.GetValues<string>(groupVariableIndex);
     77      } else if (preprocessingData.VariableHasType<DateTime>(groupVariableIndex)) {
     78        groupingValues = preprocessingData.GetValues<DateTime>(groupVariableIndex).Select(x => x.ToString());
     79      }
     80
     81      var groups = groupingValues.Zip(variableValues, Tuple.Create).GroupBy(t => t.Item1, t => t.Item2);
     82
     83      if (legendOrder == LegendOrder.Alphabetically)
     84        groups = groups.OrderBy(x => x.Key, new NaturalStringComparer());
     85
     86      foreach (var group in groups) {
     87        var classRow = new DataRow {
     88          Name = group.Key,
     89          VisualProperties = {
     90              ChartType = DataRowVisualProperties.DataRowChartType.Histogram,
     91              IsVisibleInLegend = !string.IsNullOrEmpty(groupingVariableName)
     92            }
     93        };
     94        classRow.Values.AddRange(group);
     95        dataTable.Rows.Add(classRow);
     96      }
     97      return dataTable;
    7198    }
    72 
    7399  }
    74100}
Note: See TracChangeset for help on using the changeset viewer.