Working on case cards.
This commit is contained in:
		
							
								
								
									
										38
									
								
								data/parser/counties.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								data/parser/counties.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
			
		||||
 | 
			
		||||
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 csv = await zip.entryData('county_cases.csv').then(res => res.toString())
 | 
			
		||||
 | 
			
		||||
  const rows = Papa.parse(csv, {
 | 
			
		||||
    header: true
 | 
			
		||||
  }).data
 | 
			
		||||
 | 
			
		||||
  let totalPopulation = 0
 | 
			
		||||
 | 
			
		||||
  const counties = rows.reduce((counties, row) => {
 | 
			
		||||
    const county = getCounty(row.county_name)
 | 
			
		||||
    if (!county) return counties
 | 
			
		||||
    totalPopulation += +row.population
 | 
			
		||||
    counties[county] = {
 | 
			
		||||
      population: +row.population
 | 
			
		||||
    }
 | 
			
		||||
    return counties
 | 
			
		||||
  }, {})
 | 
			
		||||
 | 
			
		||||
  return {
 | 
			
		||||
    ...counties,
 | 
			
		||||
    '-- All --': { population: totalPopulation },
 | 
			
		||||
    '-- Unknown --': { population: 0 }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function process (zips) {
 | 
			
		||||
  return processSingleZip(zips.at(-1))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default process
 | 
			
		||||
							
								
								
									
										58
									
								
								data/parser/state/cases.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								data/parser/state/cases.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 }, countyInfo) {
 | 
			
		||||
  const output = {
 | 
			
		||||
    directory: `./public/data/state/cases`,
 | 
			
		||||
    file: county => `${county}.json`
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  try {
 | 
			
		||||
    await fsp.rm(output.directory, { recursive: true })
 | 
			
		||||
  } catch (e) {}
 | 
			
		||||
 | 
			
		||||
  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,
 | 
			
		||||
      moving_avg_cases: parseInt(row.moving_avg_cases),
 | 
			
		||||
      moving_avg_cases_per_capita: parseInt(row.moving_avg_cases) / info.population,
 | 
			
		||||
      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))
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function process (zips, countyInfo) {
 | 
			
		||||
  return processSingleZip(zips.at(-1), countyInfo)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default process
 | 
			
		||||
@@ -1,12 +1,12 @@
 | 
			
		||||
import mkdirp from 'mkdirp'
 | 
			
		||||
import path from 'path'
 | 
			
		||||
import fs from 'fs'
 | 
			
		||||
import fsp from 'fs/promises'
 | 
			
		||||
import Papa from 'papaparse'
 | 
			
		||||
import { getCounty } from '../../util.js'
 | 
			
		||||
 | 
			
		||||
async function processSingleZip({ date, zip }) {
 | 
			
		||||
async function processSingleZip ({ date, zip }) {
 | 
			
		||||
  const output = {
 | 
			
		||||
    directory: `./public/data/testing-trend`,
 | 
			
		||||
    directory: `./public/data/state/testing`,
 | 
			
		||||
    file: county => `${county}.json`
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -21,7 +21,7 @@ async function processSingleZip({ date, zip }) {
 | 
			
		||||
  }).data
 | 
			
		||||
 | 
			
		||||
  const counties = rows.reduce((counties, row) => {
 | 
			
		||||
    const county = row.county === 'Georgia' ? 'All' : row.county
 | 
			
		||||
    const county = getCounty(row.county)
 | 
			
		||||
    if (!county) return counties
 | 
			
		||||
    if (!counties[county]) counties[county] = []
 | 
			
		||||
    counties[county].push({
 | 
			
		||||
@@ -46,8 +46,7 @@ async function processSingleZip({ date, zip }) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    await mkdirp(output.directory)
 | 
			
		||||
 | 
			
		||||
    await fsp.writeFile(path.join(output.directory, output.file(county)), JSON.stringify(data, null, '\t'))
 | 
			
		||||
    await fsp.writeFile(path.join(output.directory, output.file(county)), JSON.stringify(data))
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user