Last active
March 16, 2020 02:29
-
-
Save kamermans/397488317c75b23414100d7e1316e96f to your computer and use it in GitHub Desktop.
COVID-19 Confirmed Cases by US County (from John's Hopkins Dataset)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # COVID-19 by US County | |
| Missouri (2): | |
| St. Louis: 2 | |
| Vermont (2): | |
| Bennington: 2 | |
| Illinois (112): | |
| Cook: 112 | |
| Arizona (57): | |
| Maricopa: 51 | |
| Pinal: 6 | |
| Nevada (13): | |
| Clark: 7 | |
| Washoe: 6 | |
| Indiana (7): | |
| Marion: 4 | |
| Hendricks: 3 | |
| Rhode Island (20): | |
| Providence: 20 | |
| District of Columbia (4): | |
| District of Columbia: 4 | |
| Washington (656): | |
| Grant: 5 | |
| Chelan: 20 | |
| Pierce: 9 | |
| King: 465 | |
| Snohomish: 147 | |
| Kittitas: 2 | |
| Spokane: 2 | |
| Clark: 3 | |
| Jefferson: 3 | |
| California (740): | |
| San Benito: 72 | |
| Orange: 57 | |
| Santa Clara: 240 | |
| Shasta: 1 | |
| San Diego: 59 | |
| Humboldt: 18 | |
| San Mateo: 15 | |
| Contra Costa: 32 | |
| Riverside: 2 | |
| Solano: 15 | |
| Sonoma: 10 | |
| San Francisco: 31 | |
| Alameda: 10 | |
| Fresno: 2 | |
| Los Angeles: 111 | |
| Sacramento: 30 | |
| Placer: 28 | |
| Yolo: 4 | |
| Madera: 3 | |
| Louisiana (1): | |
| Jefferson: 1 | |
| Maryland (16): | |
| Montgomery: 14 | |
| Harford: 2 | |
| Kentucky (7): | |
| Fayette: 4 | |
| Harrison: 2 | |
| Jefferson: 1 | |
| Wisconsin (34): | |
| Dane: 34 | |
| Texas (71): | |
| Collin: 1 | |
| Bexar: 32 | |
| Harris: 21 | |
| Fort Bend: 17 | |
| Montgomery: 0 | |
| Georgia (30): | |
| Fulton: 19 | |
| Cobb: 5 | |
| Polk: 5 | |
| Cherokee: 1 | |
| Tennessee (9): | |
| Williamson: 5 | |
| Davidson: 2 | |
| Shelby: 2 | |
| South Carolina (10): | |
| Spartanburg: 1 | |
| Charleston: 3 | |
| Kershaw: 6 | |
| Iowa (3): | |
| Johnson: 3 | |
| Oklahoma (3): | |
| Tulsa: 3 | |
| Virginia (4): | |
| Fairfax: 4 | |
| New Hampshire (22): | |
| Grafton: 19 | |
| Rockingham: 3 | |
| Oregon (51): | |
| Klamath: 3 | |
| Douglas: 2 | |
| Marion: 2 | |
| Umatilla: 8 | |
| Washington: 31 | |
| Jackson: 5 | |
| North Carolina (11): | |
| Wake: 7 | |
| Chatham: 4 | |
| New Jersey (18): | |
| Bergen: 16 | |
| Hudson: 2 | |
| Minnesota (5): | |
| Ramsey: 4 | |
| Carver: 1 | |
| Utah (3): | |
| Davis: 3 | |
| New York (397): | |
| Ulster: 2 | |
| Westchester: 286 | |
| New York: 65 | |
| Nassau: 28 | |
| Rockland: 8 | |
| Saratoga: 6 | |
| Suffolk: 2 | |
| Pennsylvania (17): | |
| Wayne: 4 | |
| Montgomery: 9 | |
| Delaware: 4 | |
| Nebraska (39): | |
| Douglas: 39 | |
| Colorado (28): | |
| Denver: 8 | |
| Summit: 8 | |
| Douglas: 9 | |
| El Paso: 3 | |
| Connecticut (4): | |
| Fairfield: 4 | |
| Florida (49): | |
| Broward: 7 | |
| Manatee: 3 | |
| Okaloosa: 2 | |
| Volusia: 2 | |
| Charlotte: 1 | |
| Sarasota: 8 | |
| Santa Rosa: 5 | |
| Hillsborough: 15 | |
| Lee: 6 | |
| Massachusetts (99): | |
| Norfolk: 19 | |
| Suffolk: 56 | |
| Middlesex: 18 | |
| Plymouth: 4 | |
| Berkshire: 2 | |
| Hawaii (4): | |
| Honolulu: 4 | |
| Kansas (2): | |
| Johnson: 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "encoding/csv" | |
| "encoding/json" | |
| "fmt" | |
| "io" | |
| "io/ioutil" | |
| "log" | |
| "net/http" | |
| "strconv" | |
| ) | |
| const ( | |
| statsURL = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv" | |
| fccURL = "https://geo.fcc.gov/api/census/block/find?latitude=%v&longitude=%v&format=json" | |
| colState = 0 | |
| colCountry = 1 | |
| colLat = 2 | |
| colLon = 3 | |
| firstDataColumn = 4 | |
| ) | |
| type FCCData struct { | |
| County FCCCounty | |
| State FCCState | |
| Status string | |
| } | |
| type FCCCounty struct { | |
| Name string | |
| } | |
| type FCCState struct { | |
| Code string | |
| Name string | |
| } | |
| func LookupFCCData(lat, lon float64) *FCCData { | |
| resp, err := http.Get(fmt.Sprintf(fccURL, lat, lon)) | |
| if err != nil { | |
| panic(err) | |
| } | |
| defer resp.Body.Close() | |
| data, err := ioutil.ReadAll(resp.Body) | |
| if err != nil { | |
| panic(err) | |
| } | |
| out := new(FCCData) | |
| err = json.Unmarshal(data, out) | |
| if err != nil { | |
| panic(err) | |
| } | |
| return out | |
| } | |
| func main() { | |
| resp, err := http.Get(statsURL) | |
| if err != nil { | |
| panic(err) | |
| } | |
| defer resp.Body.Close() | |
| r := csv.NewReader(resp.Body) | |
| r.ReuseRecord = true | |
| perStateCounty := map[string]map[string]int{} | |
| perState := map[string]int{} | |
| line := 0 | |
| for { | |
| line++ | |
| record, err := r.Read() | |
| if err == io.EOF { | |
| break | |
| } | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| if line == 1 { | |
| continue | |
| } | |
| if record[colCountry] != "US" { | |
| continue | |
| } | |
| lat, err := strconv.ParseFloat(record[colLat], 64) | |
| if err != nil { | |
| panic(err) | |
| } | |
| lon, err := strconv.ParseFloat(record[colLon], 64) | |
| if err != nil { | |
| panic(err) | |
| } | |
| geo := LookupFCCData(lat, lon) | |
| if geo.State.Name == "" { | |
| continue | |
| } | |
| if _, ok := perState[geo.State.Name]; !ok { | |
| perState[geo.State.Name] = 0 | |
| } | |
| if _, ok := perStateCounty[geo.State.Name]; !ok { | |
| perStateCounty[geo.State.Name] = map[string]int{} | |
| } | |
| if _, ok := perStateCounty[geo.State.Name][geo.County.Name]; !ok { | |
| perStateCounty[geo.State.Name][geo.County.Name] = 0 | |
| } | |
| for _, val := range record[firstDataColumn:] { | |
| v, err := strconv.Atoi(val) | |
| if err != nil { | |
| panic(err) | |
| } | |
| perState[geo.State.Name] += v | |
| perStateCounty[geo.State.Name][geo.County.Name] += v | |
| } | |
| } | |
| fmt.Println("# COVID-19 by US County") | |
| for state, perCounty := range perStateCounty { | |
| fmt.Printf("%s (%v):\n", state, perState[state]) | |
| for county, v := range perCounty { | |
| fmt.Printf(" %s: %v\n", county, v) | |
| } | |
| fmt.Println("") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment