Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 10615 was 10586, checked in by tsteinre, 11 years ago
  • divided/refactored PreprocessingData into TransactionalPreprocessingData and preprocessingData
File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25
26namespace HeuristicLab.DataPreprocessing {
27  public class SearchLogic : ISearchLogic {
28    private readonly ITransactionalPreprocessingData preprocessingData;
29
30    public SearchLogic(ITransactionalPreprocessingData thePreprocessingData) {
31      preprocessingData = thePreprocessingData;
32    }
33
34    public IDictionary<string, IEnumerable<int>> GetMissingValueIndices() {
35      var dic = new Dictionary<string, IEnumerable<int>>();
36      foreach (string variableName in preprocessingData.VariableNames) {
37        dic.Add(variableName, GetMissingValueIndices(preprocessingData.GetColumnIndex(variableName)));
38      }
39      return dic;
40    }
41
42    public bool IsMissingValue(int columnIndex, int rowIndex) {
43      if (preprocessingData.IsType<double>(columnIndex)) {
44        return double.IsNaN(preprocessingData.GetCell<double>(columnIndex, rowIndex));
45      } else if (preprocessingData.IsType<string>(columnIndex)) {
46        return string.IsNullOrEmpty(preprocessingData.GetCell<string>(columnIndex, rowIndex));
47      } else if (preprocessingData.IsType<DateTime>(columnIndex)) {
48        return preprocessingData.GetCell<DateTime>(columnIndex, rowIndex).Equals(DateTime.MinValue);
49      } else {
50        throw new ArgumentException("cell in column " + columnIndex + " and row index " + rowIndex + " contains a non supported type.");
51      }
52    }
53
54    public IEnumerable<int> GetMissingValueIndices(int columnIndex) {
55      if (preprocessingData.IsType<double>(columnIndex)) {
56        return preprocessingData.GetValues<double>(columnIndex).Select((s, i) => new { i, s }).Where(t => double.IsNaN(t.s)).Select(t => t.i);
57      } else if (preprocessingData.IsType<string>(columnIndex)) {
58        return preprocessingData.GetValues<string>(columnIndex).Select((s, i) => new { i, s }).Where(t => string.IsNullOrEmpty(t.s)).Select(t => t.i);
59      } else if (preprocessingData.IsType<DateTime>(columnIndex)) {
60        return preprocessingData.GetValues<DateTime>(columnIndex).Select((s, i) => new { i, s }).Where(t => t.s.Equals(DateTime.MinValue)).Select(t => t.i);
61      } else {
62        throw new ArgumentException("column " + columnIndex + " contains a non supported type.");
63      }
64    }
65
66  }
67}
Note: See TracBrowser for help on using the repository browser.