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"); } }
private static Dictionary <string, LdsInfo> GetLdsInfoDictionary(string zip5, IEnumerable <string> zip4List) { var ldsDictionary = new Dictionary <string, LdsInfo>(); var table = Uszd.GetDataByZip4List(zip5, zip4List, 0); foreach (var row in table) { var stateCode = StateCache.StateCodeFromLdsStateCode(row.LdsStateCode); ldsDictionary[row.Zip4] = new LdsInfo(stateCode, row.Congress, row.StateSenate, row.StateHouse, row.County); } return(ldsDictionary); }
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); }
private void ApplyLdsInfo(IList <StreetAnalysisData> dataList) { if ((dataList == null) || (dataList.Count == 0)) { return; } // This dictionary caches the Zip+4 values var ldsDictionary = new Dictionary <string, LdsInfo>(); // In the first pass we resolve all range values and collect the // single values; foreach (var data in dataList) // We skip all PO BOXes here. They are handled separately { if (data.StreetName != PoBox) { try { ValidatePlus4s(data); if (data.Plus4Low == data.Plus4High) { ldsDictionary[data.Plus4Low] = null; } else { var group = new Dictionary <LdsInfo, object>(); var uszdTable = Uszd.GetDataByZipPlus4Range(data.ZipCode, data.Plus4Low, data.Plus4High, 0); foreach (var uszdRow in uszdTable) { var stateCode = StateCache.StateCodeFromLdsStateCode(uszdRow.LdsStateCode); group[ new LdsInfo(stateCode, uszdRow.Congress, uszdRow.StateSenate, uszdRow.StateHouse, uszdRow.County)] = null; } if (group.Count == 0) { _Statistics.MissingZip4Range++; throw new VoteException( "*{0} missing Lds info range {1}-{2} {1}-{3}", data.UpdateKey, data.ZipCode, data.Plus4Low, data.Plus4High); } if (group.Count > 1) { _Statistics.MultipleZip4Range++; if (data.StreetName == "PO BOX") { throw new VoteException( "{0} multiple PO BOX range {1}-{2} {1}-{3}", data.UpdateKey, data.ZipCode, data.Plus4Low, data.Plus4High); } throw new VoteException( "{0} multiple Lds info range {1}-{2} {1}-{3}", data.UpdateKey, data.ZipCode, data.Plus4Low, data.Plus4High); } data.LdsInfo = group.Keys.Single(); } } catch (VoteException ex) { if (!ex.Message.StartsWith("*")) { ReportError(ex.Message); } data.SetMissingLdsInfo(); } } } // Now we get all the ldsInfos var table = Uszd.GetDataByZip4List(dataList[0].ZipCode, ldsDictionary.Keys, 0); foreach (var row in table) { var stateCode = StateCache.StateCodeFromLdsStateCode(row.LdsStateCode); ldsDictionary[row.Zip4] = new LdsInfo(stateCode, row.Congress, row.StateSenate, row.StateHouse, row.County); } // Finally, we apply the ldsInfos to the non-ranged data items foreach (var data in dataList) { if ((data.StreetName != PoBox) && (data.Plus4Low == data.Plus4High)) { LdsInfo ldsInfo; if (ldsDictionary.TryGetValue(data.Plus4Low, out ldsInfo) && (ldsInfo != null)) { data.LdsInfo = ldsInfo; } else { _Statistics.MissingZip4++; //LogMissingZipPlus4(data.ZipCode, data.Plus4Low); //AppendErrorsText("{0} missing Lds info {1}-{2}", // data.UpdateKey, data.ZipCode, data.Plus4Low); data.SetMissingLdsInfo(); } } } }