private static void LoadDayFile(string fileName) { string date = fileName.Substring(fileName.LastIndexOf(".csv") - 10).Replace(".csv", ""); if (date == "03-22-2020") { postMarch21 = true; } var csv = GetCsvParser(fileName); string[] cols = csv.ReadFields(); var days = new List <string>(cols); days.RemoveRange(0, 4); while (!csv.EndOfData) { string[] fields = csv.ReadFields(); SiteDay siteDay; if (postMarch21) { siteDay = new SiteDay(date, fields[1], fields[2], fields[3], fields[7], fields[8], fields[9]); } else { string cityState = fields[0]; // Skip cruise ship if (cityState.Contains("Diamond Princess")) { continue; } if (!cityState.Contains(",")) { siteDay = new SiteDay(date, "", fields[0], fields[1], fields[3], fields[4], fields[5]); } else { // This is like "Sacremento, California" var cityStateArray = cityState.Split(','); siteDay = new SiteDay(date, cityStateArray[0], StateForCode(cityStateArray[1].Trim()), fields[1], fields[3], fields[4], fields[5]); } } InsertSiteDay(siteDay); } }
private static void InsertSiteDay(SiteDay siteDay) { var country = Countries.Find(x => x.Name == siteDay.Country); if (country == null) { country = new Country(siteDay.Country, "", ""); Countries.Add(country); } // Country if (siteDay.State == "") { country.SiteDays.Add(siteDay); return; } var state = country.States.Find(x => x.Name == siteDay.State); if (state == null) { state = new State(siteDay.State, "", ""); country.States.Add(state); } //if (state.Name == "Sacramento County, CA") // Console.WriteLine("STOP"); // State if (siteDay.City == "") { state.SiteDays.Add(siteDay); return; } var city = state.Cities.Find(x => x.Name == siteDay.City); if (city == null) { city = new City(siteDay.City, "", ""); state.Cities.Add(city); } // City city.SiteDays.Add(siteDay); }