コード例 #1
0
        public void DoOneZipCode(string zipCode)
        {
            // Get all zip rows from ZipStreetsDownloaded
            var    isSingle           = false;
            var    found              = false;
            string singleLdsStateCode = null;
            var    streetsTable       = ZipStreetsDownloaded.GetLookupDataByZipCode(zipCode, 0);

            if (streetsTable.Count > 0)
            {
                found = true;

                // Fetch and summarize the USZD data
                var ldsDictionary = new Dictionary <LdsInfo, object>();
// ReSharper disable InconsistentNaming
                var zip4s = CreateZipPlus4List(streetsTable);
// ReSharper restore InconsistentNaming
                var uszdTable = Uszd.GetDataByZip4List(zipCode, zip4s, 0);
                foreach (var row in uszdTable)
                {
                    var stateCode = StateCache.StateCodeFromLdsStateCode(row.LdsStateCode);
                    singleLdsStateCode = row.LdsStateCode;
                    var ldsInfo = new LdsInfo(stateCode, row.Congress, row.StateSenate,
                                              row.StateHouse, row.County);
                    ldsDictionary[ldsInfo] = null;
                }
                if (ldsDictionary.Count == 1)
                {
                    isSingle = true;
                    var singleLdsInfo = ldsDictionary.Keys.Single();
                    //List<string> fields = new List<string>();
                    var csvWriter = new SimpleCsvWriter();
                    //AddField(fields, zipCode);
                    //AddField(fields, singleLdsInfo.Congress.Substring(1));
                    //AddField(fields, singleLdsInfo.StateSenate);
                    //AddField(fields, singleLdsInfo.StateHouse);
                    //AddField(fields, singleLdsStateCode);
                    //AddField(fields, singleLdsInfo.County);
                    //AddField(fields, singleLdsInfo.StateCode);
                    //TextWriter.WriteLine(string.Join(",", fields));
                    csvWriter.AddField(zipCode);
                    csvWriter.AddField(singleLdsInfo.Congress.Substring(1));
                    csvWriter.AddField(singleLdsInfo.StateSenate);
                    csvWriter.AddField(singleLdsInfo.StateHouse);
                    csvWriter.AddField(singleLdsStateCode);
                    csvWriter.AddField(singleLdsInfo.County);
                    csvWriter.AddField(singleLdsInfo.StateCode);
                    csvWriter.Write(_TextWriter);
                }
            }

            if (found)
            {
                Report("{0}: {1}", zipCode, isSingle ? "Single" : "Multiple");
            }
        }
コード例 #2
0
        public bool DoOneZipCode(string zipCode)
        {
            // Get all zip rows from ZipStreetsDownloaded
            var    isSingle           = false;
            var    found              = false;
            string singleLdsStateCode = null;
            var    streetsTable       = ZipStreetsDownloaded.GetLookupDataByZipCode(zipCode, 0);

            if (streetsTable.Count > 0)
            {
                found = true;

                // Fetch and summarize the USZD data
                var ldsDictionary = new Dictionary <LdsInfo, object>();
                var zip4S         = CreateZipPlus4List(streetsTable);
                var uszdTable     = Uszd.GetDataByZip4List(zipCode, zip4S, 0);
                foreach (var row in uszdTable)
                {
                    var stateCode = StateCache.StateCodeFromLdsStateCode(row.LdsStateCode);
                    singleLdsStateCode = row.LdsStateCode;
                    var ldsInfo = new LdsInfo(stateCode, row.Congress, row.StateSenate,
                                              row.StateHouse, row.County);
                    ldsDictionary[ldsInfo] = null;
                }
                if (ldsDictionary.Count == 1)
                {
                    isSingle = true;
                    var singleLdsInfo = ldsDictionary.Keys.Single();
                    if (!_SuppressUpdate)
                    {
                        ZipSingleUszd.Insert(zipCode: zipCode,
                                             congress: singleLdsInfo.Congress.Substring(1),
                                             // LdsInfo padds it to 3
                                             stateSenate: singleLdsInfo.StateSenate,
                                             stateHouse: singleLdsInfo.StateHouse,
                                             ldsStateCode: singleLdsStateCode, county: singleLdsInfo.County,
                                             stateCode: singleLdsInfo.StateCode);
                    }
                }
            }

            if (found)
            {
                Report("{0}: {1}", zipCode, isSingle ? "Single" : "Multiple");
            }

            return(isSingle);
        }
コード例 #3
0
        internal void DoOneZipCode(string zipCode)
        {
            if (!SuppressUpdate && TextWriter == null)
            {
                ZipStreets.DeleteByZipCode(zipCode, 0);
            }

            using (
                var reader = ZipStreetsDownloaded.GetAnalysisDataReaderByZipCode(zipCode, 0)
                )
            {
                var first = true;

                string currentDirectionPrefix = null;
                string currentStreetName      = null;
                string currentStreetSuffix    = null;
                string currentDirectionSuffix = null;

                List <StreetAnalysisData> dataList = null;

                while (reader.Read())
                {
                    if (!StateCache.IsValidStateCode(reader.State))
                    {
                        continue;                       // skip PR etc
                    }
                    if (reader.Plus4Low.EndsWith("ND")) // no delivery
                    {
                        continue;
                    }

                    if (first)
                    {
                        AppendStatusText("{1} Beginning zipCode {0}", zipCode, RowsWritten);
                        first = false;
                    }
                    var directionPrefix = reader.DirectionPrefix;
                    var streetName      = reader.StreetName;
                    var streetSuffix    = reader.StreetSuffix;
                    var directionSuffix = reader.DirectionSuffix;
                    if (directionPrefix != currentDirectionPrefix ||
                        streetName != currentStreetName || streetSuffix != currentStreetSuffix ||
                        directionSuffix != currentDirectionSuffix)
                    {
                        if (dataList != null)
                        {
                            RowsWritten += AnalyzeStreet(dataList);
                        }
                        dataList = new List <StreetAnalysisData>();
                        currentDirectionPrefix = directionPrefix;
                        currentStreetName      = streetName;
                        currentStreetSuffix    = streetSuffix;
                        currentDirectionSuffix = directionSuffix;
                    }
                    if (dataList != null)
                    {
                        dataList.Add(new StreetAnalysisData(reader));
                    }
                }
                if (dataList != null)
                {
                    RowsWritten += AnalyzeStreet(dataList);
                }
            }
        }