/// <summary> /// Return a list of field names that this definition will read from the data table. /// </summary> /// <param name="fieldsThatExist"></param> /// <returns></returns> public List <string> GetFieldNames(List <string> fieldsThatExist) { var filter = GetFilter(fieldsThatExist); var fieldsToRead = new List <string>(); fieldsToRead.Add(XFieldName); fieldsToRead.Add(YFieldName); if (!string.IsNullOrEmpty(X2FieldName)) { fieldsToRead.Add(X2FieldName); } if (!string.IsNullOrEmpty(Y2FieldName)) { fieldsToRead.Add(Y2FieldName); } var fieldsToAdd = new List <string>(); foreach (var fieldName in fieldsToRead) { if (fieldsThatExist.Contains(fieldName + "Error")) { fieldsToAdd.Add(fieldName + "Error"); } } fieldsToRead.AddRange(fieldsToAdd); // Add any field names from the filter. fieldsToRead.AddRange(ExtractFieldNamesFromFilter(filter)); // Add any fields from child graphable models. foreach (IGraphable series in Series.FindAllChildren <IGraphable>()) { fieldsToRead.AddRange(series.GetExtraFieldsToRead(this)); } return(fieldsToRead); }
/// <summary>Reads all data from the specified reader.</summary> /// <param name="reader">Storage reader.</param> /// <param name="simulationDescriptions">Complete list of simulation descriptions.</param> public void ReadData(IStorageReader reader, List <SimulationDescription> simulationDescriptions) { if (X != null && Y != null) { return; } if (series.TableName == null) { if (!String.IsNullOrEmpty(XFieldName)) { X = GetDataFromModels(XFieldName); } if (!String.IsNullOrEmpty(YFieldName)) { Y = GetDataFromModels(YFieldName); } if (!String.IsNullOrEmpty(X2FieldName)) { X2 = GetDataFromModels(X2FieldName); } if (!String.IsNullOrEmpty(Y2FieldName)) { Y2 = GetDataFromModels(Y2FieldName); } } else { var fieldsThatExist = reader.ColumnNames(series.TableName); // If we have descriptors, then use them to filter the data for this series. List <string> simulationNameFilter = new List <string>();; IEnumerable <SimulationDescription> simulationNamesWithDescriptors = new List <SimulationDescription>(); string filter = null; if (Descriptors != null) { foreach (var descriptor in Descriptors) { if (fieldsThatExist.Contains(descriptor.Name)) { filter = AddToFilter(filter, $"[{descriptor.Name}] = '{descriptor.Value}'"); } else { if (simulationNamesWithDescriptors.Any()) { simulationNamesWithDescriptors = simulationNamesWithDescriptors.Where(s => s.HasDescriptor(descriptor)); } else { simulationNamesWithDescriptors = simulationDescriptions.Where(sim => sim.HasDescriptor(descriptor)); } } } if (simulationNamesWithDescriptors.Any()) { simulationNameFilter = simulationNamesWithDescriptors.Select(s => s.Name).ToList(); } // Incorporate our scope filter if we haven't limited filter to particular simulations. if (!simulationNameFilter.Any() && inScopeSimulationNames != null) { simulationNameFilter = new List <string>(inScopeSimulationNames); } } else if (inScopeSimulationNames != null) { simulationNameFilter = new List <string>(inScopeSimulationNames ?? Enumerable.Empty <string>()); } if (!string.IsNullOrEmpty(userFilter)) { filter = AddToFilter(filter, userFilter); } // Get a list of fields to read from data store. var fieldsToRead = new List <string>(); fieldsToRead.Add(XFieldName); fieldsToRead.Add(YFieldName); if (X2FieldName != null) { fieldsToRead.Add(X2FieldName); } if (Y2FieldName != null) { fieldsToRead.Add(Y2FieldName); } // Add any error fields to the list of fields to read. var fieldsToAdd = new List <string>(); foreach (var fieldName in fieldsToRead) { if (fieldsThatExist.Contains(fieldName + "Error")) { fieldsToAdd.Add(fieldName + "Error"); } } fieldsToRead.AddRange(fieldsToAdd); // Add any field names from the filter. fieldsToRead.AddRange(ExtractFieldNamesFromFilter(filter)); // Add any fields from child graphable models. foreach (IGraphable series in series.FindAllChildren <IGraphable>()) { fieldsToRead.AddRange(series.GetExtraFieldsToRead(this)); } // Checkpoints don't exist in observed files so don't pass a checkpoint name to // GetData in this situation. string localCheckpointName = CheckpointName; if (!reader.ColumnNames(series.TableName).Contains("CheckpointID")) { localCheckpointName = null; } // Go get the data. Data = reader.GetData(series.TableName, localCheckpointName, simulationNameFilter, fieldNames: fieldsToRead.Distinct(), filter: filter); // Get the units for our x and y variables. XFieldUnits = reader.Units(series.TableName, XFieldName); YFieldUnits = reader.Units(series.TableName, YFieldName); // If data was found, populate our data (e.g. X and Y) properties. if (Data?.Rows.Count > 0) { X = GetDataFromTable(Data, XFieldName); Y = GetDataFromTable(Data, YFieldName); X2 = GetDataFromTable(Data, X2FieldName); Y2 = GetDataFromTable(Data, Y2FieldName); XError = GetErrorDataFromTable(Data, XFieldName); YError = GetErrorDataFromTable(Data, YFieldName); if (series.Cumulative) { Y = MathUtilities.Cumulative(Y as IEnumerable <double>); } if (series.CumulativeX) { X = MathUtilities.Cumulative(X as IEnumerable <double>); } } } }