Exemple #1
0
        public static void SearchStreetZipCodesFromAPIAndWrite(IStreetLookUp streetlookup, List <StreetLookupInput> textResource, StreamWriter writer, CsvWriter csvWriter)
        {
            Counter = 0;
            StatisticsOfCorrectAddress   statsCorrectAddr       = new StatisticsOfCorrectAddress();
            StatisticsOfIncorrectAddress statsIncorrectAddr     = new StatisticsOfIncorrectAddress();
            Dictionary <AddressCorrectness, Statistics> results = new Dictionary <AddressCorrectness, Statistics>();

            foreach (var data in textResource)
            {
                var states     = streetlookup.GetStatesSearchByStreetAndZip(data.StreetName, data.ZipCode);
                var validation = streetlookup.ValidateStreetAndZip(data.StreetName, data.ZipCode);
                ConsoleStreetPrint.Data(streetlookup.GetNameOfAPI(), validation, states, data.StateCode);
                Counter += 1;
                results  = MatchedStatistic.Calculate(states, data.StateCode, statsCorrectAddr, statsIncorrectAddr, results);
            }
            StatisticsToCsvFile.Write(streetlookup.GetNameOfAPI(), results, writer, csvWriter);
        }
        public static Dictionary <AddressCorrectness, Statistics> Calculate(List <string> states, string correctState, StatisticsOfCorrectAddress statsCorrectAddr,
                                                                            StatisticsOfIncorrectAddress statsIncorrectAddr, Dictionary <AddressCorrectness, Statistics> results)

        {
            if (TestRunner.Counter <= 70)
            {
                results[AddressCorrectness.Correct] = AnaylyzeForCorrectAddress(states, correctState, statsCorrectAddr);
            }
            if (TestRunner.Counter >= 70)
            {
                results[AddressCorrectness.Incorrect] = AnaylyzeForIncorrectAddress(states, correctState, statsIncorrectAddr);
            }
            return(results);
        }
        private static StatisticsOfCorrectAddress AnaylyzeForCorrectAddress(List <string> states, string correctState, StatisticsOfCorrectAddress statsCorrectAddr)

        {
            if (states.Contains(correctState))
            {
                statsCorrectAddr.NumberOfMatched += 1;
            }
            statsCorrectAddr.PercentageOfMatched = (statsCorrectAddr.NumberOfMatched / 70) * 100;
            return(statsCorrectAddr);
        }