Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/SearchLogic.cs @ 10367

Last change on this file since 10367 was 10367, checked in by rstoll, 11 years ago
  • modified PreprocessingData, uses columnIndex now instead of variableName (is faster and more convenient), set variabelName based methods to Obsolete
  • Already changed SearchLogic, DataGridLogic, StatisticLogic as well as PreprocessingDataManipulation

*

File size: 2.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6namespace HeuristicLab.DataPreprocessing {
7  class SearchLogic : ISearchLogic {
8    private readonly IPreprocessingData preprocessingData;
9
10    public SearchLogic(IPreprocessingData thePreprocessingData) {
11      preprocessingData = thePreprocessingData;
12    }
13
14    public IDictionary<string, IEnumerable<int>> GetMissingValueIndices() {
15      var dic = new Dictionary<string, IEnumerable<int>>();
16      foreach (string variableName in preprocessingData.VariableNames) {
17        dic.Add(variableName, GetMissingValueIndices(preprocessingData.GetColumnIndex(variableName)));
18      }
19      return dic;
20    }
21
22    public bool IsMissingValue(int columnIndex, int rowIndex) {
23      if (preprocessingData.IsType<double>(columnIndex)) {
24        return double.IsNaN(preprocessingData.GetCell<double>(columnIndex, rowIndex));
25      } else if (preprocessingData.IsType<string>(columnIndex)) {
26        return string.IsNullOrEmpty(preprocessingData.GetCell<string>(columnIndex, rowIndex));
27      } else if (preprocessingData.IsType<DateTime>(columnIndex)) {
28        return preprocessingData.GetCell<DateTime>(columnIndex, rowIndex).Equals(DateTime.MinValue);
29      } else {
30        throw new ArgumentException("cell in column " + columnIndex + " and row index " + rowIndex + " contains a non supported type.");
31      }
32    }
33
34    public IEnumerable<int> GetMissingValueIndices(int columnIndex) {
35      if (preprocessingData.IsType<double>(columnIndex)) {
36        return preprocessingData.GetValues<double>(columnIndex).Select((s, i) => new { i, s }).Where(t => double.IsNaN(t.s)).Select(t => t.i);
37      } else if (preprocessingData.IsType<string>(columnIndex)) {
38        return preprocessingData.GetValues<string>(columnIndex).Select((s, i) => new { i, s }).Where(t => string.IsNullOrEmpty(t.s)).Select(t => t.i);
39      } else if (preprocessingData.IsType<DateTime>(columnIndex)) {
40        return preprocessingData.GetValues<DateTime>(columnIndex).Select((s, i) => new { i, s }).Where(t => t.s.Equals(DateTime.MinValue)).Select(t => t.i);
41      } else {
42        throw new ArgumentException("column " + columnIndex + " contains a non supported type.");
43      }
44    }
45
46  }
47}
Note: See TracBrowser for help on using the repository browser.