Skip to content

Instantly share code, notes, and snippets.

@eigenhombre
Created April 8, 2020 02:25
Show Gist options
  • Save eigenhombre/0fb0fb05a99708abdebcdc1ff810cd75 to your computer and use it in GitHub Desktop.
Save eigenhombre/0fb0fb05a99708abdebcdc1ff810cd75 to your computer and use it in GitHub Desktop.
Quick and dirty look at Cook County COVID19 cases
(ns covid19.core
"
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
"
(:gen-class)
(:require [clj-http.client :as http]
[clojure.data.csv :as csv]
[clojure.java.io :as io]))
(def csv-url (str "https://raw.githubusercontent.com/"
"CSSEGISandData/COVID-19/master/"
"csse_covid_19_data/csse_covid_19_time_series/"
"time_series_covid19_confirmed_US.csv"))
(defonce rawdata (->> csv-url
http/get
:body))
(defn normalize-records [raw]
(let [[headers & rows] (csv/read-csv raw)]
(for [r rows]
(merge {:days (->> r
(drop 11)
(map #(Integer. %)))}
(zipmap (take 11 (map keyword headers))
(take 11 r))))))
(first (normalize-records rawdata))
;;=>
'{:Country_Region "US", :Admin2 "", :Combined_Key "American Samoa, US", :iso3 "ASM", :UID "16", :Province_State "American Samoa", :days [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], :code3 "16", :iso2 "AS", :FIPS "60.0", :Long_ "-170.132", :Lat "-14.270999999999999"}
(defn selected-rows [& filters]
(reduce (fn [acc f]
(filter f acc))
(normalize-records rawdata)
filters))
(defn -main [& _]
(let [daily-cases
(->> (selected-rows (comp (partial = "US") :Country_Region)
(comp (partial = "Illinois") :Province_State)
(comp (partial = "Cook") :Admin2))
first
:days)
weekly-deltas (->> daily-cases
(partition-all 7)
(map (comp (partial apply -)
(juxt last first))))]
(println "Daily cases:" daily-cases)
(println "Weekly new:" weekly-deltas)))
;; Sample output
;; -------------
;; Daily cases: (0 0 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 4 4 4 5 5 6 7 7 11 22 27 40 50 50 62 107 178 278 278 548 805 922 1194 1418 1418 2239 2613 3445 3727 4496 5152 5575 6111 7439 8034 8728 8728)
;; Weekly new: (1 1 0 0 0 2 7 85 1016 3078 3576)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment