-
Notifications
You must be signed in to change notification settings - Fork 1
/
processCovidData.mjs
36 lines (31 loc) · 996 Bytes
/
processCovidData.mjs
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
import fs from "fs-extra";
import { groupBy } from "lodash-es";
import { parseCSV } from "./parseCSV.mjs";
const indexData = await parseCSV("./datasets/raw/covid-19-index.csv");
const filteredIndexData = indexData.filter(
(row) => row.aggregation_level === "0",
);
const countryIndices = filteredIndexData.map((row) => row.location_key);
const countryMap = filteredIndexData.reduce((acc, row) => {
acc[row.location_key] = row.country_name;
return acc;
}, {});
const countrySet = new Set(countryIndices);
const epidemiologyData = await parseCSV(
"./datasets/raw/covid-19-epidemiology.csv",
);
const data = [];
for (const row of epidemiologyData) {
if (countrySet.has(row.location_key)) {
data.push({
date: row.date,
code: row.location_key,
name: countryMap[row.location_key],
newCases: parseInt(row.new_confirmed),
});
}
}
const groupedData = groupBy(data, "name");
await fs.writeJSON("./datasets/covid-cases.json", groupedData, {
spaces: 2,
});