make-mp-data 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/default.js +1 -1
- package/index.js +61 -39
- package/package.json +1 -1
package/default.js
CHANGED
package/index.js
CHANGED
|
@@ -87,6 +87,7 @@ async function main(config) {
|
|
|
87
87
|
format = "csv",
|
|
88
88
|
token = null,
|
|
89
89
|
region = "US",
|
|
90
|
+
writeToDisk = true
|
|
90
91
|
} = config;
|
|
91
92
|
|
|
92
93
|
const uuidChance = new Chance(seed);
|
|
@@ -115,7 +116,7 @@ async function main(config) {
|
|
|
115
116
|
const firstEvents = events.filter((e) => e.isFirstEvent);
|
|
116
117
|
const eventData = [];
|
|
117
118
|
const userProfilesData = [];
|
|
118
|
-
|
|
119
|
+
let scdTableData = [];
|
|
119
120
|
const groupProfilesData = [];
|
|
120
121
|
const lookupTableData = [];
|
|
121
122
|
const avgEvPerUser = Math.floor(numEvents / numUsers);
|
|
@@ -158,6 +159,9 @@ async function main(config) {
|
|
|
158
159
|
);
|
|
159
160
|
}
|
|
160
161
|
}
|
|
162
|
+
//flatten SCD
|
|
163
|
+
scdTableData = scdTableData.flat();
|
|
164
|
+
|
|
161
165
|
console.log("\n");
|
|
162
166
|
|
|
163
167
|
// make group profiles
|
|
@@ -201,17 +205,24 @@ async function main(config) {
|
|
|
201
205
|
[lookupFiles, lookupTableData],
|
|
202
206
|
];
|
|
203
207
|
console.log("\n");
|
|
208
|
+
|
|
209
|
+
if (!writeToDisk) return { eventData, userProfilesData, scdTableData, groupProfilesData, lookupTableData };
|
|
204
210
|
//write the files
|
|
205
211
|
for (const pair of pairs) {
|
|
206
212
|
const [paths, data] = pair;
|
|
207
213
|
for (const path of paths) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
214
|
+
let datasetsToWrite;
|
|
215
|
+
if (data?.[0]?.["key"]) datasetsToWrite = data.map(d => d.data);
|
|
216
|
+
else datasetsToWrite = [data];
|
|
217
|
+
for (const writeData of datasetsToWrite) {
|
|
218
|
+
if (format === "csv") {
|
|
219
|
+
console.log(`writing ${path}`);
|
|
220
|
+
const csv = Papa.unparse(writeData, {});
|
|
221
|
+
await touch(path, csv);
|
|
222
|
+
console.log(`\tdone\n`);
|
|
223
|
+
} else {
|
|
224
|
+
await touch(path, data, true);
|
|
225
|
+
}
|
|
215
226
|
}
|
|
216
227
|
}
|
|
217
228
|
}
|
|
@@ -363,34 +374,45 @@ function buildFileNames(config) {
|
|
|
363
374
|
return writePaths;
|
|
364
375
|
}
|
|
365
376
|
|
|
366
|
-
//
|
|
367
|
-
main
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
377
|
+
// this is for CLI
|
|
378
|
+
if (require.main === module) {
|
|
379
|
+
//that's all folks :)
|
|
380
|
+
main(config)
|
|
381
|
+
.then((data) => {
|
|
382
|
+
console.log(`------------------SUMMARY------------------`);
|
|
383
|
+
const { events, groups, users } = data.import;
|
|
384
|
+
const files = data.files;
|
|
385
|
+
const folder = files.pop();
|
|
386
|
+
const groupBytes = groups.reduce((acc, group) => { return acc + group.bytes; }, 0);
|
|
387
|
+
const groupSuccess = groups.reduce((acc, group) => { return acc + group.success; }, 0);
|
|
388
|
+
const bytes = events.bytes + groupBytes + users.bytes;
|
|
389
|
+
const stats = {
|
|
390
|
+
events: comma(events.success || 0),
|
|
391
|
+
users: comma(users.success || 0),
|
|
392
|
+
groups: comma(groupSuccess || 0),
|
|
393
|
+
bytes: bytesHuman(bytes || 0)
|
|
394
|
+
};
|
|
395
|
+
if (bytes > 0) console.table(stats);
|
|
396
|
+
console.log(`\nfiles written to ${folder}...`);
|
|
397
|
+
console.log("\t" + files.flat().join('\n\t'));
|
|
398
|
+
console.log(`\n------------------SUMMARY------------------\n\n\n`);
|
|
399
|
+
})
|
|
400
|
+
.catch((e) => {
|
|
401
|
+
console.log(`------------------ERROR------------------`);
|
|
402
|
+
console.error(e);
|
|
403
|
+
console.log(`------------------ERROR------------------`);
|
|
404
|
+
debugger;
|
|
405
|
+
})
|
|
406
|
+
.finally(() => {
|
|
407
|
+
console.log('have a wonderful day :)');
|
|
408
|
+
openFinder(path.resolve("./data"));
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
else {
|
|
414
|
+
module.exports = main;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|