Esempio n. 1
0
        /// <summary>Reads all data from the specified reader.</summary>
        /// <param name="data">Data to read from.</param>
        /// <param name="simulationDescriptions">Complete list of simulation descriptions.</param>
        /// <param name="reader">Data store reader.</param>
        public void ReadData(DataTable data, List <SimulationDescription> simulationDescriptions, IStorageReader reader)
        {
            if (X != null && Y != null)
            {
                return;
            }

            if (Series.TableName == null)
            {
                GetDataFromModels();
            }
            else
            {
                var fieldsThatExist = DataTableUtilities.GetColumnNames(data).ToList();

                // 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>();
                if (Descriptors != null)
                {
                    foreach (var descriptor in Descriptors)
                    {
                        if (!fieldsThatExist.Contains(descriptor.Name))
                        {
                            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>());
                }

                string filter = GetFilter(fieldsThatExist);

                if (simulationNameFilter.Any())
                {
                    var simulationIds    = reader.ToSimulationIDs(simulationNameFilter);
                    var simulationIdsCSV = StringUtilities.Build(simulationIds, ",");
                    if (fieldsThatExist.Contains("SimulationID"))
                    {
                        filter = AddToFilter(filter, $"SimulationID in ({simulationIdsCSV})");
                    }
                }

                filter         = filter?.Replace('\"', '\'');
                View           = new DataView(data);
                View.RowFilter = 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 (View?.Count > 0)
                {
                    X      = GetDataFromView(View, XFieldName);
                    Y      = GetDataFromView(View, YFieldName);
                    X2     = GetDataFromView(View, X2FieldName);
                    Y2     = GetDataFromView(View, Y2FieldName);
                    XError = GetErrorDataFromView(View, XFieldName);
                    YError = GetErrorDataFromView(View, YFieldName);
                    if (Series.Cumulative)
                    {
                        Y = MathUtilities.Cumulative(Y as IEnumerable <double>);
                    }
                    if (Series.CumulativeX)
                    {
                        X = MathUtilities.Cumulative(X as IEnumerable <double>);
                    }
                }
            }
        }