示例#1
0
        private void BuildComparisonResult(DiscrepancyOutputter outputter, out ComparisonResult result)
        {
            result = new ComparisonResult();

            result.discrepancyCount   = outputter.GetDiscrepancyCount();
            result.roundingErrorCount = outputter.GetRoundingErrorCount();

            // Create comment.
            StringBuilder commentBuilder = new StringBuilder();

            if (tableDatas[0].recordCount != tableDatas[1].recordCount || tableDatas[0].columnCount != tableDatas[1].columnCount)
            {
                commentBuilder.Append("Different");
                if (tableDatas[0].recordCount != tableDatas[1].recordCount)
                {
                    commentBuilder.Append(" row");
                    if (tableDatas[0].columnCount != tableDatas[1].columnCount)
                    {
                        commentBuilder.Append(" and");
                    }
                }
                if (tableDatas[0].columnCount != tableDatas[1].columnCount)
                {
                    commentBuilder.Append(" column");
                }
                commentBuilder.Append(" counts.");
            }
            result.comment = commentBuilder.ToString();
        }
示例#2
0
        private DiscrepancyType InitialMatch(TableData[] datas, DiscrepancyOutputter outputter)
        {
            string query = BuildOnlyMatchableRowsQuiery();
            MatchedRecordComparer comparer = new MatchedRecordComparer(data, settings, outputter);
            Recordset             matches  = db.QueryResult(query);
            DiscrepancyType       result   = DiscrepancyType.NONE;

            while (matches.Read())
            {
                string[] matchedRecord    = new string[matches.GetFieldCount() - HASH_FIELDS_COUNT];
                int      nextIndexToWrite = 0;
                for (int i = 0; i < matches.GetFieldCount(); i++)
                {
                    // Skip hash fields.
                    if (i == HASH_FIELD_INDEX || i == datas[0].columnCount + 2)
                    {
                        continue;
                    }

                    matchedRecord[nextIndexToWrite++] = matches.GetString(i);
                }

                string[] first, second;
                ExtractRecords(matchedRecord, datas[0].columnCount + 1, datas[1].columnCount + 1, out first, out second);
                DiscrepancyType type = comparer.Compare(first, second);

                if (type > result)
                {
                    result = type;
                }
            }
            matches.Close();

            return(result);
        }
        public string[][] Match(TableData[] datas, MatchedRecordComparer comparer, DiscrepancyOutputter outputter)
        {
            List <string[]> result = new List <string[]>();

            // Extract nonmatching records.
            Dictionary <string, List <string[]> > firstRecords;
            Dictionary <string, List <string[]> > secondRecords;

            ExtractRecords(out firstRecords, out secondRecords);

            if (firstRecords.Count != 0 || secondRecords.Count != 0)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Warning: Not enough key columns. Experimental algorithm is turned on.");

                Console.WriteLine("First records: ");
                foreach (KeyValuePair <string, List <string[]> > pair in firstRecords)
                {
                    Console.WriteLine("Hash:");
                    foreach (string[] record in pair.Value)
                    {
                        for (int i = 0; i < record.Length; i++)
                        {
                            Console.Write(record[i] + ", ");
                        }
                        Console.WriteLine();
                    }
                }

                Console.WriteLine("Second records: ");
                foreach (KeyValuePair <string, List <string[]> > pair in secondRecords)
                {
                    Console.WriteLine("Hash:");
                    foreach (string[] record in pair.Value)
                    {
                        for (int i = 0; i < record.Length; i++)
                        {
                            Console.Write(record[i] + ", ");
                        }
                        Console.WriteLine();
                    }
                }

                Console.ResetColor();
            }

            foreach (KeyValuePair <string, List <string[]> > pairOne in firstRecords)
            {
                foreach (KeyValuePair <string, List <string[]> > pairTwo in secondRecords)
                {
                    // Comparing records with same hash at the moment.
                    if (pairOne.Key.Equals(pairTwo.Key))
                    {
                        MatchRecords(pairOne.Value.ToArray(), pairTwo.Value.ToArray(), comparer, outputter);
                    }
                }
            }

            return(result.ToArray());
        }
示例#4
0
        private DiscrepancyType AdditionalMatch(TableData[] datas, DiscrepancyOutputter outputter)
        {
            DiscrepancyType result = DiscrepancyType.NONE;

            MatchedRecordComparer          comparer = new MatchedRecordComparer(data, settings, outputter);
            AdditionalSQLHashRecordMatcher matcher  = new AdditionalSQLHashRecordMatcher(srcTables, data, db);

            matcher.Match(datas, comparer, outputter);

            return(result);
        }
示例#5
0
        public MatchedRecordComparer(ComparisonData data, RoundingSettings settings, DiscrepancyOutputter outputter)
        {
            List <int> list = new List <int>();

            foreach (string ignoredColumn in data.ignoredColumns)
            {
                list.Add(XLSXUtils.CellReferenceToColumnIndex(ignoredColumn));
            }
            ignoredColumnIndices = list.ToArray();

            this.settings  = settings;
            this.outputter = outputter;
        }
示例#6
0
        public DiscrepancyType Compare(DiscrepancyOutputter outputter, out ComparisonResult result)
        {
            DiscrepancyType type;

            Extract();

            outputter.Header(tableDatas[0].header);
            type = matcher.Match(tableDatas, outputter);
            outputter.WriteStatistics(tableDatas);

            BuildComparisonResult(outputter, out result);

            return(type);
        }
示例#7
0
        public DiscrepancyType Match(TableData[] datas, DiscrepancyOutputter outputter)
        {
            PrepareTables();

            DiscrepancyType result = DiscrepancyType.NONE;
            DiscrepancyType type;

            type = InitialMatch(datas, outputter);
            if (type > result)
            {
                result = type;
            }

            type = AdditionalMatch(datas, outputter);
            if (type > result)
            {
                result = type;
            }

            return(result);
        }
        private void MatchRecords(string[][] recordSetOne, string[][] recordSetTwo, MatchedRecordComparer comparer, DiscrepancyOutputter outputter)
        {
            HashSet <string> checkedIndices = new HashSet <string>();

            for (int i = 0; i < recordSetOne.Length; i++)
            {
                string[] recordOne = recordSetOne[i];

                string[] bestMatch     = null;
                double   smallestDelta = double.MaxValue;
                for (int j = 0; j < recordSetTwo.Length; j++)
                {
                    string[] recordTwo = recordSetTwo[j];
                    if (checkedIndices.Contains(recordTwo[1]))
                    {
                        continue;
                    }

                    double delta = CalculateGreatestDelta(recordOne, recordTwo);
                    if (delta < smallestDelta)
                    {
                        bestMatch     = recordTwo;
                        smallestDelta = delta;
                    }
                }


                if (bestMatch != null)
                {
                    checkedIndices.Add(bestMatch[1]);

                    string[] recordOneNoHash = RemoveHashFromRecord(recordOne);
                    string[] recordTwoNoHash = RemoveHashFromRecord(bestMatch);

                    int recordColumnCount = Math.Min(recordOneNoHash.Length, recordTwoNoHash.Length);

                    string[] newOne = new string[recordColumnCount];
                    string[] newTwo = new string[recordColumnCount];

                    Array.Copy(recordOneNoHash, newOne, recordColumnCount);
                    Array.Copy(recordTwoNoHash, newTwo, recordColumnCount);

                    comparer.Compare(newOne, newTwo);
                }
            }

            // Print missing.
            for (int i = 0; i < recordSetTwo.Length; i++)
            {
                if (!checkedIndices.Contains(recordSetTwo[i][1]))
                {
                    outputter.MissingRecord(RemoveHashFromRecord(recordSetTwo[i]), 0);
                }
            }

            checkedIndices.Clear();
        }