Exemple #1
0
        public static List <ResultRow> FindDuplicates(List <ResultRow> originalResults)
        {
            if (originalResults == null || originalResults.Count < 2)
            {
                return(originalResults);
            }

            List <ResultRow> duplicateRows = new List <ResultRow>();

            int       lastRowAdded = -1;
            int       i            = 1;
            ResultRow previousRow  = originalResults[0];

            while (i < originalResults.Count)
            {
                ResultRow currentRow = originalResults[i];
                if (previousRow.Location.Equals(currentRow.Location) &&
                    previousRow.PerformanceDate.Equals(currentRow.PerformanceDate))
                {
                    if (lastRowAdded != i - 1)
                    {
                        duplicateRows.Add(previousRow);
                    }

                    duplicateRows.Add(currentRow);
                    lastRowAdded = i;
                }

                previousRow = currentRow;
                i++;
            }

            return(duplicateRows);
        }
Exemple #2
0
        public static Tuple <List <ResultRow>, List <string> > MapSourceRowsToTargetRows(
            List <string> listVersions,
            Dictionary <string, Dictionary <DateTime, string> > versionMapping,
            List <string> versionColumnsPresent,
            List <SourceRow> sourceRows)
        {
            // Convert source rows to target rows
            Dictionary <uint, List <ResultRow> > resultRowsByCustomerId = new Dictionary <uint, List <ResultRow> >(sourceRows.Count);

            foreach (SourceRow sourceRow in sourceRows)
            {
                List <ResultRow> resultRowsPerCustomer;
                if (!resultRowsByCustomerId.TryGetValue(sourceRow.CustomerNumber, out resultRowsPerCustomer))
                {
                    resultRowsPerCustomer = new List <ResultRow>(1);
                    resultRowsByCustomerId.Add(sourceRow.CustomerNumber, resultRowsPerCustomer);
                }

                ResultRow resultRow = new ResultRow
                {
                    CustomerNumber      = sourceRow.CustomerNumber,
                    PerformanceFullDate = sourceRow.PerformanceDate,
                    PerformanceDate     = sourceRow.PerformanceDate.ToString("MM/dd")
                };

                string version = CsvParsingHelper.DetermineVersion(
                    sourceRow.CustomerNumber,
                    !string.IsNullOrEmpty(sourceRow.List1),
                    !string.IsNullOrEmpty(sourceRow.List2),
                    !string.IsNullOrEmpty(sourceRow.List3),
                    !string.IsNullOrEmpty(sourceRow.List4),
                    !string.IsNullOrEmpty(sourceRow.List5),
                    listVersions);

                resultRow.Version = version;

                if (versionMapping != null &&
                    versionMapping.TryGetValue(version, out Dictionary <DateTime, string> dateMapping) &&
                    dateMapping.TryGetValue(resultRow.PerformanceFullDate, out string mappedValue))
                {
                    resultRow[version] = mappedValue;
                }

                resultRow.YearsSubscribed  = sourceRow.YearsSubscribed;
                resultRow.LetterSalutation = sourceRow.LetterSalutation;
                resultRow.FullName         = CsvParsingHelper.ConstructFullName(sourceRow.FirstName, sourceRow.LastName);
                CsvParsingHelper.DetermineLocation(sourceRow, resultRow);

                resultRowsPerCustomer.Add(resultRow);
            }

            List <ResultRow> resultRows = new List <ResultRow>(resultRowsByCustomerId.Count);

            foreach (List <ResultRow> resultRowsPerCustomer in resultRowsByCustomerId.Values)
            {
                resultRowsPerCustomer.Sort(new ResultRowImportanceComparer());
                resultRows.Add(resultRowsPerCustomer[0]);
            }

            resultRows.Sort(new ResultRowLocationComparer());

            // Output target rows into a new CSV
            List <string> targetRows;

            if (versionColumnsPresent != null)
            {
                targetRows = new List <string>(ResultRow.BaseRows.Count + versionColumnsPresent.Count);
                targetRows.AddRange(ResultRow.BaseRows);
                targetRows.AddRange(versionColumnsPresent);
            }
            else
            {
                targetRows = ResultRow.BaseRows;
            }

            return(new Tuple <List <ResultRow>, List <string> >(resultRows, targetRows));
        }
Exemple #3
0
        private static void DetermineLocation(SourceRow sourceRow, ResultRow resultRow)
        {
            if (string.IsNullOrEmpty(sourceRow.Section) ||
                string.IsNullOrEmpty(sourceRow.Location))
            {
                resultRow.Level    = CsvParsingHelper.ErrorString;
                resultRow.Location = CsvParsingHelper.ErrorString + sourceRow.Location;
                return;
            }

            Match sectionMatch = CsvParsingHelper.sourceSectionParser.Match(sourceRow.Section);

            if (!sectionMatch.Success)
            {
                throw new SeatcardSorterException($"Couldn't parse section for customer_no {sourceRow.CustomerNumber}");
            }

            MatchCollection locationMatches = CsvParsingHelper.sourceLocationParser.Matches(sourceRow.Location);

            if (locationMatches.Count < 1)
            {
                throw new SeatcardSorterException($"Couldn't parse location for customer_no {sourceRow.CustomerNumber}");
            }

            string sectionLevel = sectionMatch.Groups[1].Value;

            resultRow.Section = sectionMatch.Groups[3].Value;

            if (locationMatches.Count > 2)
            {
                resultRow.Level    = CsvParsingHelper.ErrorString;
                resultRow.Location = CsvParsingHelper.ErrorString + sourceRow.Location;
                return;
            }

            if (locationMatches.Count == 1)
            {
                Match  locationMatch = locationMatches[0];
                string locationLevel = locationMatch.Groups[2].Value;
                string row           = locationMatch.Groups[4].Value;
                string seat          = locationMatch.Groups[5].Value;
                if (!uint.TryParse(seat, out uint seatNumber))
                {
                    throw new SeatcardSorterException($"Couldn't parse location seat number for customer_no {sourceRow.CustomerNumber}");
                }

                if (!CsvParsingHelper.LevelsMatch(locationLevel, sectionLevel))
                {
                    resultRow.Level    = CsvParsingHelper.ErrorString;
                    resultRow.Location = CsvParsingHelper.ErrorString + sourceRow.Location;
                }
                else
                {
                    resultRow.Level      = locationLevel;
                    resultRow.Row        = row;
                    resultRow.SeatNumber = seatNumber;

                    resultRow.Location = CsvParsingHelper.GenerateLocation(resultRow.Level, resultRow.Section, resultRow.Row, resultRow.SeatNumber);
                }
            }
            else // if (locationMatches.Count == 2)
            {
                Match firstLocationMatch  = locationMatches[0];
                Match secondLocationMatch = locationMatches[1];

                string firstLocationLevel  = firstLocationMatch.Groups[2].Value;
                string secondLocationLevel = secondLocationMatch.Groups[2].Value;

                char firstAisle      = firstLocationMatch.Groups[3].Value[0];
                char secondAisle     = secondLocationMatch.Groups[3].Value[0];
                int  aisleDifference = firstAisle - secondAisle;
                if (!string.Equals(firstLocationLevel, secondLocationLevel) ||
                    !CsvParsingHelper.LevelsMatch(firstLocationLevel, sectionLevel) ||
                    aisleDifference < -1 ||
                    aisleDifference > 1)
                {
                    resultRow.Level    = CsvParsingHelper.ErrorString;
                    resultRow.Location = CsvParsingHelper.ErrorString + sourceRow.Location;
                }
                else
                {
                    string row  = firstLocationMatch.Groups[4].Value;
                    string seat = firstLocationMatch.Groups[5].Value;
                    uint   seatNumber;
                    if (!uint.TryParse(seat, out seatNumber))
                    {
                        throw new SeatcardSorterException($"Couldn't parse location seat number for customer_no {sourceRow.CustomerNumber}");
                    }

                    resultRow.Level      = firstLocationLevel;
                    resultRow.Row        = row;
                    resultRow.SeatNumber = seatNumber;
                    resultRow.Location   = CsvParsingHelper.GenerateLocation(resultRow.Level, resultRow.Section, resultRow.Row, resultRow.SeatNumber);
                }
            }
        }