Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 10240 was 10236, checked in by sbreuer, 11 years ago
  • moved missing value functionality to ISearchLogic
  • created IStringConvertibleMatrix implementation and DataGridContentView
File size: 2.3 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(variableName));
18      }
19      return dic;
20    }
21
22    public bool IsMissingValue(string variableName, int rowIndex) {
23      if (preprocessingData.IsType<double>(variableName)) {
24        return double.IsNaN(preprocessingData.GetCell<double>(variableName, rowIndex));
25      } else if (preprocessingData.IsType<string>(variableName)) {
26        return string.IsNullOrEmpty(preprocessingData.GetCell<string>(variableName, rowIndex));
27      } else if (preprocessingData.IsType<DateTime>(variableName)) {
28        return preprocessingData.GetCell<DateTime>(variableName, rowIndex).Equals(DateTime.MinValue);
29      } else {
30        throw new ArgumentException("cell in column with variableName: " + variableName + " and row index " + rowIndex + " contains a non supported type.");
31      }
32    }
33
34    public IEnumerable<int> GetMissingValueIndices(string variableName) {
35      if (preprocessingData.IsType<double>(variableName)) {
36        return preprocessingData.GetValues<double>(variableName).Select((s, i) => new { i, s }).Where(t => double.IsNaN(t.s)).Select(t => t.i);
37      } else if (preprocessingData.IsType<string>(variableName)) {
38        return preprocessingData.GetValues<string>(variableName).Select((s, i) => new { i, s }).Where(t => string.IsNullOrEmpty(t.s)).Select(t => t.i);
39      } else if (preprocessingData.IsType<DateTime>(variableName)) {
40        return preprocessingData.GetValues<DateTime>(variableName).Select((s, i) => new { i, s }).Where(t => t.s.Equals(DateTime.MinValue)).Select(t => t.i);
41      } else {
42        throw new ArgumentException("column with variableName: " + variableName + " contains a non supported type.");
43      }
44    }
45
46  }
47}
Note: See TracBrowser for help on using the repository browser.