@splithub/node 0.2.1 → 0.2.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/dist/index.d.ts CHANGED
@@ -1,11 +1,19 @@
1
- import { SplitHubConfig, Experiment, Flow } from '@splithub/core';
2
- import { VariantCounts, Verdict, MeanComparison } from '@splithub/stats';
1
+ import { SplitHubConfig, Experiment } from '@splithub/core';
3
2
  import { IncomingMessage, ServerResponse } from 'node:http';
4
3
 
5
4
  /** How far a goal may precede the exposure it converts, for clock differences between server and browser. */
6
5
  declare const ATTRIBUTION_SKEW_MS = 60000;
7
6
  /** Events of one goal from one visitor counted per UTC day. */
8
7
  declare const GOAL_DAILY_CAP = 50;
8
+ /** Unique exposed and unique converted visitors of one variant. */
9
+ interface VariantCounts {
10
+ variant: string;
11
+ exposures: number;
12
+ conversions: number;
13
+ revenue?: number;
14
+ revenueSum?: number;
15
+ revenueSumSq?: number;
16
+ }
9
17
  /** Per-variant counts every store returns: `revenueSum` / `revenueSumSq` are over per-visitor revenue (non-converted visitors add 0). */
10
18
  interface AttributedCounts extends VariantCounts {
11
19
  revenue: number;
@@ -133,8 +141,10 @@ type FetchHandler = (request: Request) => Promise<Response>;
133
141
  * One handler for ingest and results, mountable at any path:
134
142
  *
135
143
  * POST {base} → ingest an event batch
136
- * GET {base}/status → all experiments with counts and verdict headline
137
- * GET {base}/results/:id → full verdict for one experiment
144
+ * GET {base}/status → all experiments with exposures, visitors and days
145
+ * GET {base}/results/:id → visitors, conversions, rate (and revenue) per variant
146
+ *
147
+ * Reads are raw counts; verdicts and recommendations are SplitHub Cloud's.
138
148
  * GET {base}/health → { ok: true }
139
149
  *
140
150
  * Works in Next.js route handlers, Remix, Hono, Bun, Deno and Node (via `toNodeListener`).
@@ -150,85 +160,45 @@ declare function createSplitHubHandler(options: HandlerOptions): FetchHandler;
150
160
  */
151
161
  declare function toNodeListener(handler: FetchHandler): (req: IncomingMessage, res: ServerResponse) => void;
152
162
 
153
- /** One level of a multivariate factor, summed over every combination that uses it. */
154
- interface FactorLevelResult {
155
- level: string;
156
- exposures: number;
163
+ /** Self-hosted reads give counts; verdicts and recommendations are computed by SplitHub Cloud. */
164
+ declare const ANALYSIS_UNAVAILABLE: {
165
+ available: false;
166
+ message: string;
167
+ url: string;
168
+ };
169
+ interface RawVariant {
170
+ variant: string;
171
+ /** Unique visitors counted in this variant (first exposure decides). */
172
+ visitors: number;
173
+ /** Visitors who reached the goal after their exposure. */
157
174
  conversions: number;
175
+ /** conversions / visitors, 0 without visitors. */
158
176
  rate: number;
159
- /** Relative lift vs the factor's first level; null for that level itself. */
160
- relativeLift: number | null;
161
- /** Fixed-horizon p-value, for reference; null for the first level. */
162
- pValue: number | null;
163
- /** Always-valid p-value (what `significant` is decided on); null for the first level. */
164
- sequentialPValue: number | null;
165
- /** Probability this level beats the first one, same formula as the per-combination table; null for the first level. */
166
- probabilityToBeat: number | null;
167
- /** Always-valid, Holm-corrected across every factor level and combination of the experiment. */
168
- significant: boolean;
169
- }
170
- /** A multivariate factor read on its own (its main effect), independent of the other factors. */
171
- interface FactorResult {
172
- key: string;
173
- levels: FactorLevelResult[];
174
- /** The level that beats the first one significantly with the largest lift, if any. */
175
- best: string | null;
177
+ /** Sum of per-visitor revenue, when the goal carries revenue. */
178
+ revenue?: number;
179
+ /** Sum of squared per-visitor revenue, when the store reports it. */
180
+ revenueSumSq?: number;
176
181
  }
177
- /** Revenue per visitor (visitors who did not pay count as 0), compared with the control by Welch's t-test. */
178
- interface RevenueResult {
179
- variants: Array<{
180
- variant: string;
181
- visitors: number;
182
- revenue: number;
183
- perVisitor: number;
184
- }>;
185
- /** Fixed-horizon and always-valid numbers per variant; `significant` uses the always-valid p, Holm-corrected. */
186
- comparisons: MeanComparison[];
182
+ interface RawMetric {
183
+ metric: string;
184
+ role: 'secondary' | 'guardrail';
185
+ worse?: 'higher' | 'lower';
186
+ variants: RawVariant[];
187
187
  }
188
- interface ExperimentResults {
188
+ interface RawResults {
189
189
  experiment: string;
190
190
  kind: string;
191
191
  status: string;
192
192
  goal: string | null;
193
193
  description: string | null;
194
- verdict: Verdict;
195
- /** Days until a verdict at the current traffic: 0 once decided, null when there is no estimate. */
196
- daysToVerdict: number | null;
197
- /** Visitors per day behind `daysToVerdict`, null when unknown. */
198
- visitorsPerDay: number | null;
199
- /** Multivariate experiments only: each factor's main effect. */
200
- factors?: FactorResult[];
201
- /** Present when the store reports `revenueSum` and `revenueSumSq` per variant. */
202
- revenue?: RevenueResult;
203
- }
204
- interface ResultsOptions {
205
- now?: Date;
206
- /** Days of data; defaults to the span between the first and last exposure in `store.summaries()`. */
207
- days?: number;
208
- /** Visitors per day for `daysToVerdict`; defaults to visitors / days. */
209
- visitorsPerDay?: number;
210
- /** The experiment's summary when the caller already has it (saves a `summaries()` call). */
211
- summary?: ExperimentSummary | null;
194
+ /** Declared order: the first variant is the control. */
195
+ variants: RawVariant[];
196
+ metrics?: RawMetric[];
197
+ /** Days between the first and the last exposure, one decimal; 0 without data. */
198
+ days: number;
199
+ analysis: typeof ANALYSIS_UNAVAILABLE;
212
200
  }
213
- /**
214
- * Main effects of a multivariate experiment: for each factor, every level's
215
- * visitors and conversions summed over the combinations that use it, compared
216
- * with the factor's first level. Same tests as the verdict. Significance is
217
- * Holm-corrected across all factor levels and, when `familyPValues` carries the
218
- * combinations' always-valid p-values, across those too, so reading factors and
219
- * combinations together still keeps the 5% false positive rate.
220
- */
221
- declare function factorEffects(experiment: Experiment, counts: VariantCounts[], options?: {
222
- familyPValues?: number[];
223
- }): FactorResult[];
224
- /**
225
- * Expected traffic shares of the variants under a targeting flow. Splits mix
226
- * their outputs by weight. A condition sends an unknown share of visitors each
227
- * way, so the split is only defined when every branch that reaches a variant
228
- * leads to the same proportions. Null when it depends on who visits.
229
- */
230
- declare function flowExpectedShares(experiment: Experiment, flow: Flow): number[] | null;
231
- interface StatusRow {
201
+ interface RawStatusRow {
232
202
  experiment: string;
233
203
  kind: string;
234
204
  status: string;
@@ -236,28 +206,17 @@ interface StatusRow {
236
206
  description: string | null;
237
207
  exposures: number;
238
208
  visitors: number;
209
+ /** Whole days with data, at least 1 once there is any; 0 without data. */
239
210
  days: number;
240
- verdict: Verdict['status'] | null;
241
- /** Short text for tables: "#2 wins +15.9%", "#2 +3.1% (too early)", "no difference", "SRM! check setup", "no data". Ordinals, not names: variant names can be long. */
242
- headline: string | null;
243
- /** Leading variant: its name, its ordinal in the declared order (#1 is the control) and the relative lift. */
244
- best: {
245
- variant: string;
246
- index: number;
247
- lift: number | null;
248
- } | null;
249
- /** `verdict.sample.quality`, null without a goal or data. */
250
- sample: Verdict['sample']['quality'] | null;
251
- /** `verdict.sample.stars` (data quality, 0..5), null without a goal or data. */
252
- stars: number | null;
253
211
  }
254
212
  /** An experiment of the config, or the holdout comparison for `__holdout`. */
255
213
  declare function resultsExperiment(config: SplitHubConfig, key: string): Experiment | null;
256
- declare function experimentResults(config: SplitHubConfig, store: Store, key: string, options?: ResultsOptions): Promise<ExperimentResults | null>;
257
- declare function statusTable(config: SplitHubConfig, store: Store): Promise<StatusRow[]>;
258
- /** The leading variant of a verdict with its ordinal (#1 is the control, in declared order). */
259
- declare function bestOf(v: Verdict): StatusRow['best'];
260
- declare function headlineFor(v: Verdict): string;
214
+ /** Counts per variant for one experiment, its secondary and guardrail goals included. No statistics. */
215
+ declare function rawResults(config: SplitHubConfig, store: Store, key: string, options?: {
216
+ summary?: ExperimentSummary | null;
217
+ }): Promise<RawResults | null>;
218
+ /** Every experiment with exposures, visitors and days; the holdout once it has visitors. */
219
+ declare function rawStatusTable(config: SplitHubConfig, store: Store): Promise<RawStatusRow[]>;
261
220
 
262
221
  type ValidationResult = {
263
222
  ok: true;
@@ -286,4 +245,4 @@ declare const attributionConformance: ConformanceCase[];
286
245
  /** Sorts by variant and keeps the compared fields, so any store's output can be `toEqual`-ed with `expected`. */
287
246
  declare function sortCounts(rows: StoreVariantCounts[]): AttributedCounts[];
288
247
 
289
- export { ATTRIBUTION_SKEW_MS, type AttributedCounts, type AttributionEvent, type ConformanceCase, type ExperimentResults, type ExperimentSummary, type FactorLevelResult, type FactorResult, type FetchHandler, GOAL_DAILY_CAP, type HandlerOptions, type ResultsOptions, type RevenueResult, type SqlDialect, type StatusRow, type Store, type StoreVariantCounts, type StoredEvent, type VariantCountsSql, type VariantCountsSqlOptions, attributeVariants, attributionConformance, bestOf, countsFromRow, createMemoryStore, createSplitHubHandler, experimentResults, factorEffects, flowExpectedShares, headlineFor, resultsExperiment, revenueOf, sortCounts, statusTable, toNodeListener, validateBatch, variantCountsSql };
248
+ export { ANALYSIS_UNAVAILABLE, ATTRIBUTION_SKEW_MS, type AttributedCounts, type AttributionEvent, type ConformanceCase, type ExperimentSummary, type FetchHandler, GOAL_DAILY_CAP, type HandlerOptions, type RawMetric, type RawResults, type RawStatusRow, type RawVariant, type SqlDialect, type Store, type StoreVariantCounts, type StoredEvent, type VariantCounts, type VariantCountsSql, type VariantCountsSqlOptions, attributeVariants, attributionConformance, countsFromRow, createMemoryStore, createSplitHubHandler, rawResults, rawStatusTable, resultsExperiment, revenueOf, sortCounts, toNodeListener, validateBatch, variantCountsSql };
package/dist/index.js CHANGED
@@ -1,221 +1,68 @@
1
1
  // src/handler.ts
2
2
  import { isCrawler } from "@splithub/core";
3
3
 
4
- // src/results.ts
4
+ // src/raw.ts
5
5
  import { getExperiment, HOLDOUT_KEY, holdoutExperiment } from "@splithub/core";
6
- import { compareMeans, compareVariants, computeVerdict, estimateDaysToVerdict, holm, VERDICT_DEFAULTS } from "@splithub/stats";
7
6
  var DAY_MS = 864e5;
8
- function factorLevels(experiment, factor, counts2) {
9
- return factor.levels.map((level) => {
10
- const combos = experiment.variants.filter((v) => v.levels?.[factor.key] === level).map((v) => v.key);
11
- const rows = counts2.filter((c) => combos.includes(c.variant));
12
- return { variant: level, exposures: rows.reduce((s, r) => s + r.exposures, 0), conversions: rows.reduce((s, r) => s + r.conversions, 0) };
13
- });
14
- }
15
- function factorPValues(experiment, counts2) {
16
- const out = [];
17
- for (const factor of experiment.factors ?? []) {
18
- const perLevel = factorLevels(experiment, factor, counts2);
19
- if (perLevel.every((l) => l.exposures > 0)) out.push(...compareVariants(perLevel).map((c) => c.sequential.pValue));
20
- }
21
- return out;
22
- }
23
- function factorEffects(experiment, counts2, options = {}) {
24
- if (!experiment.factors?.length) return [];
25
- const perFactor = experiment.factors.map((factor) => {
26
- const perLevel = factorLevels(experiment, factor, counts2);
27
- return { factor, perLevel, comparisons: perLevel.every((l) => l.exposures > 0) ? compareVariants(perLevel) : [] };
28
- });
29
- const all = perFactor.flatMap((f) => f.comparisons);
30
- const rejected = holm([...all.map((c) => c.sequential.pValue), ...options.familyPValues ?? []], 1 - VERDICT_DEFAULTS.confidence);
31
- const significant = new Map(all.map((c, i) => [c, rejected[i]]));
32
- return perFactor.map(({ factor, perLevel, comparisons }) => {
33
- const levels = perLevel.map((l, i) => {
34
- const cmp = i === 0 ? void 0 : comparisons.find((c) => c.variant === l.variant);
35
- return {
36
- level: l.variant,
37
- exposures: l.exposures,
38
- conversions: l.conversions,
39
- rate: l.exposures ? l.conversions / l.exposures : 0,
40
- relativeLift: cmp?.relativeLift ?? null,
41
- pValue: cmp?.pValue ?? null,
42
- sequentialPValue: cmp?.sequential.pValue ?? null,
43
- probabilityToBeat: cmp?.probabilityToBeat ?? null,
44
- significant: cmp ? Boolean(significant.get(cmp)) : false
45
- };
46
- });
47
- const winners = levels.filter((l) => l.significant && (l.relativeLift ?? 0) > 0).sort((a, b) => (b.relativeLift ?? 0) - (a.relativeLift ?? 0));
48
- return { key: factor.key, levels, best: winners[0]?.level ?? null };
49
- });
50
- }
51
- var sum = (xs) => xs.reduce((s, x) => s + x, 0);
52
- var sameShares = (a, b) => {
53
- const sa = sum(a);
54
- const sb = sum(b);
55
- return a.every((x, i) => Math.abs(x / sa - b[i] / sb) < 1e-9);
7
+ var ANALYSIS_UNAVAILABLE = {
8
+ available: false,
9
+ message: "Verdicts, stars and recommendations come with SplitHub Cloud.",
10
+ url: "https://splithub.io/cloud"
56
11
  };
57
- function flowExpectedShares(experiment, flow) {
58
- const keys = experiment.variants.map((v) => v.key);
59
- const zero = () => new Array(keys.length).fill(0);
60
- const memo = /* @__PURE__ */ new Map();
61
- const walk = (id, depth) => {
62
- if (!id) return { mass: zero(), known: true };
63
- if (depth > 64) return "unknown";
64
- const cached = memo.get(id);
65
- if (cached) return cached;
66
- const node = flow.nodes[id];
67
- let out;
68
- if (!node || node.type === "skip") out = { mass: zero(), known: true };
69
- else if (node.type === "variant") {
70
- const mass = zero();
71
- const i = keys.indexOf(node.variant);
72
- if (i >= 0) mass[i] = 1;
73
- out = { mass, known: true };
74
- } else {
75
- const raw = node.type === "split" ? node.outputs.filter((o) => o.weight > 0).map((o) => ({ weight: o.weight, reach: walk(o.to, depth + 1) })) : [{ weight: 1, reach: walk(node.then, depth + 1) }, { weight: 1, reach: walk(node.else, depth + 1) }];
76
- const branches = [];
77
- for (const b of raw) if (b.reach !== "unknown") branches.push({ weight: b.weight, reach: b.reach });
78
- const live = branches.filter((b) => sum(b.reach.mass) > 0);
79
- if (branches.length < raw.length) out = "unknown";
80
- else if (node.type === "split" && branches.every((b) => b.reach.known)) {
81
- const total = sum(branches.map((b) => b.weight));
82
- const mass = zero();
83
- for (const b of branches) b.reach.mass.forEach((m, i) => mass[i] += b.weight / total * m);
84
- out = { mass, known: true };
85
- } else if (live.length === 0) out = { mass: zero(), known: true };
86
- else if (live.every((b) => sameShares(b.reach.mass, live[0].reach.mass))) {
87
- const ref = live[0].reach.mass;
88
- out = { mass: ref.map((m) => m / sum(ref)), known: false };
89
- } else out = "unknown";
90
- }
91
- memo.set(id, out);
92
- return out;
93
- };
94
- const reach = walk(flow.start, 0);
95
- if (reach === "unknown" || sum(reach.mass) <= 0) return null;
96
- return reach.mass;
97
- }
98
12
  function resultsExperiment(config, key) {
99
13
  return getExperiment(config, key) ?? (key === HOLDOUT_KEY ? holdoutExperiment(config) : null);
100
14
  }
101
- function alignCounts(experiment, observed) {
15
+ function rawVariants(experiment, observed, withRevenue) {
102
16
  return experiment.variants.map((v) => {
103
17
  const row = observed.find((o) => o.variant === v.key);
18
+ const visitors = row?.exposures ?? 0;
19
+ const conversions = row?.conversions ?? 0;
20
+ const revenue = row?.revenueSum ?? row?.revenue;
104
21
  return {
105
22
  variant: v.key,
106
- exposures: row?.exposures ?? 0,
107
- conversions: row?.conversions ?? 0,
108
- revenue: row?.revenue ?? row?.revenueSum ?? 0,
109
- ...row?.revenueSum !== void 0 ? { revenueSum: row.revenueSum } : {},
110
- ...row?.revenueSumSq !== void 0 ? { revenueSumSq: row.revenueSumSq } : {}
23
+ visitors,
24
+ conversions,
25
+ rate: visitors > 0 ? conversions / visitors : 0,
26
+ ...withRevenue && revenue !== void 0 ? { revenue } : {},
27
+ ...withRevenue && row?.revenueSumSq !== void 0 ? { revenueSumSq: row.revenueSumSq } : {}
111
28
  };
112
29
  });
113
30
  }
114
- async function metricInputs(experiment, store) {
115
- const m = experiment.metrics;
116
- if (!m) return [];
117
- const list = [
118
- ...m.secondary.map((metric) => ({ metric, role: "secondary" })),
119
- ...m.guardrails.map((g) => ({ metric: g.goal, role: "guardrail", worse: g.worse }))
120
- ];
121
- return Promise.all(list.map(async (x) => ({ ...x, counts: alignCounts(experiment, await store.variantCounts(experiment.key, x.metric)) })));
122
- }
123
- async function experimentResults(config, store, key, options = {}) {
31
+ async function rawResults(config, store, key, options = {}) {
124
32
  const experiment = resultsExperiment(config, key);
125
33
  if (!experiment) return null;
126
34
  const goal2 = experiment.goal;
127
35
  const observed = goal2 ? await store.variantCounts(key, goal2) : [];
128
- const counts2 = alignCounts(experiment, observed);
129
- const metrics = goal2 ? await metricInputs(experiment, store) : [];
130
- const now = options.now ?? /* @__PURE__ */ new Date();
131
- const summary = options.summary !== void 0 ? options.summary : goal2 ? (await store.summaries()).find((s) => s.experiment === key) ?? null : null;
132
- const span = summary?.firstExposureAt != null && summary.lastExposureAt != null ? (summary.lastExposureAt - summary.firstExposureAt) / DAY_MS : void 0;
133
- const days = options.days ?? span;
134
- const visitors = counts2.reduce((s, c) => s + c.exposures, 0);
135
- const visitorsPerDay = options.visitorsPerDay ?? (days !== void 0 && days >= 1 / 24 && visitors > 0 ? visitors / days : null);
136
- let expected = { expectedWeights: experiment.variants.map((v) => v.weight) };
137
- if (experiment.flow) {
138
- const shares = flowExpectedShares(experiment, experiment.flow);
139
- expected = shares ? { expectedWeights: shares } : { skipSrm: "Split check skipped: targeting conditions decide which variant a visitor reaches, so the expected split depends on who visits." };
140
- }
141
- const isMvt = experiment.kind === "mvt" && Boolean(goal2);
142
- const familyPValues = isMvt ? factorPValues(experiment, counts2) : void 0;
143
- const limits = { ...experiment.minDays !== void 0 ? { minDays: experiment.minDays } : {}, ...experiment.goodSample !== void 0 ? { goodSample: experiment.goodSample } : {} };
144
- const verdict = goal2 ? computeVerdict(key, counts2, { ...expected, days, familyPValues, now, ...limits, ...metrics.length ? { metrics } : {} }) : { ...computeVerdict(key, [], { now, ...limits }), message: "No goal configured for this experiment; add `goal` in splithub.config.ts." };
145
- const factors = isMvt ? factorEffects(experiment, counts2, { familyPValues: verdict.comparisons.map((c) => c.sequential.pValue) }) : void 0;
146
- const revenue = goal2 ? revenueResult(counts2, Boolean(config.goals.find((g) => g.key === goal2)?.revenue)) : void 0;
36
+ const goalHasRevenue = Boolean(goal2 && config.goals.find((g) => g.key === goal2)?.revenue);
37
+ const withRevenue = goalHasRevenue || observed.some((o) => (o.revenueSum ?? o.revenue ?? 0) !== 0);
38
+ const summary = options.summary !== void 0 ? options.summary : (await store.summaries()).find((s) => s.experiment === key) ?? null;
39
+ const span = summary?.firstExposureAt != null && summary.lastExposureAt != null ? (summary.lastExposureAt - summary.firstExposureAt) / DAY_MS : 0;
40
+ const m = goal2 ? experiment.metrics : void 0;
41
+ const metrics = m ? await Promise.all([
42
+ ...m.secondary.map(async (metric) => ({ metric, role: "secondary", variants: rawVariants(experiment, await store.variantCounts(key, metric), false) })),
43
+ ...m.guardrails.map(async (g) => ({ metric: g.goal, role: "guardrail", ...g.worse ? { worse: g.worse } : {}, variants: rawVariants(experiment, await store.variantCounts(key, g.goal), false) }))
44
+ ]) : void 0;
147
45
  return {
148
46
  experiment: key,
149
47
  kind: experiment.kind,
150
48
  status: experiment.status,
151
49
  goal: goal2,
152
- description: experiment.description,
153
- verdict,
154
- daysToVerdict: goal2 ? estimateDaysToVerdict(verdict, visitorsPerDay) : null,
155
- visitorsPerDay: visitorsPerDay === null ? null : Math.round(visitorsPerDay * 10) / 10,
156
- ...factors ? { factors } : {},
157
- ...revenue ? { revenue } : {}
158
- };
159
- }
160
- function revenueResult(counts2, goalHasRevenue) {
161
- if (!counts2.every((c) => typeof c.revenueSumSq === "number")) return void 0;
162
- const rows = counts2.map((c) => ({ variant: c.variant, n: c.exposures, sum: c.revenueSum ?? c.revenue ?? 0, sumSq: c.revenueSumSq ?? 0 }));
163
- if (!goalHasRevenue && rows.every((r) => r.sum === 0)) return void 0;
164
- return {
165
- variants: rows.map((r) => ({ variant: r.variant, visitors: r.n, revenue: r.sum, perVisitor: r.n > 0 ? r.sum / r.n : 0 })),
166
- comparisons: compareMeans(rows)
50
+ description: experiment.description ?? null,
51
+ variants: rawVariants(experiment, observed, withRevenue),
52
+ ...metrics?.length ? { metrics } : {},
53
+ days: Math.round(span * 10) / 10,
54
+ analysis: ANALYSIS_UNAVAILABLE
167
55
  };
168
56
  }
169
- async function statusTable(config, store) {
170
- const summaries = await store.summaries();
171
- const byKey = new Map(summaries.map((s) => [s.experiment, s]));
172
- const rows = [];
57
+ async function rawStatusTable(config, store) {
58
+ const byKey = new Map((await store.summaries()).map((s) => [s.experiment, s]));
173
59
  const holdout = holdoutExperiment(config);
174
60
  const all = holdout && byKey.has(HOLDOUT_KEY) ? [...config.experiments, holdout] : config.experiments;
175
- for (const exp of all) {
61
+ return all.map((exp) => {
176
62
  const s = byKey.get(exp.key);
177
- const days = s?.firstExposureAt && s.lastExposureAt ? Math.max(1, Math.ceil((s.lastExposureAt - s.firstExposureAt) / 864e5)) : 0;
178
- let verdict = null;
179
- let headline = null;
180
- let best = null;
181
- let sample = null;
182
- let stars = null;
183
- if (exp.goal && s) {
184
- const r = await experimentResults(config, store, exp.key, { summary: s });
185
- verdict = r?.verdict.status ?? null;
186
- headline = r ? headlineFor(r.verdict) : null;
187
- best = r ? bestOf(r.verdict) : null;
188
- sample = r?.verdict.sample.quality ?? null;
189
- stars = r?.verdict.sample.stars ?? null;
190
- }
191
- rows.push({ experiment: exp.key, kind: exp.kind, status: exp.status, goal: exp.goal, description: exp.description ?? null, exposures: s?.exposures ?? 0, visitors: s?.visitors ?? 0, days, verdict, headline, best, sample, stars });
192
- }
193
- return rows;
194
- }
195
- function bestOf(v) {
196
- const best = v.comparisons.slice().sort((a, b) => b.absoluteLift - a.absoluteLift)[0];
197
- const name = v.winner ?? best?.variant;
198
- if (!name) return null;
199
- const cmp = best && best.variant === name ? best : v.comparisons.find((c) => c.variant === name);
200
- return { variant: name, index: v.sample.variants.findIndex((x) => x.variant === name) + 1, lift: cmp?.relativeLift ?? null };
201
- }
202
- function headlineFor(v) {
203
- const best = bestOf(v);
204
- const lift = best?.lift != null ? `${best.lift >= 0 ? "+" : ""}${(best.lift * 100).toFixed(1)}%` : "";
205
- switch (v.status) {
206
- case "winner_found":
207
- return `#${best?.index ?? "?"} wins ${lift}`.trim();
208
- case "insufficient_sample":
209
- return best ? `#${best.index} ${lift} (too early)` : "too early";
210
- case "srm_detected":
211
- return "SRM! check setup";
212
- case "guardrail_breached":
213
- return `guardrail hit: ${v.guardrailBreached?.[0]?.metric ?? "?"}`;
214
- case "no_significant_difference":
215
- return "no difference";
216
- default:
217
- return "no data";
218
- }
63
+ const days = s?.firstExposureAt && s.lastExposureAt ? Math.max(1, Math.ceil((s.lastExposureAt - s.firstExposureAt) / DAY_MS)) : 0;
64
+ return { experiment: exp.key, kind: exp.kind, status: exp.status, goal: exp.goal, description: exp.description ?? null, exposures: s?.exposures ?? 0, visitors: s?.visitors ?? 0, days };
65
+ });
219
66
  }
220
67
 
221
68
  // src/validate.ts
@@ -311,9 +158,9 @@ function createSplitHubHandler(options) {
311
158
  if (request.method === "GET") {
312
159
  if (tail[1] === "health") return json(request, { ok: true, project: config.project });
313
160
  if (!authorized(request)) return json(request, { error: "unauthorized" }, 401);
314
- if (tail[1] === "status") return json(request, { project: config.project, experiments: await statusTable(config, store) });
161
+ if (tail[1] === "status") return json(request, { project: config.project, experiments: await rawStatusTable(config, store), analysis: ANALYSIS_UNAVAILABLE });
315
162
  if (tail[0] === "results" && tail[1]) {
316
- const r = await experimentResults(config, store, tail[1]);
163
+ const r = await rawResults(config, store, tail[1]);
317
164
  return r ? json(request, r) : json(request, { error: `unknown experiment "${tail[1]}"` }, 404);
318
165
  }
319
166
  }
@@ -632,22 +479,19 @@ function sortCounts(rows) {
632
479
  }).sort((a, b) => a.variant < b.variant ? -1 : a.variant > b.variant ? 1 : 0);
633
480
  }
634
481
  export {
482
+ ANALYSIS_UNAVAILABLE,
635
483
  ATTRIBUTION_SKEW_MS,
636
484
  GOAL_DAILY_CAP,
637
485
  attributeVariants,
638
486
  attributionConformance,
639
- bestOf,
640
487
  countsFromRow,
641
488
  createMemoryStore,
642
489
  createSplitHubHandler,
643
- experimentResults,
644
- factorEffects,
645
- flowExpectedShares,
646
- headlineFor,
490
+ rawResults,
491
+ rawStatusTable,
647
492
  resultsExperiment,
648
493
  revenueOf,
649
494
  sortCounts,
650
- statusTable,
651
495
  toNodeListener,
652
496
  validateBatch,
653
497
  variantCountsSql