-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
41 lines (36 loc) · 1.29 KB
/
main.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
const XLSX = require("xlsx");
const { get5yrDataByTableId, get5yrGeoTable, writeToSql } = require("./data");
const { year, excelFile, outputDatabase, chunkSize } = require("./config");
const workbook = XLSX.readFile(excelFile);
const sheet_name_list = workbook.SheetNames;
const xlData = XLSX.utils.sheet_to_json(workbook.Sheets[sheet_name_list[0]]);
(async () => {
// Import GEO Tables
console.log("Loading 5yr Geo Tables");
const geos5Yr = await get5yrGeoTable();
const tblName5Yr = `${outputDatabase}.dbo.G${year}5YR`;
await writeToSql(geos5Yr, {
tblName: tblName5Yr,
chunkSize,
idColumn: "DADSID",
overwrite: true,
});
for (let i = 0; i < xlData.length; i++) {
const row = xlData[i];
const tableId = row["Table ID"];
console.log(`Loading table file (${i} / ${xlData.length}) -- ${tableId}`);
if (tableId) {
const fiveYrData = await get5yrDataByTableId(tableId);
console.log(`Table Loaded. Writing to db... (${fiveYrData.length} rows)`);
const tblName = `${outputDatabase}.dbo.${tableId}`;
await writeToSql(fiveYrData, {
tblName,
chunkSize,
idColumn: "GEO_ID",
overwrite: true,
});
console.log(`${tableId} - written to database.`);
}
}
// await createJoinedViewByYear(xlData, '5');
})();