Published
Edited
Dec 3, 2021
8 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
statesSummary = aq.fromCSV(
await (await fetch(`https://api.covidactnow.org/v2/states.csv?apiKey=${API_KEY}`)).text()
)
Insert cell
data = aq.fromCSV(
await (await fetch(`https://api.covidactnow.org/v2/states.timeseries.csv?apiKey=${API_KEY}`)).text()
)
.join(statesSummary.select(['state', 'population']), ['state', 'state'])
.groupby('state')
.derive({
casesPer100k: aq.rolling(d => op.average(d['actuals.newCases']) * 100000 / d['population'], [-6, 0]),
deathsPer5m: aq.rolling(d => op.average(d['actuals.newDeaths']) * 5000000 / d['population'], [-6, 0]),
hospitalizationsPer250k: d => d['actuals.hospitalBeds.currentUsageCovid'] * 250000 / d['population'],
laggedDate: aq.escape(d => d3.timeDay.offset(d.date, -lagDays)),
// Interpolate previous vaccine values where data is missing
vaccineRatio: d => op.fill_down(d['metrics.vaccinationsInitiatedRatio'], 0),
vaccineRatio2: d=> op.fill_down(d['metrics.vaccinationsCompletedRatio'], 0),
})
.ungroup()
Insert cell
keyVaccinationDates = Array.from(d3.group(data.objects(), d => d.state)).reduce((acc, [state, data]) => {
return acc.concat(
d3.range(VACCINE_MILESTONE_FREQUENCY, 1, VACCINE_MILESTONE_FREQUENCY).map(p => {
const closestDataPoint = data[d3.bisectLeft(data.map(d => settings.vaccinesCompleted ? d.vaccineRatio2 : d.vaccineRatio), p)]
return {
state,
approxVaccineRatio: p,
date: closestDataPoint ? closestDataPoint.date : null,
}
})
)
}, [])
Insert cell
extents = data.rollup({
caseMax: op.max('casesPer100k'), deathMax: op.max(settings.hospitalizations ? 'deathsPer5m' : 'hospitalizationsPer250k') }).object(0)
Insert cell
Insert cell
Insert cell
Insert cell
DATE_STRIPE_FREQUENCY = width > 600 ? 4 : 7
Insert cell
VACCINE_MILESTONE_FREQUENCY = width > 600 ? 0.1 : 0.2
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more