Philipp Meier / Aug 20 2021 / Published
Remix of Untitled by PMPhilipp Meier
Covid-19 in Neu-Ulm (experimental)
{:deps {org.clojure/clojure {:mvn/version "1.10.1"} ;; complient is used for autocompletion ;; add your libs here (and restart the runtime to pick up changes) compliment/compliment {:mvn/version "0.3.9"} techascent/tech.ml.dataset {:mvn/version "5.00-alpha-24"} techascent/tech.viz {:mvn/version "0.3"} applied-science/darkstar {:git/url "https://github.com/applied-science/darkstar/" :sha "541a3ff36065c59e92fe6aa61e41a4385ba6f893"} }}Extensible Data Notation
Select the Landkreise (counties) to show
(def counties ;; define which counties to show in the final graph [ "LK Neu-Ulm" "SK Ulm" "LK Alb-Donau-Kreis" "LK Günzburg" "LK Unterallgäu" "LK Biberach" ] )0.0s
TLDR: The final graph.
(require [tech.viz.vega :as vega])(require [tech.v3.datatype.functional :as dfn])(require [tech.v3.datatype.datetime :as dtype-dt])(require [tech.v3.datatype.datetime.operations :as dtype-dt-ops])(require [tech.v3.dataset :as ds])(require [tech.v3.dataset.base :as dsb])(require [applied-science.darkstar :as darkstar])Clojure Setup
17.4s
WARNING: this is just an experiment. Don't trust the data. Look at https://pavelmayer.de/covid/risks/ and the RKI.
Data aggregated by Pavel Mayer
wget -N --progress=dot:giga https://pavelmayer.de/covid/risks/all-series.csv -O data.csvDownload data file
32.5s
tail data.csvShow head of data file
0.8s
(def date-col :Datum)(def df (java.text.SimpleDateFormat. "dd.MM.yyyy"))(defn pd [x] (let [r (if (string? x) (.parse df x) x)] r ) )Misc fns
0.0s
Quick check data for all Landkreise
(def csv-data (-> "data.csv" (ds/->dataset {:key-fn keyword :parser-fn {date-col [:date pd]}}) (ds/sort-by-column :Datum)))(println (ds/tail csv-data))Parse data
26.1s
Covid-19 7 day incidence
(def c (-> csv-data (ds/select-columns [date-col :Landkreis :InzidenzFallNeu_7TageSumme]) (ds/filter-column :Landkreis (set counties)) (ds/filter-column :InzidenzFallNeu_7TageSumme pos?)))(defn chart-i7 [c days] (-> c (ds/tail (* (count counties) days)) (ds/update-column date-col (fn [c] (map (.getTime %) c))) (ds/mapseq-reader) ;;all graphing functions run from pure clojure data. No batteries required. (vega/time-series date-col :InzidenzFallNeu_7TageSumme {:title "7 Tage-Inzidenz" :label-key :Landkreis :background "white"}) (assoc :width 800) ;;(assoc-in [:marks 0 :encode :enter :stroke :scale] "my-color") (update :marks conj {:type :rule :y 50}) (update :scales conj { "name" "annot-color" "type" "ordinal" "domain" {"data" "annotation","field" "text"} "range" ["#99ff99", "#ffff99", "#ffcc99", "#ff9999"] }) (update :scales conj { "name" "dash" "type" "ordinal" "domain" {"data" "annotation","field" "text"} "range" [[1, 0.5],[0.5, 1],[1, 1],[0.5 0.5]] }) _(update :scales (fn [scales] (prn "SCALES" scales) (map (fn [scale] (prn "SCALE" scale) (if (= "color" (:name scale)) (assoc-in scale ["range" "scheme"] "blues") scale)) scales))) (update :marks conj {:type "rect" :from {:data "annotation"} :encode {:enter {:y {:scale "y",:field "start"} :y2 {:scale "y",:field "end"} :x {:value 0} :x2 {:signal "width"} :fill {:scale "annot-color",:field "text"} :opacity {:value 0.2}}}}) (update :data conj {:name "annotation" :values [{:start 0,:end 35,:text "low"} {:start 35,:end 50,:text "medium"} {:start 50,:end 100,:text "high"} {:start 100,:end 350,:text "super"}]} ) (with-meta {:nextjournal/viewer "vega-lite"}) ))(chart-i7 c 60)0.1s
0.0s
Fine.