using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace HeuristicLab.DataPreprocessing { class SearchLogic : ISearchLogic { private readonly IPreprocessingData preprocessingData; public SearchLogic(IPreprocessingData thePreprocessingData) { preprocessingData = thePreprocessingData; } public IDictionary> GetMissingValueIndices() { var dic = new Dictionary>(); foreach (string variableName in preprocessingData.VariableNames) { dic.Add(variableName, GetMissingValueIndices(variableName)); } return dic; } public bool IsMissingValue(string variableName, int rowIndex) { if (preprocessingData.IsType(variableName)) { return double.IsNaN(preprocessingData.GetCell(variableName, rowIndex)); } else if (preprocessingData.IsType(variableName)) { return string.IsNullOrEmpty(preprocessingData.GetCell(variableName, rowIndex)); } else if (preprocessingData.IsType(variableName)) { return preprocessingData.GetCell(variableName, rowIndex).Equals(DateTime.MinValue); } else { throw new ArgumentException("cell in column with variableName: " + variableName + " and row index " + rowIndex + " contains a non supported type."); } } public IEnumerable GetMissingValueIndices(string variableName) { if (preprocessingData.IsType(variableName)) { return preprocessingData.GetValues(variableName).Select((s, i) => new { i, s }).Where(t => double.IsNaN(t.s)).Select(t => t.i); } else if (preprocessingData.IsType(variableName)) { return preprocessingData.GetValues(variableName).Select((s, i) => new { i, s }).Where(t => string.IsNullOrEmpty(t.s)).Select(t => t.i); } else if (preprocessingData.IsType(variableName)) { return preprocessingData.GetValues(variableName).Select((s, i) => new { i, s }).Where(t => t.s.Equals(DateTime.MinValue)).Select(t => t.i); } else { throw new ArgumentException("column with variableName: " + variableName + " contains a non supported type."); } } } }