make-mp-data 1.2.1 → 1.2.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.
- package/README.md +24 -4
- package/index.js +18 -15
- package/package.json +1 -1
- package/tests/unit.test.js +1 -3
- package/utils.js +22 -18
package/README.md
CHANGED
|
@@ -5,13 +5,33 @@ a quick and dirty CLI in node.js to generate fake data for mixpanel.
|
|
|
5
5
|
|
|
6
6
|
## tldr;
|
|
7
7
|
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx make-mp-data
|
|
11
|
+
```
|
|
12
|
+
- makes events + users (and writes them to CSVs)
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npx make-mp-data --numUsers 100 --numEvents 10000 --days 90 --format json
|
|
16
|
+
```
|
|
17
|
+
- makes ~10k events + 100 users from the last 90 days (but writes JSON)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npx make-mp-data --complex
|
|
22
|
+
```
|
|
23
|
+
- makes events + users + groups + scd + lookup tables
|
|
24
|
+
- this includes every type of data that mixpanel supports
|
|
25
|
+
|
|
8
26
|
```bash
|
|
9
27
|
npx make-mp-data --token 1234
|
|
10
28
|
```
|
|
11
|
-
- makes events
|
|
12
|
-
- makes lookup tables and SCD type 2 exported as CSVs
|
|
29
|
+
- makes events + users (and send them to mixpanel)
|
|
13
30
|
|
|
14
|
-
|
|
31
|
+
```bash
|
|
32
|
+
npx make-mp-data --help
|
|
33
|
+
```
|
|
34
|
+
- explains all the options you can specify
|
|
15
35
|
|
|
16
36
|
## customization
|
|
17
37
|
|
|
@@ -26,5 +46,5 @@ npx make-mp-data ecommSpec.js --token 1234 --numDays 30 --numUsers 1000 --numEve
|
|
|
26
46
|
|
|
27
47
|
see `--help` for a full list of options
|
|
28
48
|
|
|
29
|
-
see `./models/` for a few `dataModel.js
|
|
49
|
+
see `./models/` for a few `dataModel.js` examples...
|
|
30
50
|
|
package/index.js
CHANGED
|
@@ -61,7 +61,7 @@ async function main(config) {
|
|
|
61
61
|
const uuidChance = new Chance(seed);
|
|
62
62
|
log(`------------------SETUP------------------`);
|
|
63
63
|
log(`\nyour data simulation will heretofore be known as: \n\n\t${config.simulationName.toUpperCase()}...\n`);
|
|
64
|
-
log(`and your configuration is:\n`, JSON.stringify({ seed, numEvents, numUsers, numDays, format, token, region, writeToDisk }, null, 2));
|
|
64
|
+
log(`and your configuration is:\n\n`, JSON.stringify({ seed, numEvents, numUsers, numDays, format, token, region, writeToDisk }, null, 2));
|
|
65
65
|
log(`------------------SETUP------------------`, "\n");
|
|
66
66
|
|
|
67
67
|
|
|
@@ -116,7 +116,7 @@ async function main(config) {
|
|
|
116
116
|
const numEventsThisUser = Math.round(
|
|
117
117
|
chance.normal({ mean: avgEvPerUser, dev: avgEvPerUser / u.integer(3, 7) })
|
|
118
118
|
);
|
|
119
|
-
|
|
119
|
+
|
|
120
120
|
if (firstEvents.length) {
|
|
121
121
|
eventData.push(
|
|
122
122
|
makeEvent(
|
|
@@ -147,6 +147,7 @@ async function main(config) {
|
|
|
147
147
|
);
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
|
+
|
|
150
151
|
//flatten SCD
|
|
151
152
|
scdTableData = scdTableData.flat();
|
|
152
153
|
|
|
@@ -193,7 +194,8 @@ async function main(config) {
|
|
|
193
194
|
[groupFiles, groupProfilesData],
|
|
194
195
|
[lookupFiles, lookupTableData],
|
|
195
196
|
];
|
|
196
|
-
log("\n"
|
|
197
|
+
log("\n")
|
|
198
|
+
log(`---------------SIMULATION----------------`, "\n");
|
|
197
199
|
|
|
198
200
|
if (!writeToDisk && !token) {
|
|
199
201
|
return {
|
|
@@ -207,7 +209,7 @@ async function main(config) {
|
|
|
207
209
|
log(`-----------------WRITES------------------`, `\n\n`);
|
|
208
210
|
//write the files
|
|
209
211
|
if (writeToDisk) {
|
|
210
|
-
if (verbose) log(`writing files... for ${config.simulationName}
|
|
212
|
+
if (verbose) log(`writing files... for ${config.simulationName}`);
|
|
211
213
|
loopFiles: for (const pair of pairs) {
|
|
212
214
|
const [paths, data] = pair;
|
|
213
215
|
if (!data.length) continue loopFiles;
|
|
@@ -218,7 +220,7 @@ async function main(config) {
|
|
|
218
220
|
for (const writeData of datasetsToWrite) {
|
|
219
221
|
//if it's a lookup table, it's always a CSV
|
|
220
222
|
if (format === "csv" || path.includes("-LOOKUP.csv")) {
|
|
221
|
-
log(
|
|
223
|
+
log(`\twriting ${path}`);
|
|
222
224
|
const columns = u.getUniqueKeys(writeData);
|
|
223
225
|
//papa parse needs nested JSON stringified
|
|
224
226
|
writeData.forEach((e) => {
|
|
@@ -228,7 +230,6 @@ async function main(config) {
|
|
|
228
230
|
});
|
|
229
231
|
const csv = Papa.unparse(writeData, { columns });
|
|
230
232
|
await touch(path, csv);
|
|
231
|
-
log(`\tdone\n`);
|
|
232
233
|
} else {
|
|
233
234
|
const ndjson = data.map((d) => JSON.stringify(d)).join("\n");
|
|
234
235
|
await touch(path, ndjson, false);
|
|
@@ -293,7 +294,7 @@ async function main(config) {
|
|
|
293
294
|
}
|
|
294
295
|
|
|
295
296
|
}
|
|
296
|
-
log(
|
|
297
|
+
log(`\n-----------------WRITES------------------`, "\n");
|
|
297
298
|
return {
|
|
298
299
|
import: importResults,
|
|
299
300
|
files: [eventFiles, userFiles, scdFiles, groupFiles, lookupFiles, folder],
|
|
@@ -311,7 +312,7 @@ function makeProfile(props, defaults) {
|
|
|
311
312
|
|
|
312
313
|
for (const key in props) {
|
|
313
314
|
try {
|
|
314
|
-
profile[key] = choose(props[key]);
|
|
315
|
+
profile[key] = u.choose(props[key]);
|
|
315
316
|
} catch (e) {
|
|
316
317
|
// debugger;
|
|
317
318
|
}
|
|
@@ -451,21 +452,23 @@ if (require.main === module) {
|
|
|
451
452
|
const suppliedConfig = args._[0];
|
|
452
453
|
|
|
453
454
|
//if the user specifics an separate config file
|
|
455
|
+
//todo this text isn't displaying
|
|
454
456
|
let config = null;
|
|
455
457
|
if (suppliedConfig) {
|
|
456
|
-
log(`using ${suppliedConfig} for data\n`);
|
|
458
|
+
console.log(`using ${suppliedConfig} for data\n`);
|
|
457
459
|
config = require(path.resolve(suppliedConfig));
|
|
458
460
|
}
|
|
459
461
|
else {
|
|
460
462
|
if (complex) {
|
|
461
|
-
log(`... using default COMPLEX configuration [everything] ...\n`);
|
|
462
|
-
log(`... for more simple data, don't use the --complex flag ...\n`);
|
|
463
|
-
config
|
|
463
|
+
console.log(`... using default COMPLEX configuration [everything] ...\n`);
|
|
464
|
+
console.log(`... for more simple data, don't use the --complex flag ...\n`);
|
|
465
|
+
console.log(`... or specify your own js config file (see docs or --help) ...\n`);
|
|
466
|
+
config = require(path.resolve(__dirname, "./models/complex.js"));
|
|
464
467
|
}
|
|
465
468
|
else {
|
|
466
|
-
log(`... using default SIMPLE configuration [events + users] ...\n`);
|
|
467
|
-
log(`... for more complex data, use the --complex flag ...\n`);
|
|
468
|
-
config = require(path.resolve("./models/simple.js"));
|
|
469
|
+
console.log(`... using default SIMPLE configuration [events + users] ...\n`);
|
|
470
|
+
console.log(`... for more complex data, use the --complex flag ...\n`);
|
|
471
|
+
config = require(path.resolve(__dirname, "./models/simple.js"));
|
|
469
472
|
}
|
|
470
473
|
}
|
|
471
474
|
|
package/package.json
CHANGED
package/tests/unit.test.js
CHANGED
|
@@ -70,9 +70,7 @@ describe('utils', () => {
|
|
|
70
70
|
const generatedPerson = person();
|
|
71
71
|
expect(generatedPerson).toHaveProperty('$name');
|
|
72
72
|
expect(generatedPerson).toHaveProperty('$email');
|
|
73
|
-
expect(generatedPerson).toHaveProperty('$avatar');
|
|
74
|
-
expect(generatedPerson).toHaveProperty('anonymousIds');
|
|
75
|
-
expect(generatedPerson.anonymousIds).toBeInstanceOf(Array);
|
|
73
|
+
expect(generatedPerson).toHaveProperty('$avatar');
|
|
76
74
|
});
|
|
77
75
|
|
|
78
76
|
|
package/utils.js
CHANGED
|
@@ -285,30 +285,34 @@ function person(bornDaysAgo = 30) {
|
|
|
285
285
|
const $avatar = avatarPrefix + avPath;
|
|
286
286
|
const $created = date(bornDaysAgo, true, null)();
|
|
287
287
|
|
|
288
|
+
const user = {
|
|
289
|
+
$name,
|
|
290
|
+
$email,
|
|
291
|
+
$avatar,
|
|
292
|
+
$created,
|
|
293
|
+
};
|
|
294
|
+
|
|
288
295
|
//anon Ids
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
296
|
+
if (global.MP_SIMULATION_CONFIG?.anonIds) {
|
|
297
|
+
const anonymousIds = [];
|
|
298
|
+
const clusterSize = integer(2, 10);
|
|
299
|
+
for (let i = 0; i < clusterSize; i++) {
|
|
300
|
+
anonymousIds.push(uid(42));
|
|
301
|
+
}
|
|
302
|
+
user.anonymousIds = anonymousIds;
|
|
293
303
|
}
|
|
294
304
|
|
|
295
305
|
//session Ids
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
306
|
+
if (global.MP_SIMULATION_CONFIG?.sessionIds) {
|
|
307
|
+
const sessionIds = [];
|
|
308
|
+
const sessionSize = integer(5, 30);
|
|
309
|
+
for (let i = 0; i < sessionSize; i++) {
|
|
310
|
+
sessionIds.push([uid(5), uid(5), uid(5), uid(5)].join("-"));
|
|
311
|
+
}
|
|
312
|
+
user.sessionIds = sessionIds;
|
|
300
313
|
}
|
|
301
314
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
return {
|
|
305
|
-
$name,
|
|
306
|
-
$email,
|
|
307
|
-
$avatar,
|
|
308
|
-
$created,
|
|
309
|
-
anonymousIds,
|
|
310
|
-
sessionIds
|
|
311
|
-
};
|
|
315
|
+
return user;
|
|
312
316
|
};
|
|
313
317
|
|
|
314
318
|
|