1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 |
|
---|
6 | namespace 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 | }
|
---|