make-mp-data 2.1.4 → 2.1.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/dungeons/foobar.js +100 -100
- package/dungeons/simple.js +1 -1
- package/lib/core/storage.js +5 -3
- package/lib/generators/adspend.js +25 -10
- package/lib/orchestrators/user-loop.js +3 -3
- package/package.json +4 -4
package/dungeons/foobar.js
CHANGED
|
@@ -25,106 +25,106 @@ function integer(min = 1, max = 100) {
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
const dates = [
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
"
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
"
|
|
104
|
-
"
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
"
|
|
108
|
-
"
|
|
109
|
-
"
|
|
110
|
-
"
|
|
111
|
-
"
|
|
112
|
-
"
|
|
113
|
-
"
|
|
114
|
-
"
|
|
115
|
-
"
|
|
116
|
-
"
|
|
117
|
-
"
|
|
118
|
-
"
|
|
119
|
-
"
|
|
120
|
-
"
|
|
121
|
-
"
|
|
122
|
-
"
|
|
123
|
-
"
|
|
124
|
-
"
|
|
125
|
-
"
|
|
126
|
-
"
|
|
127
|
-
"
|
|
28
|
+
"2026-09-18T21:48:28.173Z",
|
|
29
|
+
"2026-12-09T03:17:46.661Z",
|
|
30
|
+
"2026-02-26T07:52:14.943Z",
|
|
31
|
+
"2026-04-22T08:35:17.647Z",
|
|
32
|
+
"2026-11-25T17:03:58.061Z",
|
|
33
|
+
"2026-01-14T21:46:58.982Z",
|
|
34
|
+
"2026-06-20T12:47:25.687Z",
|
|
35
|
+
"2026-08-13T22:18:08.665Z",
|
|
36
|
+
"2026-08-09T07:47:18.321Z",
|
|
37
|
+
"2026-06-21T19:04:43.432Z",
|
|
38
|
+
"2026-03-09T00:18:37.705Z",
|
|
39
|
+
"2026-08-02T09:23:41.699Z",
|
|
40
|
+
"2026-11-26T13:25:08.673Z",
|
|
41
|
+
"2026-05-23T11:51:34.238Z",
|
|
42
|
+
"2026-10-24T20:14:05.106Z",
|
|
43
|
+
"2026-10-01T18:52:32.463Z",
|
|
44
|
+
"2026-10-15T19:22:40.675Z",
|
|
45
|
+
"2026-06-13T21:29:11.962Z",
|
|
46
|
+
"2026-08-29T12:02:48.632Z",
|
|
47
|
+
"2026-12-22T12:11:40.809Z",
|
|
48
|
+
"2026-01-03T03:39:19.446Z",
|
|
49
|
+
"2026-06-28T10:05:43.908Z",
|
|
50
|
+
"2026-12-01T18:49:00.447Z",
|
|
51
|
+
"2026-12-30T05:44:23.418Z",
|
|
52
|
+
"2026-03-14T22:38:40.833Z",
|
|
53
|
+
"2026-12-28T06:45:31.946Z",
|
|
54
|
+
"2026-07-20T21:40:19.498Z",
|
|
55
|
+
"2026-12-26T06:44:41.982Z",
|
|
56
|
+
"2026-10-28T13:45:35.409Z",
|
|
57
|
+
"2026-02-28T00:11:54.916Z",
|
|
58
|
+
"2026-07-08T10:01:57.834Z",
|
|
59
|
+
"2026-02-23T08:00:59.386Z",
|
|
60
|
+
"2026-08-20T05:23:33.024Z",
|
|
61
|
+
"2026-02-10T20:52:46.564Z",
|
|
62
|
+
"2026-08-24T21:32:15.202Z",
|
|
63
|
+
"2026-06-17T03:51:35.142Z",
|
|
64
|
+
"2026-04-09T13:13:45.218Z",
|
|
65
|
+
"2026-07-26T16:31:51.091Z",
|
|
66
|
+
"2026-05-26T04:06:33.013Z",
|
|
67
|
+
"2026-11-05T17:15:37.412Z",
|
|
68
|
+
"2026-10-20T17:01:38.205Z",
|
|
69
|
+
"2026-01-08T05:09:18.692Z",
|
|
70
|
+
"2026-08-24T13:52:14.774Z",
|
|
71
|
+
"2026-06-26T13:47:07.276Z",
|
|
72
|
+
"2026-06-19T15:05:53.246Z",
|
|
73
|
+
"2026-05-01T04:06:52.028Z",
|
|
74
|
+
"2026-05-26T22:45:59.626Z",
|
|
75
|
+
"2026-04-17T20:50:58.460Z",
|
|
76
|
+
"2026-07-28T04:32:04.578Z",
|
|
77
|
+
"2026-01-29T05:31:48.744Z",
|
|
78
|
+
"2026-08-06T18:47:29.190Z",
|
|
79
|
+
"2026-04-03T23:12:20.415Z",
|
|
80
|
+
"2026-09-13T08:47:35.938Z",
|
|
81
|
+
"2026-07-27T15:12:15.145Z",
|
|
82
|
+
"2026-10-24T00:39:21.835Z",
|
|
83
|
+
"2026-10-08T16:50:36.591Z",
|
|
84
|
+
"2026-02-27T15:53:19.204Z",
|
|
85
|
+
"2026-04-21T08:24:05.883Z",
|
|
86
|
+
"2026-03-08T10:07:46.720Z",
|
|
87
|
+
"2026-01-10T08:36:19.554Z",
|
|
88
|
+
"2026-02-17T12:56:00.562Z",
|
|
89
|
+
"2026-10-03T07:54:46.486Z",
|
|
90
|
+
"2026-05-29T10:18:36.289Z",
|
|
91
|
+
"2026-05-06T23:27:07.145Z",
|
|
92
|
+
"2026-05-27T08:41:47.787Z",
|
|
93
|
+
"2026-09-16T12:22:09.573Z",
|
|
94
|
+
"2026-05-03T00:31:06.036Z",
|
|
95
|
+
"2026-11-24T19:38:43.380Z",
|
|
96
|
+
"2026-06-03T04:01:56.328Z",
|
|
97
|
+
"2026-05-04T02:25:25.455Z",
|
|
98
|
+
"2026-12-19T18:35:25.052Z",
|
|
99
|
+
"2026-05-07T21:54:28.113Z",
|
|
100
|
+
"2026-11-24T09:58:08.766Z",
|
|
101
|
+
"2026-03-17T02:46:20.903Z",
|
|
102
|
+
"2026-09-04T09:20:24.930Z",
|
|
103
|
+
"2026-02-04T10:23:33.624Z",
|
|
104
|
+
"2026-01-26T02:42:06.668Z",
|
|
105
|
+
"2026-08-11T02:26:21.969Z",
|
|
106
|
+
"2026-07-11T13:34:51.283Z",
|
|
107
|
+
"2026-12-20T00:09:10.080Z",
|
|
108
|
+
"2026-05-28T00:20:07.079Z",
|
|
109
|
+
"2026-01-13T14:54:03.339Z",
|
|
110
|
+
"2026-08-10T17:18:12.759Z",
|
|
111
|
+
"2026-10-06T15:05:11.437Z",
|
|
112
|
+
"2026-11-18T03:53:12.932Z",
|
|
113
|
+
"2026-02-19T18:06:13.680Z",
|
|
114
|
+
"2026-08-03T11:48:00.207Z",
|
|
115
|
+
"2026-11-22T15:19:47.316Z",
|
|
116
|
+
"2026-06-30T19:56:49.636Z",
|
|
117
|
+
"2026-12-03T00:25:23.926Z",
|
|
118
|
+
"2026-07-30T15:27:18.198Z",
|
|
119
|
+
"2026-09-07T01:40:58.245Z",
|
|
120
|
+
"2026-05-16T05:24:14.727Z",
|
|
121
|
+
"2026-11-14T03:46:49.323Z",
|
|
122
|
+
"2026-02-16T09:18:23.473Z",
|
|
123
|
+
"2026-10-19T14:07:11.462Z",
|
|
124
|
+
"2026-02-09T08:52:04.735Z",
|
|
125
|
+
"2026-06-06T09:41:11.810Z",
|
|
126
|
+
"2026-05-07T23:14:05.114Z",
|
|
127
|
+
"2026-06-03T06:52:21.652Z"
|
|
128
128
|
];
|
|
129
129
|
|
|
130
130
|
const billionsOfEvents = 2
|
package/dungeons/simple.js
CHANGED
|
@@ -31,7 +31,7 @@ const config = {
|
|
|
31
31
|
region: "US",
|
|
32
32
|
hasAnonIds: false, //if true, anonymousIds are created for each user
|
|
33
33
|
hasSessionIds: false, //if true, hasSessionIds are created for each user
|
|
34
|
-
hasAdSpend:
|
|
34
|
+
hasAdSpend: true,
|
|
35
35
|
hasLocation: true,
|
|
36
36
|
hasAndroidDevices: false,
|
|
37
37
|
hasIOSDevices: false,
|
package/lib/core/storage.js
CHANGED
|
@@ -91,7 +91,9 @@ export async function createHookArray(arr = [], opts) {
|
|
|
91
91
|
if (isPassthroughHook) {
|
|
92
92
|
// Fast path for passthrough hooks - no transformation needed
|
|
93
93
|
if (Array.isArray(item)) {
|
|
94
|
-
|
|
94
|
+
for (let i = 0; i < item.length; i++) {
|
|
95
|
+
arr.push(item[i]);
|
|
96
|
+
}
|
|
95
97
|
} else {
|
|
96
98
|
arr.push(item);
|
|
97
99
|
}
|
|
@@ -132,7 +134,7 @@ export async function createHookArray(arr = [], opts) {
|
|
|
132
134
|
|
|
133
135
|
try {
|
|
134
136
|
// Create a copy of the data to write
|
|
135
|
-
const dataToWrite =
|
|
137
|
+
const dataToWrite = arr.slice();
|
|
136
138
|
// Clear the array immediately to prevent race conditions
|
|
137
139
|
arr.length = 0;
|
|
138
140
|
|
|
@@ -188,7 +190,7 @@ export async function createHookArray(arr = [], opts) {
|
|
|
188
190
|
try {
|
|
189
191
|
batch++;
|
|
190
192
|
const writePath = getWritePath();
|
|
191
|
-
const dataToWrite =
|
|
193
|
+
const dataToWrite = arr.slice();
|
|
192
194
|
arr.length = 0; // Clear array after copying data
|
|
193
195
|
await FILE_CONN(() => writeToDisk(dataToWrite, { writePath }));
|
|
194
196
|
} finally {
|
|
@@ -18,26 +18,35 @@ import * as u from "../utils/utils.js";
|
|
|
18
18
|
export async function makeAdSpend(context, day, campaigns = null) {
|
|
19
19
|
// Update operation counter
|
|
20
20
|
context.incrementOperations();
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
// Use campaigns from context if not provided
|
|
23
23
|
const campaignConfigs = campaigns || context.campaigns;
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
if (!campaignConfigs || campaignConfigs.length === 0) {
|
|
26
26
|
return [];
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
const chance = u.getChance();
|
|
30
30
|
const adSpendEvents = [];
|
|
31
|
-
|
|
31
|
+
|
|
32
|
+
// Determine if we should apply time shift
|
|
33
|
+
// Only shift if the date is in the historical "fixed" range (before 2025)
|
|
34
|
+
const dayTimestamp = dayjs(day).unix();
|
|
35
|
+
const CUTOFF_DATE = dayjs('2025-01-01').unix(); // Dates before 2025 are considered "fixed" range
|
|
36
|
+
const shouldShift = dayTimestamp < CUTOFF_DATE;
|
|
37
|
+
|
|
38
|
+
// Get time shift from context, but only use it if we should shift
|
|
39
|
+
const timeShiftSeconds = shouldShift ? (context.TIME_SHIFT_SECONDS || 0) : 0;
|
|
40
|
+
|
|
32
41
|
for (const network of campaignConfigs) {
|
|
33
42
|
const networkCampaigns = network.utm_campaign;
|
|
34
|
-
|
|
43
|
+
|
|
35
44
|
for (const campaign of networkCampaigns) {
|
|
36
45
|
// Skip organic campaigns
|
|
37
46
|
if (campaign === "$organic") continue;
|
|
38
47
|
|
|
39
|
-
// Generate realistic ad spend metrics
|
|
40
|
-
const adSpendEvent = createAdSpendEvent(network, campaign, day, chance);
|
|
48
|
+
// Generate realistic ad spend metrics with conditional time shift
|
|
49
|
+
const adSpendEvent = createAdSpendEvent(network, campaign, day, chance, timeShiftSeconds);
|
|
41
50
|
adSpendEvents.push(adSpendEvent);
|
|
42
51
|
}
|
|
43
52
|
}
|
|
@@ -51,9 +60,15 @@ export async function makeAdSpend(context, day, campaigns = null) {
|
|
|
51
60
|
* @param {string} campaign - Campaign name
|
|
52
61
|
* @param {string} day - ISO date string
|
|
53
62
|
* @param {Object} chance - Chance.js instance
|
|
63
|
+
* @param {number} timeShiftSeconds - Time shift in seconds to apply to timestamps (default: 0)
|
|
54
64
|
* @returns {Object} Ad spend event object
|
|
55
65
|
*/
|
|
56
|
-
function createAdSpendEvent(network, campaign, day, chance) {
|
|
66
|
+
function createAdSpendEvent(network, campaign, day, chance, timeShiftSeconds = 0) {
|
|
67
|
+
// Apply time shift to the day timestamp
|
|
68
|
+
const dayTimestamp = dayjs(day).unix();
|
|
69
|
+
const shiftedTimestamp = dayTimestamp + timeShiftSeconds;
|
|
70
|
+
const shiftedDay = dayjs.unix(shiftedTimestamp).toISOString();
|
|
71
|
+
|
|
57
72
|
// Generate realistic cost
|
|
58
73
|
const cost = chance.floating({ min: 10, max: 250, fixed: 2 });
|
|
59
74
|
|
|
@@ -77,7 +92,7 @@ function createAdSpendEvent(network, campaign, day, chance) {
|
|
|
77
92
|
|
|
78
93
|
return {
|
|
79
94
|
event: "$ad_spend",
|
|
80
|
-
time:
|
|
95
|
+
time: shiftedDay, // Use shifted timestamp
|
|
81
96
|
// source: 'dm4',
|
|
82
97
|
utm_campaign: campaign,
|
|
83
98
|
campaign_id: id,
|
|
@@ -92,7 +107,7 @@ function createAdSpendEvent(network, campaign, day, chance) {
|
|
|
92
107
|
views,
|
|
93
108
|
impressions,
|
|
94
109
|
cost,
|
|
95
|
-
date: dayjs(
|
|
110
|
+
date: dayjs.unix(shiftedTimestamp).format("YYYY-MM-DD"), // Also use shifted timestamp for date
|
|
96
111
|
};
|
|
97
112
|
}
|
|
98
113
|
|
|
@@ -149,7 +149,7 @@ export async function userLoop(context) {
|
|
|
149
149
|
const timeShift = context.getTimeShift();
|
|
150
150
|
userFirstEventTime = dayjs(data[0].time).subtract(timeShift, 'seconds').unix();
|
|
151
151
|
numEventsPreformed += data.length;
|
|
152
|
-
usersEvents
|
|
152
|
+
usersEvents.push(...data);
|
|
153
153
|
|
|
154
154
|
if (!userConverted) {
|
|
155
155
|
// if (verbose) {
|
|
@@ -167,11 +167,11 @@ export async function userLoop(context) {
|
|
|
167
167
|
const currentFunnel = chance.pickone(usageFunnels);
|
|
168
168
|
const [data, userConverted] = await makeFunnel(context, currentFunnel, user, userFirstEventTime, profile, userSCD);
|
|
169
169
|
numEventsPreformed += data.length;
|
|
170
|
-
usersEvents
|
|
170
|
+
usersEvents.push(...data);
|
|
171
171
|
} else {
|
|
172
172
|
const data = await makeEvent(context, distinct_id, userFirstEventTime, u.pick(config.events), user.anonymousIds, user.sessionIds, {}, config.groupKeys, true);
|
|
173
173
|
numEventsPreformed++;
|
|
174
|
-
usersEvents
|
|
174
|
+
usersEvents.push(data);
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
177
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "make-mp-data",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.6",
|
|
4
4
|
"description": "builds all mixpanel primitives for a given project",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -62,15 +62,15 @@
|
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"@google-cloud/functions-framework": "^3.4.2",
|
|
64
64
|
"@google-cloud/storage": "^7.14.0",
|
|
65
|
-
"ak-fetch": "^2.0.
|
|
66
|
-
"ak-gemini": "^1.
|
|
65
|
+
"ak-fetch": "^2.0.15",
|
|
66
|
+
"ak-gemini": "^1.1.13",
|
|
67
67
|
"ak-tools": "^1.1.12",
|
|
68
68
|
"chance": "^1.1.11",
|
|
69
69
|
"dayjs": "^1.11.11",
|
|
70
70
|
"dotenv": "^16.4.5",
|
|
71
71
|
"google-auth-library": "^9.15.0",
|
|
72
72
|
"hyparquet-writer": "^0.6.1",
|
|
73
|
-
"mixpanel-import": "^3.
|
|
73
|
+
"mixpanel-import": "^3.2.7",
|
|
74
74
|
"p-limit": "^3.1.0",
|
|
75
75
|
"seedrandom": "^3.0.5",
|
|
76
76
|
"sentiment": "^5.0.2",
|