make-mp-data 1.1.0 → 1.1.11

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 (4) hide show
  1. package/cli.js +3 -1
  2. package/default.js +2 -2
  3. package/index.js +25 -15
  4. package/package.json +1 -1
package/cli.js CHANGED
@@ -8,6 +8,7 @@ const hero = String.raw`
8
8
  ┛ ┛
9
9
  makes all the things for mixpanel (v${version || 1})
10
10
  by ak@mixpanel.com
11
+ -----------------------------------------
11
12
  `;
12
13
 
13
14
 
@@ -17,7 +18,8 @@ function cliParams() {
17
18
  const args = yargs(process.argv.splice(2))
18
19
  .scriptName("make-mp-data")
19
20
  .usage(`\nusage:\nnpx $0 [dataModel.js] [options]
20
- ex:
21
+
22
+ examples:
21
23
  npx $0
22
24
  npx $0 --token 1234 --u 100 --e 1000 --d 7 --w false
23
25
  npx $0 myDataConfig.js
package/default.js CHANGED
@@ -90,7 +90,7 @@ const config = {
90
90
  ],
91
91
  superProps: {
92
92
  platform: ["web", "mobile", "web", "mobile", "web", "kiosk", "smartTV"],
93
- emotions: generateEmoji(),
93
+ // emotions: generateEmoji(),
94
94
 
95
95
  },
96
96
  /*
@@ -100,7 +100,7 @@ const config = {
100
100
  userProps: {
101
101
  title: chance.profession.bind(chance),
102
102
  luckyNumber: weightedRange(42, 420),
103
- vibe: generateEmoji(),
103
+ // vibe: generateEmoji(),
104
104
  spiritAnimal: chance.animal.bind(chance)
105
105
  },
106
106
 
package/index.js CHANGED
@@ -87,6 +87,11 @@ async function main(config) {
87
87
  VERBOSE = verbose;
88
88
  config.simulationName = makeName();
89
89
  const uuidChance = new Chance(seed);
90
+ log(`------------------SETUP------------------`);
91
+ log(`\nyour data simulation will heretofore be known as: \n\n\t${config.simulationName.toUpperCase()}...\n`);
92
+ log(`and your configuration is:\n`, JSON.stringify({ seed, numEvents, numUsers, numDays, format, token, region, writeToDisk }, null, 2));
93
+ log(`------------------SETUP------------------`, "\n");
94
+
90
95
 
91
96
  //the function which generates $distinct_id + $created, skewing towards the present
92
97
  function uuid() {
@@ -111,12 +116,12 @@ async function main(config) {
111
116
  .reduce((acc, event) => {
112
117
  const weight = event.weight || 1;
113
118
  for (let i = 0; i < weight; i++) {
114
-
119
+
115
120
  acc.push(event);
116
121
  }
117
122
  return acc;
118
123
  }, [])
119
-
124
+
120
125
  .filter((e) => !e.isFirstEvent);
121
126
 
122
127
  const firstEvents = events.filter((e) => e.isFirstEvent);
@@ -128,6 +133,7 @@ async function main(config) {
128
133
  const avgEvPerUser = Math.floor(numEvents / numUsers);
129
134
 
130
135
  //user loop
136
+ log(`---------------SIMULATION----------------`, `\n\n`);
131
137
  for (let i = 1; i < numUsers + 1; i++) {
132
138
  progress("users", i);
133
139
  const user = uuid();
@@ -213,9 +219,9 @@ async function main(config) {
213
219
  [groupFiles, groupProfilesData],
214
220
  [lookupFiles, lookupTableData],
215
221
  ];
216
- log("\n");
217
-
218
- if (!writeToDisk && !token)
222
+ log("\n", `---------------SIMULATION----------------`, "\n");
223
+
224
+ if (!writeToDisk && !token) {
219
225
  return {
220
226
  eventData,
221
227
  userProfilesData,
@@ -223,6 +229,8 @@ async function main(config) {
223
229
  groupProfilesData,
224
230
  lookupTableData,
225
231
  };
232
+ }
233
+ log(`-----------------WRITES------------------`, `\n\n`);
226
234
  //write the files
227
235
  if (writeToDisk) {
228
236
  if (verbose) log(`writing files... for ${config.simulationName}`);
@@ -246,7 +254,8 @@ async function main(config) {
246
254
  await touch(path, csv);
247
255
  log(`\tdone\n`);
248
256
  } else {
249
- await touch(path, data, true);
257
+ const ndjson = data.map((d) => JSON.stringify(d)).join("\n");
258
+ await touch(path, ndjson, true);
250
259
  }
251
260
  }
252
261
  }
@@ -261,7 +270,7 @@ async function main(config) {
261
270
  const creds = { token };
262
271
  /** @type {import('mixpanel-import').Options} */
263
272
  const commonOpts = {
264
-
273
+
265
274
  region,
266
275
  fixData: true,
267
276
  verbose: false,
@@ -302,12 +311,13 @@ async function main(config) {
302
311
  ...commonOpts,
303
312
  });
304
313
  log(`\tsent ${comma(imported.success)} ${groupKey} profiles\n`);
305
-
314
+
306
315
  importResults.groups.push(imported);
307
316
  }
308
317
  }
309
- log(`\n\n`);
318
+
310
319
  }
320
+ log(`-----------------WRITES------------------`, "\n");
311
321
  return {
312
322
  import: importResults,
313
323
  files: [eventFiles, userFiles, scdFiles, groupFiles, lookupFiles, folder],
@@ -362,7 +372,7 @@ function makeSCD(props, distinct_id, mutations, $created) {
362
372
  * @param {Boolean} isFirstEvent=false
363
373
  */
364
374
  function makeEvent(distinct_id, anonymousIds, earliestTime, events, superProps, groupKeys, isFirstEvent = false) {
365
-
375
+
366
376
  let chosenEvent = events.pickOne();
367
377
  if (typeof chosenEvent === "string")
368
378
  chosenEvent = { event: chosenEvent, properties: {} };
@@ -394,7 +404,7 @@ function makeEvent(distinct_id, anonymousIds, earliestTime, events, superProps,
394
404
  for (const groupPair of groupKeys) {
395
405
  const groupKey = groupPair[0];
396
406
  const groupCardinality = groupPair[1];
397
-
407
+
398
408
  event[groupKey] = weightedRange(1, groupCardinality).pickOne();
399
409
  }
400
410
 
@@ -512,7 +522,7 @@ if (require.main === module) {
512
522
 
513
523
  main(config)
514
524
  .then((data) => {
515
- log(`------------------SUMMARY------------------`);
525
+ log(`-----------------SUMMARY-----------------`);
516
526
  const { events, groups, users } = data.import;
517
527
  const files = data.files;
518
528
  const folder = files?.pop();
@@ -530,9 +540,9 @@ if (require.main === module) {
530
540
  bytes: bytesHuman(bytes || 0),
531
541
  };
532
542
  if (bytes > 0) console.table(stats);
533
- log(`\nfiles written to ${folder}...`);
534
- log("\t" + files?.flat().join("\n\t"));
535
- log(`\n------------------SUMMARY------------------\n\n\n`);
543
+ log(`\nfiles written to ${folder} ...`);
544
+ log(" " + files?.flat().join("\n "));
545
+ log(`\n----------------SUMMARY-----------------\n\n\n`);
536
546
  })
537
547
  .catch((e) => {
538
548
  log(`------------------ERROR------------------`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "make-mp-data",
3
- "version": "1.1.0",
3
+ "version": "1.1.11",
4
4
  "description": "builds all mixpanel primitives for a given project",
5
5
  "main": "index.js",
6
6
  "types": "types.d.ts",