public void MatchRow(object[] previousRowData, object[] updatedRowData, ColumnComparer[] comparers)
        {
            int defLength = DataDefinition.Length;

            for (int updatedI = 0; updatedI <= updatedRowData.Length - defLength; ++updatedI)
            {
                int matches = 0;

                for (int i = 0; i < defLength; ++i)
                {
                    int prevColumn = i + DataDefinition.Index;
                    int upColumn   = updatedI + i;

                    if (prevColumn >= comparers.Length)
                    {
                        continue; // Not compatible, index out of bounds.
                    }
                    ColumnComparer comparer = comparers[prevColumn];
                    if (comparer == null || !comparer.IsCompatibleIndex(upColumn))
                    {
                        continue; // Not compatible.
                    }
                    object prevVal = previousRowData[prevColumn];
                    object upVal   = updatedRowData[upColumn];

                    if (comparer.Compare(prevVal, upVal))
                    {
                        ++matches;
                    }
                }

                if (matches <= 0)
                {
                    continue;
                }

                double c = matches / (double)defLength;
                if (!_IndexMatchConfidence.ContainsKey(updatedI))
                {
                    _IndexMatchConfidence.Add(updatedI, new List <double>());
                }
                _IndexMatchConfidence[updatedI].Add(c);
            }

            ++_RowMatchCount;
        }
Esempio n. 2
0
        private IEnumerable <DefinitionUpdater> MatchRows()
        {
            var defUpdaters =
                _PreviousDefinition.DataDefinitions.Select(_ => new DefinitionUpdater(_PreviousDefinition, _)).ToArray();

            // Record a list of compatible indexes by previous sheet column.
            // These are the only columns to be tested.
            var comparers = _PreviousSheet.Header.Columns
                            .Select(c => ColumnComparer.Create(c, _UpdatedSheet.Header.Columns))
                            .ToArray();

            if (_PreviousSheet.Header.Variant == 2)
            {
                return(MatchVariant2Rows(defUpdaters, comparers));
            }

            foreach (IRow prevRow in _PreviousSheet)
            {
                if (!_UpdatedSheet.ContainsRow(prevRow.Key))
                {
                    continue;
                }

                var prevRowFields =
                    _PreviousSheet.Header.Columns.OrderBy(_ => _.Index).Select(_ => prevRow[_.Index]).ToArray();
                var updatedRow       = _UpdatedSheet[prevRow.Key];
                var updatedRowFields =
                    _UpdatedSheet.Header.Columns.OrderBy(_ => _.Index).Select(_ => updatedRow[_.Index]).ToArray();

                foreach (var def in defUpdaters)
                {
                    def.MatchRow(prevRowFields, updatedRowFields, comparers);
                }
            }

            return(defUpdaters);
        }