Published
Edited
Sep 1, 2020
Importers
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = _.flow([
mapEach(mapEach(transformEntry)),
mapEach(normalizeDomain),
mapEach(mapZip(transformTimeseries))
])(dataMap)
Insert cell
Insert cell
tidyData = flatMapMapMap(data)
Insert cell
Insert cell
getCovidDataGrouped({
statistic: "inIcuCurrently",
transformation: "log",
derivative: 1,
smoothing: 7
})
Insert cell
Insert cell
getCovidDataTidy({
statistic: "inIcuCurrently",
transformation: "log",
derivative: 1,
smoothing: 7
})
Insert cell
Insert cell
rawData = fetch("https://api.covidtracking.com/v1/states/daily.json")
.then(resp => resp.json())
.then(data =>
data
.map(({ date, ...rest }) => ({
date: dateFormat(dateParseRaw(date)),
...rest
}))
.sort((a, b) => a.date.localeCompare(b.date))
)
Insert cell
dataMap = d3.rollup(rawData, d => d[0], d => d.state, d => d.date)
Insert cell
transformEntry = _.flow([
d => d[statistic],
transformation === "logarithmic" ? d => Math.log(d) : _.identity
])
Insert cell
transformTimeseries = _.flow([differences(derivative), sma(smoothing)])
Insert cell
normalizeDomain = map => new Map(dates.map(date => [date, map.get(date)]))
Insert cell
Insert cell
flatMapMapMap = map =>
Array.from(map.entries()).flatMap(([state, value]) =>
Array.from(value.entries()).map(([date, value]) => ({ state, date, value }))
)
Insert cell
defaults = ({ statistic, transformation, derivative, smoothing })
Insert cell
// aliasing bc we lack version pinning on imports
getCovidDataGrouped = transformData
Insert cell
getCovidDataTidy = params => flatMapMapMap(getCovidDataGrouped(params))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more