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.
Files changed (3) hide show
  1. package/default.js +1 -1
  2. package/index.js +61 -39
  3. package/package.json +1 -1
package/default.js CHANGED
@@ -94,7 +94,7 @@ const config = {
94
94
  each pair represents a group_key and the number of profiles for that key
95
95
  */
96
96
  groupKeys: [
97
- ['company_id', 250],
97
+ ['company_id', 350],
98
98
 
99
99
  ],
100
100
  groupProps: {
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
- const scdTableData = [];
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
- if (format === "csv") {
209
- console.log(`writing ${path}`);
210
- const csv = Papa.unparse(data, {});
211
- await touch(path, csv);
212
- console.log(`\tdone\n`);
213
- } else {
214
- await touch(path, data, true);
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
- //that's all folks :)
367
- main(config)
368
- .then((data) => {
369
- console.log(`------------------SUMMARY------------------`);
370
- const { events, groups, users } = data.import;
371
- const files = data.files;
372
- const folder = files.pop();
373
- const groupBytes = groups.reduce((acc, group) => { return acc + group.bytes; }, 0);
374
- const groupSuccess = groups.reduce((acc, group) => { return acc + group.success; }, 0);
375
- const bytes = events.bytes + groupBytes + users.bytes;
376
- const stats = {
377
- events: comma(events.success || 0),
378
- users: comma(users.success || 0),
379
- groups: comma(groupSuccess || 0),
380
- bytes: bytesHuman(bytes || 0)
381
- };
382
- console.table(stats);
383
- console.log(`\nfiles written to ${folder}...`);
384
- console.log("\t" + files.flat().join('\t\n'));
385
- console.log(`------------------SUMMARY------------------\n\n\n`);
386
- })
387
- .catch((e) => {
388
- console.log(`------------------ERROR------------------`);
389
- console.error(e);
390
- console.log(`------------------ERROR------------------`);
391
- debugger;
392
- })
393
- .finally(() => {
394
- console.log('have a wonderful day :)');
395
- openFinder(path.resolve("./data"));
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
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "make-mp-data",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "builds all mixpanel primitives for a given project",
5
5
  "main": "index.js",
6
6
  "scripts": {