-
Notifications
You must be signed in to change notification settings - Fork 1
/
cubes-audit.js
67 lines (53 loc) · 2.17 KB
/
cubes-audit.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
66
67
// node scripts/cubes-audit.js
const {Client} = require("mondrian-rest-client"),
fs = require("fs");
const DEFAULT = "https://canon-api.datausa.io";
const client = new Client(process.env.CANON_AUDIT_API || DEFAULT);
const now = new Date()
.toLocaleString("en-US", {timeZone: "America/New_York"})
.replace("T", " ")
.replace(/\..*$/, "");
client.cubes().then(cubes => {
let row = "## CUBES AUDIT \n";
row += "\n";
row += `Data obtained from ${process.env.CANON_AUDIT_API} \n`;
row += "\n";
row += `Last updated on ${now} \n`;
row += "\n";
cubes.sort((a, b) => a.name > b.name ? 1 : -1).forEach(cube => {
const {dimensions, measures, annotations} = cube;
if (Object.keys(annotations).length < 8) {
row += `### CUBE: ${cube.name} \n`;
if (!annotations.source_name) row += "- [ ] source_name \n";
if (!annotations.source_description) row += "- [ ] source_description \n";
if (!annotations.source_link) row += "- [ ] source_link \n";
if (!annotations.dataset_name) row += "- [ ] dataset_name \n";
if (!annotations.dataset_link) row += "- [ ] dataset_link \n";
if (!annotations.topic) row += "- [ ] topic \n";
if (!annotations.subtopic) row += "- [ ] subtopic \n";
if (!annotations.details) row += "- [ ] details \n";
row += "\n";
}
dimensions.forEach(dimension => {
if (!dimension.annotations.dim_type) {
row += `### DIMENSION: ${dimension.name} \n`;
row += "- [ ] dim_type \n";
row += "\n";
}
});
measures.forEach(measure => {
if (!measure.annotations.error_for_measure) {
if (!measure.annotations.units_of_measurement || measure.name.toUpperCase().includes("MOE")) row += `### MEASURE: ${measure.name} \n`;
if (!measure.annotations.units_of_measurement) row += "- [ ] units_of_measurement \n";
if (measure.name.toUpperCase().includes("MOE")) row += "- [ ] error_for_measure \n";
row += "\n";
}
});
row += "----\n";
row += "\n";
});
fs.writeFile("./scripts/cubes-audit.md", row, "utf8", err => {
if (err) console.log(err);
else console.log("created scripts/cubes-audit.md");
});
});