@idlekit/core 0.7.0 → 0.9.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 +35 -0
- package/dist/adapters/runtime.d.ts +51 -0
- package/dist/adapters/runtime.js +16 -0
- package/dist/adapters/runtime.js.map +1 -0
- package/dist/engine/breakEternity.d.ts +11 -0
- package/dist/engine/breakEternity.js +11 -0
- package/dist/engine/breakEternity.js.map +1 -1
- package/dist/engine/breakInfinity.d.ts +7 -0
- package/dist/engine/breakInfinity.js +7 -0
- package/dist/engine/breakInfinity.js.map +1 -1
- package/dist/engine/types.d.ts +7 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -1
- package/dist/ltv/telemetryLoop.d.ts +203 -0
- package/dist/ltv/telemetryLoop.js +389 -0
- package/dist/ltv/telemetryLoop.js.map +1 -0
- package/dist/models/exponential.d.ts +95 -0
- package/dist/models/exponential.js +200 -0
- package/dist/models/exponential.js.map +1 -0
- package/dist/models/index.d.ts +12 -0
- package/dist/models/index.js +18 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/jsonSchema.d.ts +13 -0
- package/dist/models/jsonSchema.js +30 -0
- package/dist/models/jsonSchema.js.map +1 -0
- package/dist/models/ledger.d.ts +26 -0
- package/dist/models/ledger.js +63 -0
- package/dist/models/ledger.js.map +1 -0
- package/dist/models/multiCurrency.d.ts +70 -0
- package/dist/models/multiCurrency.js +343 -0
- package/dist/models/multiCurrency.js.map +1 -0
- package/dist/models/prestige.d.ts +123 -0
- package/dist/models/prestige.js +183 -0
- package/dist/models/prestige.js.map +1 -0
- package/dist/models/productionChain.d.ts +114 -0
- package/dist/models/productionChain.js +447 -0
- package/dist/models/productionChain.js.map +1 -0
- package/dist/models/shared.d.ts +59 -0
- package/dist/models/shared.js +144 -0
- package/dist/models/shared.js.map +1 -0
- package/dist/money/types.d.ts +7 -0
- package/dist/notation/formatMoney.d.ts +7 -0
- package/dist/notation/formatMoney.js +7 -0
- package/dist/notation/formatMoney.js.map +1 -1
- package/dist/notation/parseMoney.d.ts +7 -0
- package/dist/notation/parseMoney.js +7 -0
- package/dist/notation/parseMoney.js.map +1 -1
- package/dist/notation/suffixer.d.ts +7 -0
- package/dist/notation/suffixer.js +7 -0
- package/dist/notation/suffixer.js.map +1 -1
- package/dist/notation/visibilityTracker.d.ts +7 -0
- package/dist/notation/visibilityTracker.js +7 -0
- package/dist/notation/visibilityTracker.js.map +1 -1
- package/dist/policy/emitter.d.ts +7 -0
- package/dist/policy/emitter.js +7 -0
- package/dist/policy/emitter.js.map +1 -1
- package/dist/policy/tickMoney.d.ts +7 -0
- package/dist/policy/tickMoney.js +7 -0
- package/dist/policy/tickMoney.js.map +1 -1
- package/dist/policy/types.d.ts +7 -0
- package/dist/report/chart.d.ts +196 -0
- package/dist/report/chart.js +275 -0
- package/dist/report/chart.js.map +1 -0
- package/dist/report/chartSvg.d.ts +9 -0
- package/dist/report/chartSvg.js +465 -0
- package/dist/report/chartSvg.js.map +1 -0
- package/dist/serde/moneyState.d.ts +7 -0
- package/dist/serde/moneyState.js +7 -0
- package/dist/serde/moneyState.js.map +1 -1
- package/dist/sim/analysis/designSpace.d.ts +23 -0
- package/dist/sim/analysis/designSpace.js +66 -0
- package/dist/sim/analysis/designSpace.js.map +1 -0
- package/dist/sim/analysis/globalSensitivity.d.ts +70 -0
- package/dist/sim/analysis/globalSensitivity.js +207 -0
- package/dist/sim/analysis/globalSensitivity.js.map +1 -0
- package/dist/sim/analysis/parameterSearch.d.ts +44 -0
- package/dist/sim/analysis/parameterSearch.js +172 -0
- package/dist/sim/analysis/parameterSearch.js.map +1 -0
- package/dist/sim/analysis/prestigeCycle.d.ts +1 -1
- package/dist/sim/analysis/prestigeCycle.js +7 -1
- package/dist/sim/analysis/prestigeCycle.js.map +1 -1
- package/dist/sim/analysis/resetInsights.d.ts +68 -0
- package/dist/sim/analysis/resetInsights.js +129 -0
- package/dist/sim/analysis/resetInsights.js.map +1 -0
- package/dist/sim/analysis/sampleStats.d.ts +34 -0
- package/dist/sim/analysis/sampleStats.js +97 -0
- package/dist/sim/analysis/sampleStats.js.map +1 -0
- package/dist/sim/monteCarlo.d.ts +7 -1
- package/dist/sim/monteCarlo.js +8 -0
- package/dist/sim/monteCarlo.js.map +1 -1
- package/dist/sim/random.d.ts +9 -0
- package/dist/sim/random.js +10 -1
- package/dist/sim/random.js.map +1 -1
- package/dist/sim/session.d.ts +2 -0
- package/dist/sim/session.js +15 -4
- package/dist/sim/session.js.map +1 -1
- package/dist/sim/sessionOffline.d.ts +4 -0
- package/dist/sim/sessionOffline.js +1 -0
- package/dist/sim/sessionOffline.js.map +1 -1
- package/dist/sim/stochastic.d.ts +82 -0
- package/dist/sim/stochastic.js +174 -0
- package/dist/sim/stochastic.js.map +1 -0
- package/dist/sim/timedWork.d.ts +10 -0
- package/dist/sim/timedWork.js +25 -0
- package/dist/sim/timedWork.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import { RETENTION_DAYS, applyRetentionPatch, compareRetention, observeCohort, planRetentionPatch, } from "./cohort";
|
|
2
|
+
/**
|
|
3
|
+
* Telemetry feedback loop: a standardized batch of complete install cohorts,
|
|
4
|
+
* multi-cohort comparison, drift checks, experiment planning and a patch plan
|
|
5
|
+
* that keeps the scenario diff explicit. Everything runs on local values.
|
|
6
|
+
*/
|
|
7
|
+
export const COHORT_BATCH_SCHEMA_VERSION = 1;
|
|
8
|
+
const ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
|
|
9
|
+
const DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
|
10
|
+
const ROW_KEYS = new Set(["userId", "day", "active", "iapRevenue", "adRevenue", "acquisitionCost"]);
|
|
11
|
+
const ENTRY_KEYS = new Set(["id", "variant", "installDate", "observedThroughDay", "rows"]);
|
|
12
|
+
function record(value) {
|
|
13
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
function validDate(value) {
|
|
16
|
+
if (!DATE_PATTERN.test(value))
|
|
17
|
+
return false;
|
|
18
|
+
const parsed = new Date(`${value}T00:00:00Z`);
|
|
19
|
+
return !Number.isNaN(parsed.getTime()) && parsed.toISOString().slice(0, 10) === value;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Validate a standardized cohort batch and observe every cohort. All issues are
|
|
23
|
+
* collected with a JSON path, so a batch export can be fixed in one pass.
|
|
24
|
+
* Revenue fields must be present on every row of a cohort or on none of them.
|
|
25
|
+
*/
|
|
26
|
+
export function validateCohortBatch(input) {
|
|
27
|
+
const issues = [];
|
|
28
|
+
if (!record(input))
|
|
29
|
+
return { ok: false, issues: [{ path: "$", message: "Cohort batch must be an object" }] };
|
|
30
|
+
if (input.schemaVersion !== COHORT_BATCH_SCHEMA_VERSION)
|
|
31
|
+
issues.push({ path: "$.schemaVersion", message: `schemaVersion must be ${COHORT_BATCH_SCHEMA_VERSION}` });
|
|
32
|
+
for (const key of Object.keys(input))
|
|
33
|
+
if (key !== "schemaVersion" && key !== "cohorts")
|
|
34
|
+
issues.push({ path: `$.${key}`, message: "Unknown cohort batch field" });
|
|
35
|
+
if (!Array.isArray(input.cohorts) || input.cohorts.length === 0) {
|
|
36
|
+
issues.push({ path: "$.cohorts", message: "cohorts must be a non-empty array" });
|
|
37
|
+
return { ok: false, issues };
|
|
38
|
+
}
|
|
39
|
+
const ids = new Set();
|
|
40
|
+
const cohorts = [];
|
|
41
|
+
for (const [index, value] of input.cohorts.entries()) {
|
|
42
|
+
const path = `$.cohorts[${index}]`;
|
|
43
|
+
if (!record(value)) {
|
|
44
|
+
issues.push({ path, message: "Cohort must be an object" });
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const before = issues.length;
|
|
48
|
+
for (const key of Object.keys(value))
|
|
49
|
+
if (!ENTRY_KEYS.has(key))
|
|
50
|
+
issues.push({ path: `${path}.${key}`, message: "Unknown cohort field" });
|
|
51
|
+
if (typeof value.id !== "string" || !ID_PATTERN.test(value.id))
|
|
52
|
+
issues.push({ path: `${path}.id`, message: "id must match [A-Za-z0-9][A-Za-z0-9._:-]{0,127}" });
|
|
53
|
+
else if (ids.has(value.id))
|
|
54
|
+
issues.push({ path: `${path}.id`, message: `Duplicate cohort id ${value.id}` });
|
|
55
|
+
else
|
|
56
|
+
ids.add(value.id);
|
|
57
|
+
if (value.variant !== undefined && (typeof value.variant !== "string" || !ID_PATTERN.test(value.variant)))
|
|
58
|
+
issues.push({ path: `${path}.variant`, message: "variant must match [A-Za-z0-9][A-Za-z0-9._:-]{0,127}" });
|
|
59
|
+
if (value.installDate !== undefined && (typeof value.installDate !== "string" || !validDate(value.installDate)))
|
|
60
|
+
issues.push({ path: `${path}.installDate`, message: "installDate must be a valid YYYY-MM-DD date" });
|
|
61
|
+
if (typeof value.observedThroughDay !== "number" || !Number.isSafeInteger(value.observedThroughDay) || value.observedThroughDay < 0)
|
|
62
|
+
issues.push({ path: `${path}.observedThroughDay`, message: "observedThroughDay must be a nonnegative safe integer" });
|
|
63
|
+
if (!Array.isArray(value.rows) || value.rows.length === 0) {
|
|
64
|
+
issues.push({ path: `${path}.rows`, message: "rows must be a non-empty array" });
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const presence = new Map();
|
|
68
|
+
for (const [rowIndex, row] of value.rows.entries()) {
|
|
69
|
+
if (!record(row)) {
|
|
70
|
+
issues.push({ path: `${path}.rows[${rowIndex}]`, message: "Row must be an object" });
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
for (const key of Object.keys(row)) {
|
|
74
|
+
if (!ROW_KEYS.has(key))
|
|
75
|
+
issues.push({ path: `${path}.rows[${rowIndex}].${key}`, message: "Unknown row field" });
|
|
76
|
+
else
|
|
77
|
+
presence.set(key, (presence.get(key) ?? 0) + 1);
|
|
78
|
+
}
|
|
79
|
+
if (typeof row.userId !== "string" || !row.userId.trim())
|
|
80
|
+
issues.push({ path: `${path}.rows[${rowIndex}].userId`, message: "userId must be a non-empty string" });
|
|
81
|
+
if (typeof row.day !== "number")
|
|
82
|
+
issues.push({ path: `${path}.rows[${rowIndex}].day`, message: "day must be a number" });
|
|
83
|
+
if (row.active !== undefined && typeof row.active !== "boolean")
|
|
84
|
+
issues.push({ path: `${path}.rows[${rowIndex}].active`, message: "active must be boolean" });
|
|
85
|
+
for (const key of ["iapRevenue", "adRevenue", "acquisitionCost"]) {
|
|
86
|
+
if (row[key] !== undefined && typeof row[key] !== "number")
|
|
87
|
+
issues.push({ path: `${path}.rows[${rowIndex}].${key}`, message: `${key} must be a number` });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
for (const key of ["iapRevenue", "adRevenue"]) {
|
|
91
|
+
const count = presence.get(key) ?? 0;
|
|
92
|
+
if (count !== 0 && count !== value.rows.length)
|
|
93
|
+
issues.push({ path: `${path}.rows`, message: `${key} must be on every row of the cohort or none; an omitted value is unmeasured, not zero` });
|
|
94
|
+
}
|
|
95
|
+
if (issues.length !== before)
|
|
96
|
+
continue;
|
|
97
|
+
try {
|
|
98
|
+
const observation = observeCohort(value.rows, value.observedThroughDay);
|
|
99
|
+
cohorts.push({
|
|
100
|
+
id: value.id,
|
|
101
|
+
variant: value.variant ?? null,
|
|
102
|
+
installDate: value.installDate ?? null,
|
|
103
|
+
rows: value.rows.length,
|
|
104
|
+
observation,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
issues.push({ path, message: error instanceof Error ? error.message : String(error) });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return issues.length ? { ok: false, issues } : { ok: true, issues: [], cohorts };
|
|
112
|
+
}
|
|
113
|
+
/** Observe every cohort in a batch, or throw one RangeError listing each issue path. */
|
|
114
|
+
export function observeCohortBatch(input) {
|
|
115
|
+
const result = validateCohortBatch(input);
|
|
116
|
+
if (!result.ok)
|
|
117
|
+
throw new RangeError(`Invalid cohort batch: ${result.issues.map(issue => `${issue.path}: ${issue.message}`).join("; ")}`);
|
|
118
|
+
return result.cohorts;
|
|
119
|
+
}
|
|
120
|
+
// --- statistics helpers -------------------------------------------------------
|
|
121
|
+
/** Complementary error function (Numerical Recipes erfcc, fractional error < 1.2e-7). */
|
|
122
|
+
function erfc(x) {
|
|
123
|
+
const z = Math.abs(x);
|
|
124
|
+
const t = 1 / (1 + 0.5 * z);
|
|
125
|
+
const r = t * Math.exp(-z * z - 1.26551223 + t * (1.00002368 + t * (0.37409196 + t * (0.09678418 + t * (-0.18628806 + t * (0.27886807 + t * (-1.13520398 + t * (1.48851587 + t * (-0.82215223 + t * 0.17087277)))))))));
|
|
126
|
+
return x >= 0 ? r : 2 - r;
|
|
127
|
+
}
|
|
128
|
+
/** Standard normal CDF. */
|
|
129
|
+
export function standardNormalCdf(x) {
|
|
130
|
+
return 0.5 * erfc(-x / Math.SQRT2);
|
|
131
|
+
}
|
|
132
|
+
/** Standard normal quantile (Acklam's rational approximation, relative error < 1.2e-9). */
|
|
133
|
+
export function standardNormalQuantile(p) {
|
|
134
|
+
if (!(p > 0 && p < 1))
|
|
135
|
+
throw new RangeError("Normal quantile probability must be in (0, 1)");
|
|
136
|
+
const a = [-3.969683028665376e1, 2.209460984245205e2, -2.759285104469687e2, 1.38357751867269e2, -3.066479806614716e1, 2.506628277459239];
|
|
137
|
+
const b = [-5.447609879822406e1, 1.615858368580409e2, -1.556989798598866e2, 6.680131188771972e1, -1.328068155288572e1];
|
|
138
|
+
const c = [-7.784894002430293e-3, -3.223964580411365e-1, -2.400758277161838, -2.549732539343734, 4.374664141464968, 2.938163982698783];
|
|
139
|
+
const d = [7.784695709041462e-3, 3.224671290700398e-1, 2.445134137142996, 3.754408661907416];
|
|
140
|
+
const low = 0.02425;
|
|
141
|
+
if (p < low) {
|
|
142
|
+
const q = Math.sqrt(-2 * Math.log(p));
|
|
143
|
+
return (((((c[0] * q + c[1]) * q + c[2]) * q + c[3]) * q + c[4]) * q + c[5]) / ((((d[0] * q + d[1]) * q + d[2]) * q + d[3]) * q + 1);
|
|
144
|
+
}
|
|
145
|
+
if (p > 1 - low)
|
|
146
|
+
return -standardNormalQuantile(1 - p);
|
|
147
|
+
const q = p - 0.5;
|
|
148
|
+
const r = q * q;
|
|
149
|
+
return (((((a[0] * r + a[1]) * r + a[2]) * r + a[3]) * r + a[4]) * r + a[5]) * q / (((((b[0] * r + b[1]) * r + b[2]) * r + b[3]) * r + b[4]) * r + 1);
|
|
150
|
+
}
|
|
151
|
+
function assertAlpha(alpha) {
|
|
152
|
+
if (!(Number.isFinite(alpha) && alpha > 0 && alpha < 1))
|
|
153
|
+
throw new RangeError("alpha must be in (0, 1)");
|
|
154
|
+
}
|
|
155
|
+
/** Pooled two-proportion z-test hint for retained/installed counts. */
|
|
156
|
+
export function twoProportionSignificance(a, b, alpha = 0.05) {
|
|
157
|
+
assertAlpha(alpha);
|
|
158
|
+
for (const group of [a, b]) {
|
|
159
|
+
if (!Number.isSafeInteger(group.users) || group.users < 1 || !Number.isSafeInteger(group.activeUsers) || group.activeUsers < 0 || group.activeUsers > group.users) {
|
|
160
|
+
throw new RangeError("Significance counts must be integers with 0 <= activeUsers <= users and users >= 1");
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const pooled = (a.activeUsers + b.activeUsers) / (a.users + b.users);
|
|
164
|
+
const expected = [a.users * pooled, a.users * (1 - pooled), b.users * pooled, b.users * (1 - pooled)];
|
|
165
|
+
if (expected.some(count => count < 5))
|
|
166
|
+
return { test: "two-proportion-z", alpha, z: null, pValue: null, verdict: "insufficient-sample" };
|
|
167
|
+
const se = Math.sqrt(pooled * (1 - pooled) * (1 / a.users + 1 / b.users));
|
|
168
|
+
const z = (b.activeUsers / b.users - a.activeUsers / a.users) / se;
|
|
169
|
+
const pValue = Math.min(1, 2 * (1 - standardNormalCdf(Math.abs(z))));
|
|
170
|
+
return { test: "two-proportion-z", alpha, z, pValue, verdict: pValue < alpha ? "significant" : "not-significant" };
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Compare exact-day retention across cohorts. The baseline cohort (first by default)
|
|
174
|
+
* anchors the difference and the significance hint of every other cohort.
|
|
175
|
+
*/
|
|
176
|
+
export function compareCohorts(cohorts, options = {}) {
|
|
177
|
+
if (cohorts.length === 0)
|
|
178
|
+
throw new RangeError("Cohort comparison requires at least one cohort");
|
|
179
|
+
const alpha = options.alpha ?? 0.05;
|
|
180
|
+
assertAlpha(alpha);
|
|
181
|
+
const baseline = options.baseline === undefined ? cohorts[0] : cohorts.find(cohort => cohort.id === options.baseline);
|
|
182
|
+
if (!baseline)
|
|
183
|
+
throw new RangeError(`Baseline cohort ${options.baseline} is not in the batch`);
|
|
184
|
+
const assumptionRows = cohorts.map(cohort => compareRetention(cohort.observation, options.assumptions ?? {}));
|
|
185
|
+
const days = RETENTION_DAYS.map((day, dayIndex) => {
|
|
186
|
+
const base = baseline.observation.retention[dayIndex];
|
|
187
|
+
const cells = cohorts.map((cohort, cohortIndex) => {
|
|
188
|
+
const point = cohort.observation.retention[dayIndex];
|
|
189
|
+
const assumption = assumptionRows[cohortIndex][dayIndex];
|
|
190
|
+
const comparable = cohort !== baseline && point.activeUsers !== null && base.activeUsers !== null;
|
|
191
|
+
return {
|
|
192
|
+
cohortId: cohort.id,
|
|
193
|
+
variant: cohort.variant,
|
|
194
|
+
status: point.status,
|
|
195
|
+
users: point.users,
|
|
196
|
+
activeUsers: point.activeUsers,
|
|
197
|
+
rate: point.rate,
|
|
198
|
+
interval95: point.interval95,
|
|
199
|
+
differenceFromBaselinePercentagePoints: comparable ? (point.rate - base.rate) * 100 : null,
|
|
200
|
+
differenceFromAssumptionPercentagePoints: assumption.differencePercentagePoints,
|
|
201
|
+
significance: comparable ? twoProportionSignificance({ users: base.users, activeUsers: base.activeUsers }, { users: point.users, activeUsers: point.activeUsers }, alpha) : null,
|
|
202
|
+
};
|
|
203
|
+
});
|
|
204
|
+
const rates = cells.flatMap(cell => cell.rate === null ? [] : [cell.rate]);
|
|
205
|
+
return {
|
|
206
|
+
day,
|
|
207
|
+
assumption: options.assumptions?.[`d${day}`] ?? null,
|
|
208
|
+
observedCohorts: rates.length,
|
|
209
|
+
spreadPercentagePoints: rates.length >= 2 ? (Math.max(...rates) - Math.min(...rates)) * 100 : null,
|
|
210
|
+
cohorts: cells,
|
|
211
|
+
};
|
|
212
|
+
});
|
|
213
|
+
const notes = [
|
|
214
|
+
"Significance is a pooled two-proportion z-test hint per day and pair; it is not a pre-registered experiment analysis.",
|
|
215
|
+
"Cohorts with different install dates, release builds or acquisition sources differ for reasons other than the scenario.",
|
|
216
|
+
];
|
|
217
|
+
if (cohorts.length > 2)
|
|
218
|
+
notes.push(`With ${cohorts.length - 1} comparisons per day, a family-wise 5% bound needs alpha / ${cohorts.length - 1} per comparison.`);
|
|
219
|
+
return { baseline: baseline.id, alpha, comparisons: cohorts.length - 1, days, notes };
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Compare observed anchors with explicit assumptions. A day drifts when the absolute
|
|
223
|
+
* difference reaches the threshold and, by default, the assumption also lies outside
|
|
224
|
+
* the Wilson 95% interval (so a small cohort's noise alone does not alert).
|
|
225
|
+
*/
|
|
226
|
+
export function detectRetentionDrift(observation, assumptions, options = {}) {
|
|
227
|
+
const thresholdPercentagePoints = options.thresholdPercentagePoints ?? 5;
|
|
228
|
+
if (!(Number.isFinite(thresholdPercentagePoints) && thresholdPercentagePoints >= 0 && thresholdPercentagePoints <= 100)) {
|
|
229
|
+
throw new RangeError("Drift threshold must be finite and in 0..100 percentage points");
|
|
230
|
+
}
|
|
231
|
+
const requireIntervalExclusion = options.requireIntervalExclusion ?? true;
|
|
232
|
+
const comparison = compareRetention(observation, assumptions);
|
|
233
|
+
const findings = [];
|
|
234
|
+
for (const [index, row] of comparison.entries()) {
|
|
235
|
+
if (row.status !== "compared")
|
|
236
|
+
continue;
|
|
237
|
+
const interval = observation.retention[index].interval95;
|
|
238
|
+
const outside = row.assumption < interval.min || row.assumption > interval.max;
|
|
239
|
+
const difference = row.differencePercentagePoints;
|
|
240
|
+
findings.push({
|
|
241
|
+
day: row.day, assumption: row.assumption, observed: row.observed, differencePercentagePoints: difference,
|
|
242
|
+
interval95: interval, assumptionOutsideInterval: outside,
|
|
243
|
+
drift: Math.abs(difference) + 1e-9 >= thresholdPercentagePoints && (!requireIntervalExclusion || outside),
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
const status = findings.length === 0 ? "no-comparable-days" : findings.some(finding => finding.drift) ? "drift" : "within-threshold";
|
|
247
|
+
return { status, thresholdPercentagePoints, requireIntervalExclusion, findings };
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Size a retention experiment for a two-sided pooled two-proportion test with equal
|
|
251
|
+
* allocation. Each treatment group is compared with the first (control) group, with
|
|
252
|
+
* a Bonferroni-adjusted alpha. The plan does not replace an experiment platform.
|
|
253
|
+
*/
|
|
254
|
+
export function planRetentionExperiment(args) {
|
|
255
|
+
if (!RETENTION_DAYS.includes(args.retentionDay))
|
|
256
|
+
throw new RangeError(`retentionDay must be one of ${RETENTION_DAYS.join(", ")}`);
|
|
257
|
+
if (args.groups.length < 2)
|
|
258
|
+
throw new RangeError("An experiment requires a control group and at least one treatment group");
|
|
259
|
+
const ids = new Set();
|
|
260
|
+
for (const group of args.groups) {
|
|
261
|
+
if (!ID_PATTERN.test(group.id) || ids.has(group.id))
|
|
262
|
+
throw new RangeError(`Experiment group ids must be unique and match ${ID_PATTERN.source}`);
|
|
263
|
+
ids.add(group.id);
|
|
264
|
+
if (group.retention !== undefined && !(Number.isFinite(group.retention) && group.retention >= 0 && group.retention <= 1))
|
|
265
|
+
throw new RangeError(`Group ${group.id} retention must be in 0..1`);
|
|
266
|
+
}
|
|
267
|
+
const alpha = args.alpha ?? 0.05;
|
|
268
|
+
const power = args.power ?? 0.8;
|
|
269
|
+
assertAlpha(alpha);
|
|
270
|
+
if (!(Number.isFinite(power) && power > 0 && power < 1))
|
|
271
|
+
throw new RangeError("power must be in (0, 1)");
|
|
272
|
+
const control = args.groups[0];
|
|
273
|
+
const baselineRate = args.baselineRate ?? control.retention;
|
|
274
|
+
if (baselineRate === undefined || !(baselineRate > 0 && baselineRate < 1))
|
|
275
|
+
throw new RangeError("baselineRate must be in (0, 1); pass it or give the control group a retention assumption");
|
|
276
|
+
let mde = args.minimumDetectableEffectPercentagePoints;
|
|
277
|
+
if (mde === undefined) {
|
|
278
|
+
const effects = args.groups.slice(1).flatMap(group => group.retention === undefined ? [] : [Math.abs(group.retention - baselineRate) * 100]).filter(effect => effect > 0);
|
|
279
|
+
if (effects.length === 0)
|
|
280
|
+
throw new RangeError("minimumDetectableEffectPercentagePoints is required when the variants assume the same retention");
|
|
281
|
+
mde = Math.min(...effects);
|
|
282
|
+
}
|
|
283
|
+
if (!(Number.isFinite(mde) && mde > 0 && mde < 100))
|
|
284
|
+
throw new RangeError("minimumDetectableEffectPercentagePoints must be in (0, 100)");
|
|
285
|
+
const delta = mde / 100;
|
|
286
|
+
// A directionless MDE must cover both feasible alternatives: variance, and thus
|
|
287
|
+
// required sample size, is not symmetric around a baseline other than 0.5.
|
|
288
|
+
const mdeTargets = [baselineRate - delta, baselineRate + delta].filter(rate => rate >= 0 && rate <= 1);
|
|
289
|
+
const targets = args.minimumDetectableEffectPercentagePoints !== undefined
|
|
290
|
+
? mdeTargets
|
|
291
|
+
: args.groups.slice(1).flatMap(group => group.retention === undefined || group.retention === baselineRate ? mdeTargets : [group.retention]);
|
|
292
|
+
if (targets.length === 0)
|
|
293
|
+
throw new RangeError("The minimum detectable effect moves the target rate outside [0, 1]");
|
|
294
|
+
const comparisons = args.groups.length - 1;
|
|
295
|
+
const adjustedAlpha = alpha / comparisons;
|
|
296
|
+
const zAlpha = standardNormalQuantile(1 - adjustedAlpha / 2);
|
|
297
|
+
const zBeta = standardNormalQuantile(power);
|
|
298
|
+
const requiredUsers = (target) => {
|
|
299
|
+
const effect = target - baselineRate;
|
|
300
|
+
const mean = (baselineRate + target) / 2;
|
|
301
|
+
const numerator = zAlpha * Math.sqrt(2 * mean * (1 - mean)) + zBeta * Math.sqrt(baselineRate * (1 - baselineRate) + target * (1 - target));
|
|
302
|
+
return Math.ceil((numerator * numerator) / (effect * effect));
|
|
303
|
+
};
|
|
304
|
+
// Keep equal allocation and report the alternative that determines its budget.
|
|
305
|
+
let targetRate = targets[0];
|
|
306
|
+
let usersPerGroup = requiredUsers(targetRate);
|
|
307
|
+
for (const target of targets.slice(1)) {
|
|
308
|
+
const users = requiredUsers(target);
|
|
309
|
+
if (users > usersPerGroup) {
|
|
310
|
+
targetRate = target;
|
|
311
|
+
usersPerGroup = users;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
const totalUsers = usersPerGroup * args.groups.length;
|
|
315
|
+
let enrollmentDays = null;
|
|
316
|
+
if (args.dailyInstalls !== undefined) {
|
|
317
|
+
if (!(Number.isFinite(args.dailyInstalls) && args.dailyInstalls > 0))
|
|
318
|
+
throw new RangeError("dailyInstalls must be positive");
|
|
319
|
+
enrollmentDays = Math.max(7, Math.ceil(totalUsers / args.dailyInstalls));
|
|
320
|
+
}
|
|
321
|
+
const recommendations = [
|
|
322
|
+
`Enroll at least ${usersPerGroup} new installs per group and read D${args.retentionDay} only after every enrolled install is fully observed through day ${args.retentionDay}.`,
|
|
323
|
+
args.minimumDetectableEffectPercentagePoints === undefined
|
|
324
|
+
? "Sample size covers each signed assumed treatment effect; targetRate is the alternative requiring the largest equal-allocation budget."
|
|
325
|
+
: "The explicit MDE is directionless; sample size covers both feasible directions and targetRate is the more conservative alternative.",
|
|
326
|
+
"Assign groups at install time with a stable hash of a local pseudonymous ID; never reassign a player between groups.",
|
|
327
|
+
"Enroll for whole weeks (at least 7 days) so weekday and weekend installs appear in every group.",
|
|
328
|
+
"Fix the readout day and metric before launch. Repeatedly peeking and stopping on a significant hint inflates false positives.",
|
|
329
|
+
"Export each group as its own complete cohort (or one cohort per group and install date) in the cohort batch format, then run idk telemetry compare with the control as baseline.",
|
|
330
|
+
];
|
|
331
|
+
if (comparisons > 1)
|
|
332
|
+
recommendations.push(`The plan uses alpha ${adjustedAlpha} per comparison (Bonferroni for ${comparisons} treatments).`);
|
|
333
|
+
if (enrollmentDays === null)
|
|
334
|
+
recommendations.push("Pass dailyInstalls to estimate the enrollment period and the earliest readout day.");
|
|
335
|
+
return {
|
|
336
|
+
retentionDay: args.retentionDay,
|
|
337
|
+
baselineRate,
|
|
338
|
+
minimumDetectableEffectPercentagePoints: mde,
|
|
339
|
+
targetRate,
|
|
340
|
+
alpha,
|
|
341
|
+
adjustedAlpha,
|
|
342
|
+
power,
|
|
343
|
+
usersPerGroup,
|
|
344
|
+
totalUsers,
|
|
345
|
+
groups: args.groups.map((group, index) => ({
|
|
346
|
+
id: group.id, scenario: group.scenario ?? null, role: index === 0 ? "control" : "treatment",
|
|
347
|
+
assumedRetention: group.retention ?? null, requiredUsers: usersPerGroup,
|
|
348
|
+
})),
|
|
349
|
+
observationWindow: {
|
|
350
|
+
observedThroughDay: args.retentionDay,
|
|
351
|
+
enrollmentDays,
|
|
352
|
+
earliestReadoutDay: enrollmentDays === null ? null : enrollmentDays + args.retentionDay + 1,
|
|
353
|
+
},
|
|
354
|
+
recommendations,
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
/** FNV-1a 32-bit hash; deterministic and dependency-free. */
|
|
358
|
+
function fnv1a(text) {
|
|
359
|
+
let hash = 0x811c9dc5;
|
|
360
|
+
for (let index = 0; index < text.length; index++) {
|
|
361
|
+
hash ^= text.charCodeAt(index);
|
|
362
|
+
hash = Math.imul(hash, 0x01000193);
|
|
363
|
+
}
|
|
364
|
+
return hash >>> 0;
|
|
365
|
+
}
|
|
366
|
+
/** Deterministic, uniform group assignment for a local pseudonymous user ID. */
|
|
367
|
+
export function assignExperimentGroup(userId, experimentId, groupIds) {
|
|
368
|
+
if (typeof userId !== "string" || !userId)
|
|
369
|
+
throw new RangeError("userId must be a non-empty string");
|
|
370
|
+
if (groupIds.length === 0)
|
|
371
|
+
throw new RangeError("At least one group is required");
|
|
372
|
+
return groupIds[fnv1a(`${experimentId}\u0000${userId}`) % groupIds.length];
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Plan, apply and validate a retention patch in one step. The input scenario is
|
|
376
|
+
* never modified. Non-ready plans return no scenario and keep their warnings.
|
|
377
|
+
*/
|
|
378
|
+
export function planScenarioRetentionUpdate(scenario, observation) {
|
|
379
|
+
const plan = planRetentionPatch(observation, scenario.monetization?.retention);
|
|
380
|
+
if (plan.status !== "ready")
|
|
381
|
+
return { plan, changes: [] };
|
|
382
|
+
const patched = applyRetentionPatch({ scenario, observation });
|
|
383
|
+
const changes = RETENTION_DAYS.map((day) => {
|
|
384
|
+
const key = `d${day}`;
|
|
385
|
+
return { key, before: scenario.monetization?.retention?.[key] ?? null, after: patched.monetization?.retention?.[key] ?? null };
|
|
386
|
+
}).filter(change => change.before !== change.after);
|
|
387
|
+
return { plan, scenario: patched, changes };
|
|
388
|
+
}
|
|
389
|
+
//# sourceMappingURL=telemetryLoop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetryLoop.js","sourceRoot":"","sources":["../../src/ltv/telemetryLoop.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,aAAa,EAAE,kBAAkB,GAGzF,MAAM,UAAU,CAAC;AAElB;;;;GAIG;AAEH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAU,CAAC;AAgCtD,MAAM,UAAU,GAAG,qCAAqC,CAAC;AACzD,MAAM,YAAY,GAAG,qBAAqB,CAAC;AAC3C,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAAC,CAAC;AACpG,MAAM,UAAU,GAAG,IAAI,GAAG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|
|
3
|
+
import type { Money } from "../money/types";
|
|
4
|
+
import { type ModelFactory } from "../scenario/registry";
|
|
5
|
+
import type { Action, AnalyticHints, Model, SimContext, SimState } from "../sim/types";
|
|
6
|
+
export declare const EXPONENTIAL_MODEL_ID: "exponential";
|
|
7
|
+
/**
|
|
8
|
+
* Parameters of the built-in `exponential` model.
|
|
9
|
+
*
|
|
10
|
+
* Level `L` of the generator produces `idleIncome + baseIncome * (1 + g + ... + g^(L-1))` per second, where
|
|
11
|
+
* `g = growthRate`. `growthRate: 1` is the linear generator. The next level costs `costBase * costGrowth^L`.
|
|
12
|
+
* `softCap` compresses production above `softCap.startsAt`. `maxLevel` stops further purchases.
|
|
13
|
+
* `stochastic` adds seeded critical ticks, drops, and timed events on top of that income (see `sim/stochastic`).
|
|
14
|
+
*/
|
|
15
|
+
export declare const exponentialParamsSchema: z.ZodObject<{
|
|
16
|
+
idleIncome: z.ZodDefault<z.ZodString>;
|
|
17
|
+
baseIncome: z.ZodDefault<z.ZodString>;
|
|
18
|
+
growthRate: z.ZodDefault<z.ZodNumber>;
|
|
19
|
+
costBase: z.ZodDefault<z.ZodString>;
|
|
20
|
+
costGrowth: z.ZodDefault<z.ZodNumber>;
|
|
21
|
+
maxLevel: z.ZodOptional<z.ZodNumber>;
|
|
22
|
+
softCap: z.ZodOptional<z.ZodObject<{
|
|
23
|
+
kind: z.ZodDefault<z.ZodEnum<{
|
|
24
|
+
log: "log";
|
|
25
|
+
pow: "pow";
|
|
26
|
+
sqrt: "sqrt";
|
|
27
|
+
}>>;
|
|
28
|
+
startsAt: z.ZodString;
|
|
29
|
+
strength: z.ZodOptional<z.ZodNumber>;
|
|
30
|
+
}, z.core.$strip>>;
|
|
31
|
+
stochastic: z.ZodOptional<z.ZodObject<{
|
|
32
|
+
crit: z.ZodOptional<z.ZodObject<{
|
|
33
|
+
chance: z.ZodNumber;
|
|
34
|
+
multiplier: z.ZodNumber;
|
|
35
|
+
}, z.core.$strip>>;
|
|
36
|
+
drops: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
37
|
+
id: z.ZodString;
|
|
38
|
+
ratePerSec: z.ZodNumber;
|
|
39
|
+
rewardIncomeSec: z.ZodNumber;
|
|
40
|
+
}, z.core.$strip>>>;
|
|
41
|
+
events: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
42
|
+
id: z.ZodString;
|
|
43
|
+
windowSec: z.ZodNumber;
|
|
44
|
+
chance: z.ZodNumber;
|
|
45
|
+
durationSec: z.ZodNumber;
|
|
46
|
+
incomeMultiplier: z.ZodNumber;
|
|
47
|
+
}, z.core.$strip>>>;
|
|
48
|
+
}, z.core.$strip>>;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
export type ExponentialParams = z.output<typeof exponentialParamsSchema>;
|
|
51
|
+
export type ExponentialParamsInput = z.input<typeof exponentialParamsSchema>;
|
|
52
|
+
export declare const exponentialVarsSchema: z.ZodObject<{
|
|
53
|
+
level: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
54
|
+
}, z.core.$strip>;
|
|
55
|
+
export type ExponentialVars = Readonly<{
|
|
56
|
+
level?: number;
|
|
57
|
+
}>;
|
|
58
|
+
export declare function parseExponentialParams(raw: unknown): ExponentialParams;
|
|
59
|
+
/**
|
|
60
|
+
* The generator shared by `exponential` and `prestige`. `modelId` names the model in error messages,
|
|
61
|
+
* action ids, and milestone keys.
|
|
62
|
+
*/
|
|
63
|
+
export type GeneratorCore = Readonly<{
|
|
64
|
+
params: ExponentialParams;
|
|
65
|
+
levelOf: (state: Readonly<{
|
|
66
|
+
vars?: unknown;
|
|
67
|
+
}>) => number;
|
|
68
|
+
/** Production before the prestige multiplier, after the soft cap. */
|
|
69
|
+
production: <N>(E: Engine<N>, level: number) => N;
|
|
70
|
+
/** Production times the state's prestige multiplier. Deterministic: purchase quotes read this. */
|
|
71
|
+
income: <N, U extends string, Vars>(ctx: SimContext<N, U, Vars>, state: SimState<N, U, Vars>, level?: number) => Money<N, U>;
|
|
72
|
+
/**
|
|
73
|
+
* Income the runner credits: `income` times this tick's seeded stochastic factor, read from `ctx.seed` (0 when unset)
|
|
74
|
+
* and `state.t`. Without an active `stochastic` spec it is `income`.
|
|
75
|
+
*/
|
|
76
|
+
realizedIncome: <N, U extends string, Vars>(ctx: SimContext<N, U, Vars>, state: SimState<N, U, Vars>) => Money<N, U>;
|
|
77
|
+
/** True when a `stochastic` spec can change a tick's income. */
|
|
78
|
+
stochastic: boolean;
|
|
79
|
+
/** Price of `count` levels from `level`. */
|
|
80
|
+
price: <N>(E: Engine<N>, level: number, count: number) => N;
|
|
81
|
+
/** Every level's purchase price summed. */
|
|
82
|
+
investedValue: <N>(E: Engine<N>, level: number) => N;
|
|
83
|
+
remainingLevels: (level: number) => number;
|
|
84
|
+
buyAction: <N, U extends string, Vars>(ctx: SimContext<N, U, Vars>) => Action<N, U, Vars>;
|
|
85
|
+
milestones: <N, U extends string, Vars>(ctx: SimContext<N, U, Vars>, prev: SimState<N, U, Vars>, next: SimState<N, U, Vars>) => string[];
|
|
86
|
+
analytic: <N, U extends string, Vars>(ctx: SimContext<N, U, Vars>, state: SimState<N, U, Vars>) => AnalyticHints<N, U, Vars>;
|
|
87
|
+
}>;
|
|
88
|
+
export declare function createGeneratorCore(modelId: string, params: ExponentialParams): GeneratorCore;
|
|
89
|
+
/** Next-level income increment `baseIncome * growthRate^level`, before the soft cap and multiplier. */
|
|
90
|
+
export declare function exponentialLevelIncrement<N>(E: Engine<N>, params: ExponentialParams, level: number): N;
|
|
91
|
+
export declare function createExponentialModel<N, U extends string = string>(params?: ExponentialParamsInput): Model<N, U, ExponentialVars>;
|
|
92
|
+
/**
|
|
93
|
+
* Built-in `exponential@1`: one geometric generator with an optional level cap and soft cap.
|
|
94
|
+
*/
|
|
95
|
+
export declare function createExponentialFactory(): ModelFactory;
|