/** * The **Data Analysis Service** — computes statistics over the grid's live rows * so Photon AI can answer analytical questions ("what sells best?", "why is * revenue falling?", "show unusual values") with real numbers. * * ### Privacy is the point * Every statistic here is computed **in the browser, from `GridApi`**. Only the * resulting compact summary — counts, sums, a handful of top categories — is * ever sent to the language model, which does nothing but phrase it. Raw * customer rows never leave the page. * * That choice also makes this work at scale: a million-row dataset costs one * linear local pass and a few hundred tokens, where shipping rows to a model * would cost far more than any context window allows and still yield wrong * totals from a sample. * * ### Scope * These are descriptive statistics, deliberately. Correlation is linear * (Pearson) and the trend is a least-squares slope over an ordered measure; * neither is a forecast. When a user asks Photon AI to "predict next month", * the honest answer is the observed trend plus its direction, and the prompt * instructs the model to present it that way rather than inventing a forecast. * * @packageDocumentation */ import type { GridApi } from '../../core/grid-api'; /** Descriptive statistics for one numeric column. */ export interface NumericSummary { readonly colId: string; readonly header: string; readonly count: number; readonly sum: number; readonly mean: number; readonly min: number; readonly max: number; readonly median: number; readonly stdDev: number; /** Least-squares slope per row in the current order — positive means rising. */ readonly trendPerRow: number; /** Values further than {@link OUTLIER_Z} standard deviations from the mean. */ readonly outliers: readonly number[]; } /** One category's share of a measure. */ export interface CategoryBreakdown { readonly value: string; readonly count: number; readonly total: number; readonly share: number; } /** A breakdown of one measure across one dimension. */ export interface DimensionSummary { readonly dimensionColId: string; readonly dimensionHeader: string; readonly measureColId: string; readonly measureHeader: string; readonly distinctCount: number; readonly top: readonly CategoryBreakdown[]; readonly bottom: readonly CategoryBreakdown[]; } /** A linear relationship between two numeric columns. */ export interface CorrelationPair { readonly aColId: string; readonly bColId: string; /** Pearson coefficient in [-1, 1]. */ readonly r: number; } /** The complete local analysis handed to the model. */ export interface DatasetAnalysis { readonly totalRows: number; readonly visibleRows: number; readonly columnCount: number; readonly numeric: readonly NumericSummary[]; readonly dimensions: readonly DimensionSummary[]; readonly correlations: readonly CorrelationPair[]; /** Columns where some rows have no value, as `colId` → missing count. */ readonly missing: Readonly>; } /** Computes descriptive statistics over the grid's currently visible rows. */ export declare class DataAnalysisService { private readonly api; constructor(api: GridApi); /** * Analyses the rows the user is currently looking at — i.e. after filters. * That is almost always what an analytical question means: "what sells best" * asked with a region filter applied is a question about that region. */ analyze(): DatasetAnalysis; /** Descriptive stats for one numeric column, or `null` when it has no usable values. */ private summarizeNumeric; /** * Breaks each numeric measure down by each low-cardinality dimension. * * This is what answers "best selling product" and "which customers spend the * most": the top entries of (product × revenue) and (customer × spend). * Capped so a wide grid cannot produce a combinatorial explosion of pairs. */ private buildDimensions; /** Pearson correlation for every numeric pair, strongest first. */ private buildCorrelations; /** Counts empty values per column, omitting fully-populated ones. */ private countMissing; } //# sourceMappingURL=data-analysis-service.d.ts.map