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(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 | }
|
---|