@ak--47/dungeon-master 1.0.0
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 +518 -0
- package/dungeons/array-of-object-lookup-schema.json +327 -0
- package/dungeons/array-of-object-lookup.js +220 -0
- package/dungeons/ecommerce-schema.json +462 -0
- package/dungeons/ecommerce.js +447 -0
- package/dungeons/education-schema.json +2409 -0
- package/dungeons/education.js +768 -0
- package/dungeons/fintech-schema.json +14034 -0
- package/dungeons/fintech.js +696 -0
- package/dungeons/foobar-schema.json +403 -0
- package/dungeons/foobar.js +296 -0
- package/dungeons/food-delivery-schema.json +192 -0
- package/dungeons/food-delivery.js +602 -0
- package/dungeons/food-schema.json +1152 -0
- package/dungeons/food.js +754 -0
- package/dungeons/gaming-schema.json +1270 -0
- package/dungeons/gaming.js +508 -0
- package/dungeons/insurance-application-schema.json +204 -0
- package/dungeons/insurance-application.js +605 -0
- package/dungeons/media-schema.json +906 -0
- package/dungeons/media.js +790 -0
- package/dungeons/retention-cadence-schema.json +78 -0
- package/dungeons/retention-cadence.js +244 -0
- package/dungeons/rpg-schema.json +4526 -0
- package/dungeons/rpg.js +919 -0
- package/dungeons/sanity-schema.json +255 -0
- package/dungeons/sanity.js +152 -0
- package/dungeons/sass-schema.json +1291 -0
- package/dungeons/sass.js +795 -0
- package/dungeons/scd-schema.json +919 -0
- package/dungeons/scd.js +277 -0
- package/dungeons/simple-schema.json +608 -0
- package/dungeons/simple.js +285 -0
- package/dungeons/simplest-schema.json +1418 -0
- package/dungeons/simplest.js +392 -0
- package/dungeons/social-schema.json +1118 -0
- package/dungeons/social.js +686 -0
- package/dungeons/text-generation-schema.json +3096 -0
- package/dungeons/text-generation.js +812 -0
- package/index.js +567 -0
- package/lib/core/config-validator.js +395 -0
- package/lib/core/context.js +204 -0
- package/lib/core/dungeon-loader.js +337 -0
- package/lib/core/storage.js +379 -0
- package/lib/generators/adspend.js +132 -0
- package/lib/generators/events.js +271 -0
- package/lib/generators/funnels.js +407 -0
- package/lib/generators/mirror.js +167 -0
- package/lib/generators/product-lookup.js +262 -0
- package/lib/generators/product-names.js +195 -0
- package/lib/generators/profiles.js +93 -0
- package/lib/generators/scd.js +124 -0
- package/lib/generators/text.js +1192 -0
- package/lib/orchestrators/mixpanel-sender.js +266 -0
- package/lib/orchestrators/user-loop.js +335 -0
- package/lib/templates/abbreviated.d.ts +169 -0
- package/lib/templates/defaults.js +1405 -0
- package/lib/templates/phrases.js +2526 -0
- package/lib/templates/schema.d.ts +173 -0
- package/lib/templates/soup-presets.js +188 -0
- package/lib/utils/function-registry.js +302 -0
- package/lib/utils/json-evaluator.js +172 -0
- package/lib/utils/logger.js +34 -0
- package/lib/utils/utils.js +1490 -0
- package/package.json +89 -0
- package/types.d.ts +865 -0
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
import Chance from 'chance';
|
|
2
|
+
let chance = new Chance();
|
|
3
|
+
import dayjs from "dayjs";
|
|
4
|
+
import utc from "dayjs/plugin/utc.js";
|
|
5
|
+
dayjs.extend(utc);
|
|
6
|
+
import { uid, comma } from 'ak-tools';
|
|
7
|
+
import { pickAWinner, weighNumRange, date, integer, weighChoices, decimal } from "../lib/utils/utils.js";
|
|
8
|
+
|
|
9
|
+
const itemCategories = ["Books", "Movies", "Music", "Games", "Electronics", "Computers", "Smart Home", "Home", "Garden", "Pet", "Beauty", "Health", "Toys", "Kids", "Baby", "Handmade", "Sports", "Outdoors", "Automotive", "Industrial", "Entertainment", "Art", "Food", "Appliances", "Office", "Wedding", "Software"];
|
|
10
|
+
const videoCategories = ["funny", "educational", "inspirational", "music", "news", "sports", "cooking", "DIY", "travel", "gaming"];
|
|
11
|
+
const spiritAnimals = ["duck", "dog", "otter", "penguin", "cat", "elephant", "lion", "cheetah", "giraffe", "zebra", "rhino", "hippo", "whale", "dolphin", "shark", "octopus", "squid", "jellyfish", "starfish", "seahorse", "crab", "lobster", "shrimp", "clam", "snail", "slug", "butterfly", "moth", "bee", "wasp", "ant", "beetle", "ladybug", "caterpillar", "centipede", "millipede", "scorpion", "spider", "tarantula", "tick", "mite", "mosquito", "fly", "dragonfly", "damselfly", "grasshopper", "cricket", "locust", "mantis", "cockroach", "termite", "praying mantis", "walking stick", "stick bug", "leaf insect", "lacewing", "aphid", "cicada", "thrips", "psyllid", "scale insect", "whitefly", "mealybug", "planthopper", "leafhopper", "treehopper", "flea", "louse", "bedbug", "flea beetle", "weevil", "longhorn beetle", "leaf beetle", "tiger beetle", "ground beetle", "lady beetle", "firefly", "click beetle", "rove beetle", "scarab beetle", "dung beetle", "stag beetle", "rhinoceros beetle", "hercules beetle", "goliath beetle", "jewel beetle", "tortoise beetle"];
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
* ============================================================================
|
|
15
|
+
* DATASET OVERVIEW
|
|
16
|
+
* ============================================================================
|
|
17
|
+
*
|
|
18
|
+
* App: eCommerce marketplace with integrated video content
|
|
19
|
+
* Scale: 50K users, 2M events, 108 days
|
|
20
|
+
*
|
|
21
|
+
* Core loop: Users browse products, watch videos, build carts, and check out.
|
|
22
|
+
* A signup funnel converts browsers into registered users. Video engagement
|
|
23
|
+
* (likes/dislikes) runs alongside the shopping flow.
|
|
24
|
+
*
|
|
25
|
+
* Events:
|
|
26
|
+
* page view (10) > view item (8) > watch video (8) > like video (6)
|
|
27
|
+
* > save item (5) > add to cart (4) > dislike video (4) > checkout (2) > sign up (1)
|
|
28
|
+
*
|
|
29
|
+
* Funnels:
|
|
30
|
+
* - Signup Flow: page view → view item → save item → page view → sign up (50%)
|
|
31
|
+
* - Video Likes: watch → like → watch → like (60%)
|
|
32
|
+
* - Video Dislikes: watch → dislike → watch → dislike (20%)
|
|
33
|
+
* - eCommerce Purchase: view → view → add to cart → view → add to cart → checkout (15%)
|
|
34
|
+
*
|
|
35
|
+
* User props: title, luckyNumber, spiritAnimal
|
|
36
|
+
* Super props: theme (light/dark/custom)
|
|
37
|
+
* ============================================================================
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/*
|
|
41
|
+
* ============================================================================
|
|
42
|
+
* ANALYTICS HOOKS
|
|
43
|
+
* ============================================================================
|
|
44
|
+
*
|
|
45
|
+
* Hook 1: Signup Flow Improvement
|
|
46
|
+
* Type: event + everything (tag-and-filter)
|
|
47
|
+
* What: 7 days ago, signup flow switches from "v1" to "v2". Before that date,
|
|
48
|
+
* 50% of sign ups are tagged _drop and removed in the everything hook,
|
|
49
|
+
* simulating a broken flow that got fixed.
|
|
50
|
+
* Mixpanel report:
|
|
51
|
+
* - Insights > line chart > "sign up" totaled by day, breakdown by signup_flow
|
|
52
|
+
* - Expect: ~2x volume increase in last 7 days; v1 disappears, v2 takes over
|
|
53
|
+
*
|
|
54
|
+
* Hook 2: Watch Time Inflection
|
|
55
|
+
* Type: event
|
|
56
|
+
* What: 30 days ago, watch time shifts. Before: watchTimeSec reduced by 25-79%.
|
|
57
|
+
* After: increased by 25-79%. Creates a clear before/after inflection.
|
|
58
|
+
* Mixpanel report:
|
|
59
|
+
* - Insights > line chart > "watch video" with AVG(watchTimeSec) by day
|
|
60
|
+
* - Expect: clear upward inflection ~30 days ago; watch time roughly doubles
|
|
61
|
+
*
|
|
62
|
+
* Hook 3: Toys + Shoes Cart Correlation
|
|
63
|
+
* Type: event
|
|
64
|
+
* What: Checkout carts with toys get shoes injected (and vice versa). Carts
|
|
65
|
+
* with neither toys nor shoes have all item prices discounted to 75-90%.
|
|
66
|
+
* Mixpanel report:
|
|
67
|
+
* - Insights > bar chart > "checkout" broken down by cart[].category
|
|
68
|
+
* - Expect: toys and shoes co-occur at high rate; carts without both have lower values
|
|
69
|
+
*
|
|
70
|
+
* Hook 4: Quality → Watch Time Correlation
|
|
71
|
+
* Type: event
|
|
72
|
+
* What: Video quality multiplies watchTimeSec: 2160p=1.5x, 1440p=1.4x,
|
|
73
|
+
* 1080p=1.3x, 720p=1.15x, 480p=1.0x, 360p=0.85x, 240p=0.7x.
|
|
74
|
+
* Mixpanel report:
|
|
75
|
+
* - Insights > bar chart > "watch video" with AVG(watchTimeSec), breakdown by quality
|
|
76
|
+
* - Expect: monotonic increase from 240p to 2160p
|
|
77
|
+
*
|
|
78
|
+
* Hook 5: Item Flattening
|
|
79
|
+
* Type: event
|
|
80
|
+
* What: Events with an item array property get the first item's fields
|
|
81
|
+
* flattened onto the event record, making category/amount/slug available
|
|
82
|
+
* as top-level properties for easier breakdown in reports.
|
|
83
|
+
* ============================================================================
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
function makeProducts(maxItems = 5) {
|
|
88
|
+
return function () {
|
|
89
|
+
const categories = ["electronics", "books", "clothing", "home", "garden", "toys", "sports", "automotive", "beauty", "health", "grocery", "jewelry", "shoes", "tools", "office supplies"];
|
|
90
|
+
const descriptors = ["brand new", "open box", "refurbished", "used", "like new", "vintage", "antique", "collectible"];
|
|
91
|
+
const suffix = ["item", "product", "good", "merchandise", "thing", "object", "widget", "gadget", "device", "apparatus", "contraption", "instrument", "tool", "implement", "utensil", "appliance", "machine", "equipment", "gear", "kit", "set", "package"];
|
|
92
|
+
const assetPreview = ['.png', '.jpg', '.jpeg', '.heic', '.mp4', '.mov', '.avi'];
|
|
93
|
+
const data = [];
|
|
94
|
+
const numOfItems = integer(1, maxItems);
|
|
95
|
+
|
|
96
|
+
for (var i = 0; i < numOfItems; i++) {
|
|
97
|
+
const category = chance.pickone(categories);
|
|
98
|
+
const descriptor = chance.pickone(descriptors);
|
|
99
|
+
const suffixWord = chance.pickone(suffix);
|
|
100
|
+
const slug = `${descriptor.replace(/\s+/g, '-').toLowerCase()}-${suffixWord.replace(/\s+/g, '-').toLowerCase()}`;
|
|
101
|
+
const asset = chance.pickone(assetPreview);
|
|
102
|
+
|
|
103
|
+
// const product_id = chance.guid();
|
|
104
|
+
const price = integer(1, 100);
|
|
105
|
+
const quantity = integer(1, 5);
|
|
106
|
+
|
|
107
|
+
const item = {
|
|
108
|
+
// product_id: product_id,
|
|
109
|
+
// sku: integer(11111, 99999),
|
|
110
|
+
amount: price,
|
|
111
|
+
quantity: quantity,
|
|
112
|
+
total_value: price * quantity,
|
|
113
|
+
featured: chance.pickone([true, false, false]),
|
|
114
|
+
category: category,
|
|
115
|
+
descriptor: descriptor,
|
|
116
|
+
slug: slug,
|
|
117
|
+
assetPreview: `https://example.com/assets/${slug}${asset}`,
|
|
118
|
+
assetType: asset
|
|
119
|
+
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
data.push(item);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return () => [data];
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
/** @type {import('../types.d.ts').Dungeon} */
|
|
131
|
+
const config = {
|
|
132
|
+
token: "",
|
|
133
|
+
seed: "simple is best",
|
|
134
|
+
numDays: 108, //how many days worth1 of data
|
|
135
|
+
numEvents: 2_000_000, //how many events
|
|
136
|
+
numUsers: 50_000, //how many users
|
|
137
|
+
format: 'json', //csv or json
|
|
138
|
+
region: "US",
|
|
139
|
+
hasAnonIds: false, //if true, anonymousIds are created for each user
|
|
140
|
+
hasSessionIds: false, //if true, hasSessionIds are created for each user
|
|
141
|
+
hasAdSpend: false,
|
|
142
|
+
hasLocation: true,
|
|
143
|
+
hasAndroidDevices: true,
|
|
144
|
+
hasIOSDevices: true,
|
|
145
|
+
hasDesktopDevices: true,
|
|
146
|
+
hasBrowser: true,
|
|
147
|
+
hasCampaigns: false,
|
|
148
|
+
isAnonymous: false,
|
|
149
|
+
alsoInferFunnels: false,
|
|
150
|
+
concurrency: 1,
|
|
151
|
+
batchSize: 2_500_000,
|
|
152
|
+
percentUsersBornInDataset: 25,
|
|
153
|
+
events: [
|
|
154
|
+
{
|
|
155
|
+
event: "checkout",
|
|
156
|
+
weight: 2,
|
|
157
|
+
properties: {
|
|
158
|
+
currency: ["USD", "CAD", "EUR", "BTC", "ETH", "JPY"],
|
|
159
|
+
coupon: weighChoices(["none", "none", "none", "none", "10%OFF", "20%OFF", "10%OFF", "20%OFF", "30%OFF", "40%OFF", "50%OFF"]),
|
|
160
|
+
cart: makeProducts()
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
event: "add to cart",
|
|
165
|
+
weight: 4,
|
|
166
|
+
properties: {
|
|
167
|
+
item: makeProducts(1),
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
event: "view item",
|
|
172
|
+
weight: 8,
|
|
173
|
+
properties: {
|
|
174
|
+
item: makeProducts(1)
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
event: "save item",
|
|
179
|
+
weight: 5,
|
|
180
|
+
properties: {
|
|
181
|
+
item: makeProducts(1),
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
event: "page view",
|
|
186
|
+
weight: 10,
|
|
187
|
+
properties: {
|
|
188
|
+
page: ["/", "/help", "/account", "/watch", "/listen", "/product", "/people", "/peace"],
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
event: "watch video",
|
|
193
|
+
weight: 8,
|
|
194
|
+
properties: {
|
|
195
|
+
watchTimeSec: weighNumRange(10, 600, .25),
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
event: "like video",
|
|
200
|
+
weight: 6,
|
|
201
|
+
properties: {
|
|
202
|
+
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
event: "dislike video",
|
|
207
|
+
weight: 4,
|
|
208
|
+
properties: {
|
|
209
|
+
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
event: "sign up",
|
|
214
|
+
weight: 1,
|
|
215
|
+
isFirstEvent: true,
|
|
216
|
+
properties: {
|
|
217
|
+
signupMethod: ["email", "google", "facebook", "twitter", "linkedin", "github"],
|
|
218
|
+
referral: weighChoices(["none", "none", "none", "friend", "ad", "ad", "ad", "friend", "friend", "friend", "friend"]),
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
|
|
222
|
+
],
|
|
223
|
+
funnels: [
|
|
224
|
+
{
|
|
225
|
+
sequence: ["page view", "view item", "save item", "page view", "sign up"],
|
|
226
|
+
conversionRate: 50,
|
|
227
|
+
order: "first-and-last-fixed",
|
|
228
|
+
weight: 1,
|
|
229
|
+
isFirstFunnel: true,
|
|
230
|
+
timeToConvert: 2,
|
|
231
|
+
experiment: false,
|
|
232
|
+
name: "Signup Flow"
|
|
233
|
+
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
sequence: ["watch video", "like video", "watch video", "like video"],
|
|
237
|
+
name: "Video Likes",
|
|
238
|
+
conversionRate: 60,
|
|
239
|
+
props: {
|
|
240
|
+
videoCategory: videoCategories,
|
|
241
|
+
quality: ["2160p", "1440p", "1080p", "720p", "480p", "360p", "240p"],
|
|
242
|
+
format: ["mp4", "avi", "mov", "mpg"],
|
|
243
|
+
uploader_id: chance.guid.bind(chance)
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
name: "Video Dislikes",
|
|
248
|
+
sequence: ["watch video", "dislike video", "watch video", "dislike video"],
|
|
249
|
+
conversionRate: 20,
|
|
250
|
+
props: {
|
|
251
|
+
videoCategory: videoCategories,
|
|
252
|
+
quality: ["2160p", "1440p", "1080p", "720p", "480p", "360p", "240p"],
|
|
253
|
+
format: ["mp4", "avi", "mov", "mpg"],
|
|
254
|
+
uploader_id: chance.guid.bind(chance)
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
name: "eCommerce Purchase",
|
|
259
|
+
sequence: ["view item", "view item", "add to cart", "view item", "add to cart", "checkout"],
|
|
260
|
+
conversionRate: 15,
|
|
261
|
+
requireRepeats: true,
|
|
262
|
+
weight: 10,
|
|
263
|
+
order: "last-fixed",
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
],
|
|
267
|
+
superProps: {
|
|
268
|
+
theme: pickAWinner(["light", "dark", "custom", "light", "dark"]),
|
|
269
|
+
},
|
|
270
|
+
/*
|
|
271
|
+
user properties work the same as event properties
|
|
272
|
+
each key should be an array or function reference
|
|
273
|
+
*/
|
|
274
|
+
userProps: {
|
|
275
|
+
title: chance.profession.bind(chance),
|
|
276
|
+
luckyNumber: weighNumRange(42, 420, .3),
|
|
277
|
+
spiritAnimal: spiritAnimals
|
|
278
|
+
},
|
|
279
|
+
scdProps: {},
|
|
280
|
+
mirrorProps: {},
|
|
281
|
+
|
|
282
|
+
/*
|
|
283
|
+
for group analytics keys, we need an array of arrays [[],[],[]]
|
|
284
|
+
each pair represents a group_key and the number of profiles for that key
|
|
285
|
+
*/
|
|
286
|
+
groupKeys: [],
|
|
287
|
+
groupProps: {},
|
|
288
|
+
lookupTables: [],
|
|
289
|
+
hook: function (record, type, meta) {
|
|
290
|
+
|
|
291
|
+
if (type === "event") {
|
|
292
|
+
const NOW = dayjs();
|
|
293
|
+
const DAY_SIGNUPS_IMPROVED = NOW.subtract(7, 'day');
|
|
294
|
+
const DAY_WATCH_TIME_WENT_UP = NOW.subtract(30, 'day');
|
|
295
|
+
const eventTime = dayjs(record.time);
|
|
296
|
+
|
|
297
|
+
// unflattering 'items'
|
|
298
|
+
if (record.item && Array.isArray(record.item)) {
|
|
299
|
+
record = { ...record, ...record.item[0] };
|
|
300
|
+
delete record.item;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (record.event === 'sign up') {
|
|
304
|
+
record.signup_flow = "v1";
|
|
305
|
+
if (eventTime.isBefore(DAY_SIGNUPS_IMPROVED)) {
|
|
306
|
+
// tag 50% for removal (filtered in "everything" hook)
|
|
307
|
+
if (chance.bool({ likelihood: 50 })) {
|
|
308
|
+
record._drop = true;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (eventTime.isAfter(DAY_SIGNUPS_IMPROVED)) {
|
|
312
|
+
record.signup_flow = "v2";
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (record.event === 'watch video') {
|
|
317
|
+
const factor = decimal(0.25, 0.79);
|
|
318
|
+
if (eventTime.isBefore(DAY_WATCH_TIME_WENT_UP)) {
|
|
319
|
+
record.watchTimeSec = Math.round(record.watchTimeSec * (1 - factor));
|
|
320
|
+
}
|
|
321
|
+
if (eventTime.isAfter(DAY_WATCH_TIME_WENT_UP)) {
|
|
322
|
+
// increase watch time by 33%
|
|
323
|
+
record.watchTimeSec = Math.round(record.watchTimeSec * (1 + factor));
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// toys + shoes frequently purchases together (and are higher cart values)
|
|
329
|
+
if (record.event === 'checkout' && Array.isArray(record.cart)) {
|
|
330
|
+
const hasToys = record.cart.some(item => item.category === 'toys');
|
|
331
|
+
const hasShoes = record.cart.some(item => item.category === 'shoes');
|
|
332
|
+
if (hasToys && !hasShoes) {
|
|
333
|
+
const bigCart = makeProducts(20)()()[0];
|
|
334
|
+
const shoeItems = bigCart.filter(item => item.category === 'shoes');
|
|
335
|
+
if (shoeItems.length > 0) {
|
|
336
|
+
record.cart.push(shoeItems[0]);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (hasShoes && !hasToys) {
|
|
341
|
+
const bigCart = makeProducts(20)()()[0];
|
|
342
|
+
const toyItems = bigCart.filter(item => item.category === 'toys');
|
|
343
|
+
if (toyItems.length > 0) {
|
|
344
|
+
record.cart.push(toyItems[0]);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (!hasToys && !hasShoes) {
|
|
349
|
+
const cheapFactor = decimal(.75, 0.9);
|
|
350
|
+
// make every item a bit cheaper
|
|
351
|
+
record.cart = record.cart.map(item => {
|
|
352
|
+
return {
|
|
353
|
+
...item,
|
|
354
|
+
amount: Math.round(item.amount * cheapFactor),
|
|
355
|
+
total_value: Math.round(item.total_value * cheapFactor)
|
|
356
|
+
};
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
// high quality video means longer watch times (lower quality shorter watch times)
|
|
361
|
+
if (record.event === 'watch video') {
|
|
362
|
+
const qualityFactors = {
|
|
363
|
+
"2160p": 1.5,
|
|
364
|
+
"1440p": 1.4,
|
|
365
|
+
"1080p": 1.3,
|
|
366
|
+
"720p": 1.15,
|
|
367
|
+
"480p": 1.0,
|
|
368
|
+
"360p": 0.85,
|
|
369
|
+
"240p": 0.7
|
|
370
|
+
};
|
|
371
|
+
const quality = record.quality || "480p";
|
|
372
|
+
const factor = qualityFactors[quality] || 1.0;
|
|
373
|
+
record.watchTimeSec = Math.round(record.watchTimeSec * factor);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
if (type === "everything") {
|
|
383
|
+
// big themes!
|
|
384
|
+
|
|
385
|
+
// users who view items in the home and garden category churn more frequently
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
// dark mode leads to faster purchase conversion
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
// people who pay in bitcoin tend to buy more electronics and gadgets
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
//custom themes purchase more:
|
|
395
|
+
// const numCustomMode = record.filter(a => a.theme === 'custom').length;
|
|
396
|
+
// const numLightMode = record.filter(a => a.theme === 'light').length;
|
|
397
|
+
// const numDarkMode = record.filter(a => a.theme === 'dark').length;
|
|
398
|
+
// if (numCustomMode > numLightMode || numCustomMode > numDarkMode) {
|
|
399
|
+
// //triple their checkout events
|
|
400
|
+
// const checkoutEvents = record.filter(a => a.event === 'checkout');
|
|
401
|
+
// const newCheckouts = checkoutEvents.map(a => {
|
|
402
|
+
// const randomInt = integer(-48, 48);
|
|
403
|
+
// const newCheckout = {
|
|
404
|
+
// ...a,
|
|
405
|
+
// time: dayjs(a.time).add(randomInt, 'hour').toISOString(),
|
|
406
|
+
// event: "checkout",
|
|
407
|
+
// amount: a.amount * 2,
|
|
408
|
+
// coupon: "50%OFF"
|
|
409
|
+
// };
|
|
410
|
+
// return newCheckout;
|
|
411
|
+
// });
|
|
412
|
+
// record.push(...newCheckouts);
|
|
413
|
+
// }
|
|
414
|
+
|
|
415
|
+
// //users who watch low quality videos churn more:
|
|
416
|
+
// const loQuality = ["480p", "360p", "240p"];
|
|
417
|
+
// const lowQualityWatches = record.filter(a => a.event === 'watch video' && loQuality.includes(a.quality));
|
|
418
|
+
// const highQualityWatches = record.filter(a => a.event === 'watch video' && !loQuality.includes(a.quality));
|
|
419
|
+
// if (lowQualityWatches.length > highQualityWatches.length) {
|
|
420
|
+
// if (flip()) {
|
|
421
|
+
// // find midpoint of records
|
|
422
|
+
// const midpoint = Math.floor(record.length / 2);
|
|
423
|
+
// record = record.slice(0, midpoint);
|
|
424
|
+
|
|
425
|
+
// }
|
|
426
|
+
// }
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// Filter out events tagged for removal in the event hook
|
|
434
|
+
if (type === "everything") {
|
|
435
|
+
record = record.filter(e => !e._drop);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
return record;
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
function flip(likelihood = 50) {
|
|
443
|
+
return chance.bool({ likelihood });
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
export default config;
|