This repository was archived by the owner on May 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrestructure-csv.js
65 lines (53 loc) · 3.33 KB
/
restructure-csv.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const fs = require('fs');
const parseCsv = require('csv-parse/lib/sync');
const stringifyCsv = require('csv-stringify/lib/sync');
const {percentForState} = require('./population.js');
const input = fs.readFileSync('./data/data.csv', 'utf8');
const records = parseCsv(input, {
columns: true,
});
const newRecords = [];
for (const record of records) {
newRecords.push({
date: record.date,
pubDate: record.pubDate,
state: record.state,
totalDosesCumulative: record.totalDosesCumulative,
initialDosesCumulative: record.initialDosesCumulative,
initialDosesCumulativeBioNTech: record.initialDosesCumulativeBioNTech,
initialDosesCumulativeModerna: record.initialDosesCumulativeModerna,
initialDosesCumulativeAstraZeneca: record.initialDosesCumulativeAstraZeneca,
initialDosesCumulativeNovavax: record.initialDosesCumulativeNovavax || 0,
finalDosesCumulative: record.finalDosesCumulative,
finalDosesCumulativeBioNTech: record.finalDosesCumulativeBioNTech,
finalDosesCumulativeModerna: record.finalDosesCumulativeModerna,
finalDosesCumulativeAstraZeneca: record.finalDosesCumulativeAstraZeneca,
finalDosesCumulativeNovavax: record.finalDosesCumulativeNovavax || 0,
finalDosesCumulativeJohnsonAndJohnson: record.finalDosesCumulativeJohnsonAndJohnson,
boosterDosesCumulative: record.boosterDosesCumulative || 0,
boosterDosesCumulativeBioNTech: record.boosterDosesCumulativeBioNTech || 0,
boosterDosesCumulativeModerna: record.boosterDosesCumulativeModerna || 0,
boosterDosesCumulativeJohnsonAndJohnson: record.boosterDosesCumulativeJohnsonAndJohnson || 0,
onlyPartiallyVaccinatedCumulative: record.onlyPartiallyVaccinatedCumulative,
onlyPartiallyVaccinatedPercent: record.onlyPartiallyVaccinatedPercent,
onlyPartiallyVaccinatedCumulativeBioNTech: record.onlyPartiallyVaccinatedCumulativeBioNTech,
onlyPartiallyVaccinatedCumulativeModerna: record.onlyPartiallyVaccinatedCumulativeModerna,
onlyPartiallyVaccinatedCumulativeAstraZeneca: record.onlyPartiallyVaccinatedCumulativeAstraZeneca,
//onlyPartiallyVaccinatedCumulativeJohnsonAndJohnson: 0,
// First doses of any vaccine, including J&J (which is not included in `initialDosesCumulative`).
atLeastPartiallyVaccinatedCumulative: record.atLeastPartiallyVaccinatedCumulative,
atLeastPartiallyVaccinatedPercent: record.atLeastPartiallyVaccinatedPercent,
atLeastPartiallyVaccinatedCumulativeBioNTech: record.atLeastPartiallyVaccinatedCumulativeBioNTech,
atLeastPartiallyVaccinatedCumulativeModerna: record.atLeastPartiallyVaccinatedCumulativeModerna,
atLeastPartiallyVaccinatedCumulativeAstraZeneca: record.atLeastPartiallyVaccinatedCumulativeAstraZeneca,
atLeastPartiallyVaccinatedCumulativeJohnsonAndJohnson: record.atLeastPartiallyVaccinatedCumulativeJohnsonAndJohnson,
fullyVaccinatedCumulative: record.fullyVaccinatedCumulative,
fullyVaccinatedPercent: record.fullyVaccinatedPercent,
fullyVaccinatedCumulativeBioNTech: record.fullyVaccinatedCumulativeBioNTech,
fullyVaccinatedCumulativeModerna: record.fullyVaccinatedCumulativeModerna,
fullyVaccinatedCumulativeAstraZeneca: record.fullyVaccinatedCumulativeAstraZeneca,
fullyVaccinatedCumulativeJohnsonAndJohnson: record.fullyVaccinatedCumulativeJohnsonAndJohnson,
});
}
const csv = stringifyCsv(newRecords, { header: true });
console.log(csv);