Working on expanded pages and data processing.
This commit is contained in:
		
							
								
								
									
										3
									
								
								data/package.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								data/package.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
{
 | 
			
		||||
  "type": "module"
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										15
									
								
								data/parser.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								data/parser.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
			
		||||
import fs from 'fs/promises'
 | 
			
		||||
import fg from 'fast-glob'
 | 
			
		||||
import StreamZip from 'node-stream-zip'
 | 
			
		||||
import TestingTrend from './parser/testing-trend.js'
 | 
			
		||||
 | 
			
		||||
async function main() {
 | 
			
		||||
  const sources = await fg(['./data/raw/*.zip'])
 | 
			
		||||
  sources.sort()
 | 
			
		||||
 | 
			
		||||
  const zips = sources.map(source => new StreamZip.async({ file: source }))
 | 
			
		||||
 | 
			
		||||
  await TestingTrend(zips)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
main()
 | 
			
		||||
							
								
								
									
										58
									
								
								data/parser/testing-trend.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								data/parser/testing-trend.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
			
		||||
import mkdirp from 'mkdirp'
 | 
			
		||||
import path from 'path'
 | 
			
		||||
import fs from 'fs/promises'
 | 
			
		||||
import Papa from 'papaparse'
 | 
			
		||||
 | 
			
		||||
async function processSingleZip(zip) {
 | 
			
		||||
  const output = {
 | 
			
		||||
    directory: `./public/data/testing-trend`,
 | 
			
		||||
    file: county => `${county}.json`
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  try {
 | 
			
		||||
    await fs.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 = row.county === 'Georgia' ? 'All' : 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'],
 | 
			
		||||
    })
 | 
			
		||||
    return counties
 | 
			
		||||
  }, {})
 | 
			
		||||
 | 
			
		||||
  console.log(JSON.stringify(Object.keys(counties), null, '  '))
 | 
			
		||||
 | 
			
		||||
  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 fs.writeFile(path.join(output.directory, output.file(county)), JSON.stringify(data))
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function process (zips) {
 | 
			
		||||
  return Promise.all(zips.map(zip => processSingleZip(zip)))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default process
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								data/raw/2021-03-01.zip
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								data/raw/2021-03-01.zip
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								data/raw/2021-12-27.zip
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								data/raw/2021-12-27.zip
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								data/raw/2021-12-28.zip
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								data/raw/2021-12-28.zip
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								data/raw/2021-12-29.zip
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								data/raw/2021-12-29.zip
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user