예제 #1
0
        public ParseErrors AddSheets(DataSheetCollection dataSheets, ColumnInfoCache columnInfos, string filter)
        {
            _importer.AddFromFile(_configuration.Format, dataSheets.Filter(filter), columnInfos, this);
            if (NanSettings == null || !double.TryParse(NanSettings.Indicator, out var indicator))
            {
                indicator = double.NaN;
            }
            var errors = new ParseErrors();

            foreach (var dataSet in DataSets.KeyValues)
            {
                if (NanSettings != null && NanSettings.Action == NanSettings.ActionType.Throw)
                {
                    if (dataSet.Value.NanValuesExist(indicator))
                    {
                        errors.Add(dataSet.Value, new NaNParseErrorDescription());
                    }
                }
                else
                {
                    dataSet.Value.ClearNan(indicator);
                    var emptyDataSets = dataSet.Value.Data.Where(parsedDataSet => parsedDataSet.Data.All(column => column.Value.Count == 0)).ToList();
                    if (emptyDataSets.Count == 0)
                    {
                        continue;
                    }

                    var emptyDataSetsNames = emptyDataSets.Select(d => string.Join(".", d.Description.Where(metaData => metaData.Value != null).Select(metaData => metaData.Value)));
                    errors.Add(dataSet.Value, new EmptyDataSetsParseErrorDescription(emptyDataSetsNames));
                }
            }
            return(errors);
        }
예제 #2
0
        //checks that all units coming from a mapped column unit belong to a valid dimension for this mapping
        //and also that they are all of the same dimension within every data set.
        private ParseErrors validateUnitsSupportedAndSameDimension(Cache <string, ColumnInfo> columnInfos)
        {
            var errors = new ParseErrors();

            foreach (var columnInfo in columnInfos)
            {
                foreach (var dataSet in DataSets)
                {
                    foreach (var set in dataSet.Data)
                    {
                        var column = set.Data.FirstOrDefault(x => x.Key.ColumnInfo.Name == columnInfo.Name);

                        if (column.Key == null || column.Key.ErrorDeviation == Constants.STD_DEV_GEOMETRIC)
                        {
                            continue;
                        }

                        //if unit comes from a column
                        if (column.Key.Column.Dimension == null)
                        {
                            var firstNonEmptyUnit = column.Value.FirstOrDefault(x => !string.IsNullOrEmpty(x.Unit));

                            var dimensionOfFirstUnit = columnInfo.SupportedDimensions.FirstOrDefault(x => x.FindUnit(firstNonEmptyUnit.Unit, ignoreCase: true) != null);

                            for (var i = 0; i < column.Value.Count(); i++)
                            {
                                var currentValue = column.Value.ElementAt(i);
                                if (double.IsNaN(currentValue.Measurement))
                                {
                                    continue;
                                }

                                var dimension = columnInfo.SupportedDimensions.FirstOrDefault(x => x.FindUnit(currentValue.Unit, ignoreCase: true) != null);

                                //if the unit specified does not belong to one of the supported dimensions of the mapping
                                if (dimension == null)
                                {
                                    errors.Add(dataSet, new InvalidDimensionParseErrorDescription(currentValue.Unit, columnInfo.DisplayName));
                                    continue;
                                }

                                //if the unit specified is not of the same dimension as the other units of the same data set
                                if (dimension != dimensionOfFirstUnit)
                                {
                                    errors.Add(dataSet, new InconsistentDimensionBetweenUnitsParseErrorDescription(columnInfo.DisplayName));
                                    continue;
                                }
                            }
                        }
                    }
                }
            }
            return(errors);
        }
예제 #3
0
        //checks that the dimension of all the units coming from columns for error have the same dimension to the corresponding measurement
        private ParseErrors validateErrorAgainstMeasurement(ColumnInfoCache columnInfos)
        {
            var errors = new ParseErrors();

            foreach (var column in columnInfos.Where(c => !c.IsAuxiliary))
            {
                foreach (var relatedColumn in columnInfos.RelatedColumnsFrom(column.Name))
                {
                    foreach (var dataSet in DataSets)
                    {
                        foreach (var set in dataSet.Data)
                        {
                            var measurementColumn = set.Data.FirstOrDefault(x => x.Key.ColumnInfo.Name == column.Name);
                            var errorColumn       = set.Data.FirstOrDefault(x => x.Key.ColumnInfo.Name == relatedColumn.Name);
                            if (errorColumn.Key == null || errorColumn.Key.ErrorDeviation == Constants.STD_DEV_GEOMETRIC)
                            {
                                continue;
                            }

                            if (errorColumn.Value != null && measurementColumn.Value.Count != errorColumn.Value.Count)
                            {
                                errors.Add(dataSet, new MismatchingArrayLengthsParseErrorDescription());
                                continue;
                            }

                            var errorDimension       = errorColumn.Key.Column.Dimension;
                            var measurementDimension = measurementColumn.Key.Column.Dimension;

                            if (errorDimension == null)
                            {
                                for (var i = 0; i < measurementColumn.Value.Count(); i++)
                                {
                                    if (double.IsNaN(errorColumn.Value.ElementAt(i).Measurement))
                                    {
                                        continue;
                                    }

                                    var measurementSupportedDimension = column.SupportedDimensions.FirstOrDefault(x => x.HasUnit(measurementColumn.Value.ElementAt(i).Unit));
                                    var errorSupportedDimension       = column.SupportedDimensions.FirstOrDefault(x => x.HasUnit(errorColumn.Value.ElementAt(i).Unit));
                                    if (measurementSupportedDimension != errorSupportedDimension)
                                    {
                                        errors.Add(dataSet, new ErrorUnitParseErrorDescription());
                                        continue;
                                    }
                                }
                            }
                            else
                            {
                                //if the dimension of the error is dimensionless (fe for geometric standard deviation)
                                //it is OK for it not to be of the smae dimension as the dimension of the measurement
                                if (errorDimension == Constants.Dimension.NO_DIMENSION ||
                                    errorDimension.Name == Constants.Dimension.FRACTION)
                                {
                                    continue;
                                }

                                if (measurementDimension != errorDimension)
                                {
                                    errors.Add(dataSet, new ErrorUnitParseErrorDescription());
                                    continue;
                                }
                            }
                        }
                    }
                }
            }
            return(errors);
        }