Add hospitalizations page.
This commit is contained in:
		
							
								
								
									
										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