Add hospitalizations page.
This commit is contained in:
111
data/parser/overall/cases.js
Normal file
111
data/parser/overall/cases.js
Normal file
@@ -0,0 +1,111 @@
|
||||
import mkdirp from 'mkdirp'
|
||||
import path from 'path'
|
||||
import fsp from 'fs/promises'
|
||||
import Papa from 'papaparse'
|
||||
import { getCounty } from '../../util.js'
|
||||
|
||||
async function processByCounty({ date, zip }, countyInfo, output) {
|
||||
output = {
|
||||
directory: path.join(output.directory, 'by-county'),
|
||||
file: county => `${county}.json`
|
||||
}
|
||||
|
||||
const csv = await zip.entryData('epicurve_rpt_date.csv').then(res => res.toString())
|
||||
|
||||
const rows = Papa.parse(csv, {
|
||||
header: true
|
||||
}).data
|
||||
|
||||
const counties = rows.reduce((counties, row) => {
|
||||
const county = getCounty(row.county)
|
||||
const info = countyInfo[county]
|
||||
if (!county) return counties
|
||||
if (!counties[county]) counties[county] = []
|
||||
counties[county].push({
|
||||
report_date: row['report_date'],
|
||||
population: info.population,
|
||||
cases: parseInt(row.cases),
|
||||
cases_per_capita: parseInt(row.cases) / info.population,
|
||||
cases_14_days: info.cases_14_days,
|
||||
case_rate_14_days: info.case_rate_14_days,
|
||||
total_cases: parseInt(row.total_cases_cum),
|
||||
total_cases_per_capita: parseInt(row.total_cases_cum) / info.population
|
||||
})
|
||||
return counties
|
||||
}, {})
|
||||
|
||||
for (const county in counties) {
|
||||
const data = {
|
||||
segment: { county },
|
||||
headers: Object.keys(counties[county][0]),
|
||||
rows: counties[county].map(row => Object.values(row))
|
||||
}
|
||||
|
||||
await mkdirp(output.directory)
|
||||
await fsp.writeFile(path.join(output.directory, output.file(county)), JSON.stringify(data))
|
||||
}
|
||||
}
|
||||
|
||||
async function processCombined({ date, zip }, countyInfo, output) {
|
||||
output = {
|
||||
directory: output.directory,
|
||||
file: `combined.json`
|
||||
}
|
||||
|
||||
const csv = await zip.entryData('epicurve_rpt_date.csv').then(res => res.toString())
|
||||
|
||||
const rows = Papa.parse(csv, {
|
||||
header: true
|
||||
}).data
|
||||
|
||||
const report_dates = new Set()
|
||||
|
||||
const results = rows.map(row => {
|
||||
const county = getCounty(row.county)
|
||||
if (!county) return null
|
||||
if (['-- All --', '-- Unknown --'].includes(county)) return null
|
||||
|
||||
const info = countyInfo[county]
|
||||
report_dates.add(row['report_date'])
|
||||
return {
|
||||
county,
|
||||
report_date: row['report_date'],
|
||||
population: info.population,
|
||||
cases: parseInt(row.cases),
|
||||
cases_per_capita: parseInt(row.cases) / info.population,
|
||||
cases_14_days: info.cases_14_days,
|
||||
case_rate_14_days: info.case_rate_14_days,
|
||||
total_cases: parseInt(row.total_cases_cum),
|
||||
total_cases_per_capita: parseInt(row.total_cases_cum) / info.population
|
||||
}
|
||||
}).filter(row => !!row)
|
||||
|
||||
const data = {
|
||||
segment: { report_date: Array.from(report_dates) },
|
||||
headers: Object.keys(results[0]),
|
||||
rows: results.map(row => Object.values(row))
|
||||
}
|
||||
|
||||
await mkdirp(output.directory)
|
||||
await fsp.writeFile(path.join(output.directory, output.file), JSON.stringify(data))
|
||||
}
|
||||
|
||||
|
||||
async function processSingleZip (zip, countyInfo) {
|
||||
const output = {
|
||||
directory: `./public/data/state/cases/`,
|
||||
}
|
||||
|
||||
try {
|
||||
await fsp.rm(output.directory, { recursive: true })
|
||||
} catch (e) {}
|
||||
|
||||
await processByCounty(zip, countyInfo, output)
|
||||
await processCombined(zip, countyInfo, output)
|
||||
}
|
||||
|
||||
function process (zips, countyInfo) {
|
||||
return processSingleZip(zips.at(-1), countyInfo)
|
||||
}
|
||||
|
||||
export default process
|
||||
130
data/parser/overall/hospitalizations.js
Normal file
130
data/parser/overall/hospitalizations.js
Normal file
@@ -0,0 +1,130 @@
|
||||
import mkdirp from 'mkdirp'
|
||||
import path from 'path'
|
||||
import fsp from 'fs/promises'
|
||||
import Papa from 'papaparse'
|
||||
import { getCounty } from '../../util.js'
|
||||
|
||||
async function processByCounty({ date, zip }, countyInfo, output) {
|
||||
output = {
|
||||
directory: path.join(output.directory, 'by-county'),
|
||||
file: county => `${county}.json`
|
||||
}
|
||||
|
||||
const csv = await zip.entryData('epicurve_rpt_date.csv').then(res => res.toString())
|
||||
|
||||
const rows = Papa.parse(csv, {
|
||||
header: true
|
||||
}).data
|
||||
|
||||
const hospitalizations_last_14_days = []
|
||||
|
||||
function computeHospitalizationsLast14Days() {
|
||||
return hospitalizations_last_14_days.reduce((prev, current) => prev + current, 0)
|
||||
}
|
||||
|
||||
const counties = rows.reduce((counties, row) => {
|
||||
const county = getCounty(row.county)
|
||||
const info = countyInfo[county]
|
||||
if (!county) return counties
|
||||
if (!counties[county]) counties[county] = []
|
||||
hospitalizations_last_14_days.unshift(+row.confirmed_case_hospitalization)
|
||||
hospitalizations_last_14_days.length = 14
|
||||
|
||||
counties[county].push({
|
||||
report_date: row['report_date'],
|
||||
population: info.population,
|
||||
hospitalizations: parseInt(row.confirmed_case_hospitalization),
|
||||
hospitalizations_per_capita: parseInt(row.confirmed_case_hospitalization) / info.population,
|
||||
hospitalizations_last_14_days: computeHospitalizationsLast14Days(),
|
||||
hospitalizations_last_14_days_per_capita: computeHospitalizationsLast14Days() / info.population
|
||||
})
|
||||
return counties
|
||||
}, {})
|
||||
|
||||
for (const county in counties) {
|
||||
const data = {
|
||||
segment: { county },
|
||||
headers: Object.keys(counties[county][0]),
|
||||
rows: counties[county].map(row => Object.values(row))
|
||||
}
|
||||
|
||||
await mkdirp(output.directory)
|
||||
await fsp.writeFile(path.join(output.directory, output.file(county)), JSON.stringify(data))
|
||||
}
|
||||
}
|
||||
|
||||
async function processCombined({ date, zip }, countyInfo, output) {
|
||||
output = {
|
||||
directory: output.directory,
|
||||
file: `combined.json`
|
||||
}
|
||||
|
||||
const csv = await zip.entryData('epicurve_rpt_date.csv').then(res => res.toString())
|
||||
|
||||
const rows = Papa.parse(csv, {
|
||||
header: true
|
||||
}).data
|
||||
|
||||
const report_dates = new Set()
|
||||
|
||||
let hospitalizations_last_14_days = []
|
||||
|
||||
function computeHospitalizationsLast14Days() {
|
||||
return hospitalizations_last_14_days.reduce((prev, current) => prev + current, 0)
|
||||
}
|
||||
|
||||
let oldCounty = null
|
||||
const results = rows.map(row => {
|
||||
const county = getCounty(row.county)
|
||||
if (!county) return null
|
||||
if (['-- All --', '-- Unknown --'].includes(county)) return null
|
||||
const info = countyInfo[county]
|
||||
|
||||
if (oldCounty !== county) {
|
||||
hospitalizations_last_14_days = []
|
||||
oldCounty = county
|
||||
}
|
||||
hospitalizations_last_14_days.unshift(+row.confirmed_case_hospitalization)
|
||||
hospitalizations_last_14_days.length = 14
|
||||
|
||||
report_dates.add(row['report_date'])
|
||||
return {
|
||||
county,
|
||||
report_date: row['report_date'],
|
||||
population: info.population,
|
||||
hospitalizations: parseInt(row.confirmed_case_hospitalization),
|
||||
hospitalizations_per_capita: parseInt(row.confirmed_case_hospitalization) / info.population,
|
||||
hospitalizations_last_14_days: computeHospitalizationsLast14Days(county),
|
||||
hospitalizations_last_14_days_per_capita: computeHospitalizationsLast14Days(county) / info.population
|
||||
}
|
||||
}).filter(row => !!row)
|
||||
|
||||
const data = {
|
||||
segment: { report_date: Array.from(report_dates) },
|
||||
headers: Object.keys(results[0]),
|
||||
rows: results.map(row => Object.values(row))
|
||||
}
|
||||
|
||||
await mkdirp(output.directory)
|
||||
await fsp.writeFile(path.join(output.directory, output.file), JSON.stringify(data))
|
||||
}
|
||||
|
||||
|
||||
async function processSingleZip (zip, countyInfo) {
|
||||
const output = {
|
||||
directory: `./public/data/state/hospitalizations/`,
|
||||
}
|
||||
|
||||
try {
|
||||
await fsp.rm(output.directory, { recursive: true })
|
||||
} catch (e) {}
|
||||
|
||||
await processByCounty(zip, countyInfo, output)
|
||||
await processCombined(zip, countyInfo, output)
|
||||
}
|
||||
|
||||
function process (zips, countyInfo) {
|
||||
return processSingleZip(zips.at(-1), countyInfo)
|
||||
}
|
||||
|
||||
export default process
|
||||
58
data/parser/overall/testing.js
Normal file
58
data/parser/overall/testing.js
Normal file
@@ -0,0 +1,58 @@
|
||||
import mkdirp from 'mkdirp'
|
||||
import path from 'path'
|
||||
import fsp from 'fs/promises'
|
||||
import Papa from 'papaparse'
|
||||
import { getCounty } from '../../util.js'
|
||||
|
||||
async function processSingleZip ({ date, zip }) {
|
||||
const output = {
|
||||
directory: `./public/data/state/testing/by-county/`,
|
||||
file: county => `${county}.json`
|
||||
}
|
||||
|
||||
try {
|
||||
await fsp.rm(output.directory, { recursive: true })
|
||||
} catch (e) {}
|
||||
|
||||
const csv = await zip.entryData('pcr_antigen.csv').then(res => res.toString())
|
||||
|
||||
const rows = Papa.parse(csv, {
|
||||
header: true
|
||||
}).data
|
||||
|
||||
const counties = rows.reduce((counties, row) => {
|
||||
const county = getCounty(row.county)
|
||||
if (!county) return counties
|
||||
if (!counties[county]) counties[county] = []
|
||||
counties[county].push({
|
||||
report_date: row['report_date'],
|
||||
pcr_performed: +row['ALL PCR tests performed'],
|
||||
pcr_positive: +row['All PCR positive tests'],
|
||||
antigen_performed: +row['Antigen Tests Performed'],
|
||||
antigen_positive: +row['Antigen Positive Tests'],
|
||||
combined_performed: (+row['ALL PCR tests performed']) + (+row['Antigen Tests Performed']),
|
||||
combined_positive: (+row['All PCR positive tests']) + (+row['Antigen Positive Tests']),
|
||||
seven_day_percent_positive: +row['7 day percent positive'],
|
||||
combined_performed_running_total: (+row['Running total of all PCR tests']) + (+row['Running total of all Antigen tests']),
|
||||
})
|
||||
return counties
|
||||
}, {})
|
||||
|
||||
for (const county in counties) {
|
||||
const data = {
|
||||
segment: { county },
|
||||
headers: Object.keys(counties[county][0]),
|
||||
rows: counties[county].map(row => Object.values(row))
|
||||
}
|
||||
|
||||
await mkdirp(output.directory)
|
||||
await fsp.writeFile(path.join(output.directory, output.file(county)), JSON.stringify(data))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function process (zips) {
|
||||
return processSingleZip(zips.at(-1))
|
||||
}
|
||||
|
||||
export default process
|
||||
Reference in New Issue
Block a user