Skip to content

Instantly share code, notes, and snippets.

@ordnungswidrig
Created November 12, 2020 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ordnungswidrig/a28ad3939c71b8a554e2307b84ebc530 to your computer and use it in GitHub Desktop.
Save ordnungswidrig/a28ad3939c71b8a554e2307b84ebc530 to your computer and use it in GitHub Desktop.
use tech to visualize covid-19 data for a german county
{:deps {techascent/tech.ml.dataset {:mvn/version "5.00-alpha-24"} techascent/tech.viz {:mvn/version "0.3"}}}
(require '[tech.viz.vega :as vega])
(require '[tech.v3.datatype.functional :as dfn])
(require '[tech.v3.dataset :as ds])
;; this is large maybe store locally
(def csv-data (ds/->dataset "https://pavelmayer.de/covid/risks/full-data.csv"))
(def m (->
(->> (-> csv-data (ds/filter-column "Landkreis" #{"LK Neu-Ulm"})
(ds/group-by-column "Meldedatum"))
(map (fn [[d ds]] {:Meldedatum d
:MeldedatumKlar (first (get ds "MeldedatumKlar"))
:AnzahlFall (dfn/sum (get ds "AnzahlFall"))
:FaellePro100k (dfn/sum (get ds "FaellePro100k"))})) ds/->>dataset)
(ds/sort-by-column :Meldedatum <)))
(-> m
;; rolling sum over the last 7 days
(assoc :w7 (dfn/fixed-rolling-window (m :FaellePro100k) 7 dfn/reduce-+))
(ds/tail 30)
ds/mapseq-reader
(vega/time-series :Meldedatum :w7)
(vega/vega->svg-file "timeseries.svg"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment