make-mp-data 1.5.2 → 1.5.3
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/components/cli.js +1 -1
- package/components/utils.js +32 -7
- package/index.js +7 -6
- package/package.json +1 -1
package/components/cli.js
CHANGED
package/components/utils.js
CHANGED
|
@@ -179,14 +179,14 @@ function day(start, end) {
|
|
|
179
179
|
* @param {ValueValid} value
|
|
180
180
|
*/
|
|
181
181
|
function choose(value) {
|
|
182
|
-
let wasFunctionCalled = false;
|
|
182
|
+
// let wasFunctionCalled = false;
|
|
183
183
|
const chance = getChance();
|
|
184
184
|
|
|
185
185
|
try {
|
|
186
186
|
// Keep resolving the value if it's a function
|
|
187
187
|
while (typeof value === 'function') {
|
|
188
188
|
value = value();
|
|
189
|
-
wasFunctionCalled = true;
|
|
189
|
+
// wasFunctionCalled = true;
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
// allow functions which create arrays of objects to pass through
|
|
@@ -195,12 +195,12 @@ function choose(value) {
|
|
|
195
195
|
// }
|
|
196
196
|
|
|
197
197
|
// Now, if the resolved value is an array, use chance.pickone
|
|
198
|
-
if (Array.isArray(value) &&
|
|
199
|
-
return
|
|
198
|
+
if (Array.isArray(value) && hasSameKeys(value)) {
|
|
199
|
+
return value;
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
-
if (Array.isArray(value)
|
|
203
|
-
return value;
|
|
202
|
+
if (Array.isArray(value)) {
|
|
203
|
+
return chance.pickone(value);
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
if (typeof value === 'string') {
|
|
@@ -221,6 +221,31 @@ function choose(value) {
|
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
+
|
|
225
|
+
function hasSameKeys(arr) {
|
|
226
|
+
if (arr.length <= 1) {
|
|
227
|
+
return true; // An empty array or an array with one object always has the same keys
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const firstKeys = Object.keys(arr[0]);
|
|
231
|
+
|
|
232
|
+
for (let i = 1; i < arr.length; i++) {
|
|
233
|
+
const currentKeys = Object.keys(arr[i]);
|
|
234
|
+
|
|
235
|
+
if (currentKeys.length !== firstKeys.length) {
|
|
236
|
+
return false; // Different number of keys
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
for (const key of firstKeys) {
|
|
240
|
+
if (!currentKeys.includes(key)) {
|
|
241
|
+
return false; // Key missing in current object
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return true; // All objects have the same keys
|
|
247
|
+
}
|
|
248
|
+
|
|
224
249
|
/**
|
|
225
250
|
* keeps picking from an array until the array is exhausted
|
|
226
251
|
* @param {Array} arr
|
|
@@ -1086,7 +1111,7 @@ module.exports = {
|
|
|
1086
1111
|
TimeSoup,
|
|
1087
1112
|
companyName,
|
|
1088
1113
|
generateEmoji,
|
|
1089
|
-
|
|
1114
|
+
haveSameKeys: hasSameKeys,
|
|
1090
1115
|
|
|
1091
1116
|
initChance,
|
|
1092
1117
|
getChance,
|
package/index.js
CHANGED
|
@@ -28,7 +28,7 @@ const timeShift = actualNow.diff(dayjs.unix(FIXED_NOW), "seconds");
|
|
|
28
28
|
const daysShift = actualNow.diff(dayjs.unix(FIXED_NOW), "days");
|
|
29
29
|
|
|
30
30
|
// UTILS
|
|
31
|
-
const { existsSync } = require("fs");
|
|
31
|
+
const { existsSync, writeFileSync } = require("fs");
|
|
32
32
|
const pLimit = require('p-limit');
|
|
33
33
|
const os = require("os");
|
|
34
34
|
const path = require("path");
|
|
@@ -275,7 +275,7 @@ async function main(config) {
|
|
|
275
275
|
log(`---------------SIMULATION----------------`, "\n");
|
|
276
276
|
|
|
277
277
|
// draw charts
|
|
278
|
-
const { makeChart } = config;
|
|
278
|
+
const { makeChart = false } = config;
|
|
279
279
|
if (makeChart) {
|
|
280
280
|
const bornEvents = config.events?.filter((e) => e?.isFirstEvent)?.map(e => e.event) || [];
|
|
281
281
|
const bornFunnels = config.funnels?.filter((f) => f.isFirstFunnel)?.map(f => f.sequence[0]) || [];
|
|
@@ -988,7 +988,7 @@ async function userLoop(config, storage, concurrency = 1) {
|
|
|
988
988
|
const adjustedCreated = userIsBornInDataset ? dayjs(created).subtract(daysShift, 'd') : dayjs.unix(global.FIXED_BEGIN);
|
|
989
989
|
|
|
990
990
|
if (hasLocation) {
|
|
991
|
-
const location = u.choose(DEFAULTS.locationsUsers);
|
|
991
|
+
const location = u.shuffleArray(u.choose(DEFAULTS.locationsUsers)).pop();
|
|
992
992
|
for (const key in location) {
|
|
993
993
|
user[key] = location[key];
|
|
994
994
|
}
|
|
@@ -1236,7 +1236,7 @@ async function sendToMixpanel(config, storage) {
|
|
|
1236
1236
|
scdLabel: `${scdKey}-scd`,
|
|
1237
1237
|
...commonOpts,
|
|
1238
1238
|
};
|
|
1239
|
-
if (scdEntity.entityType !== "user") options.groupKey = scdEntity.entityType
|
|
1239
|
+
if (scdEntity.entityType !== "user") options.groupKey = scdEntity.entityType;
|
|
1240
1240
|
const imported = await mp(
|
|
1241
1241
|
{
|
|
1242
1242
|
token,
|
|
@@ -1661,8 +1661,9 @@ if (NODE_ENV !== "prod") {
|
|
|
1661
1661
|
bytes: bytesHuman(bytes || 0),
|
|
1662
1662
|
};
|
|
1663
1663
|
if (bytes > 0) console.table(stats);
|
|
1664
|
-
log(`\
|
|
1665
|
-
|
|
1664
|
+
log(`\nlog written to ${folder} ...`);
|
|
1665
|
+
writeFileSync(path.join(folder, "log.txt"), JSON.stringify(data?.importResults, null, 2));
|
|
1666
|
+
// log(" " + files?.flat().join("\n "));
|
|
1666
1667
|
log(`\n----------------SUMMARY-----------------\n\n\n`);
|
|
1667
1668
|
})
|
|
1668
1669
|
.catch((e) => {
|