/**
 * Per-field bounded series: every match folds into running aggregates, a short window of match
 * counts for `rate`, and a trimmed ring of recent values for sparks.
 * Ported from oh-my-pi 9df0457b31 (MIT, Copyright Can Boluk et al.).
 */
import type { JobWidgetAgg } from "./spec-types.ts";
/** Points a series keeps for sparks. */
export declare const RING_POINTS = 240;
/**
 * Keys one field keeps a series for. Past it the oldest first-seen key that no spec block names is
 * dropped, so a field keyed per test or per path stays bounded for the life of the job.
 */
export declare const MAX_FIELD_KEYS = 256;
export interface TimedCount {
    t: number;
    n: number;
}
export interface TimedValue {
    t: number;
    v: number;
}
/** One key's (or all keys') accumulated matches. */
export interface WidgetSeries {
    /** Matches, including those that carried no number. */
    count: number;
    /** Numbers folded in. */
    values: number;
    first: number;
    last: number;
    min: number;
    max: number;
    sum: number;
    /** Matches per refresh time within the last {@link RATE_WINDOW_MS}, oldest first. */
    recent: TimedCount[];
    /** Newest values, oldest first; between {@link RING_POINTS} and twice that once full. */
    ring: TimedValue[];
    text?: string;
    line?: string;
    updatedAt: number;
}
export interface SeriesMatch {
    value: number | undefined;
    text: string | undefined;
    line: string;
    t: number;
}
/** Drops buckets older than the rate window from the front of `recent`. */
export declare function trimWindow(recent: TimedCount[], t: number): void;
/** Matches per second over the rate window. */
export declare function windowRate(recent: readonly TimedCount[], now: number, startTime: number): number;
/**
 * Reduce a series. `count` and `rate` are defined on an empty series (0); value aggregations are
 * `undefined` until a number arrived, and `change` is `undefined` when it would divide a move by
 * a zero start.
 */
export declare function aggregateSeries(series: WidgetSeries, agg: JobWidgetAgg, now: number, startTime: number): number | undefined;
/** Equal-count bucket means, at most `points` of them, each with its last point's time. */
export declare function downsample(ring: readonly TimedValue[], points: number): TimedValue[];
/**
 * Every field's series per key (`""` when its rules capture no key), plus every match merged.
 * A field keeps at most {@link MAX_FIELD_KEYS} keys; `pinned` keys (the ones spec blocks name)
 * are never evicted, so a keyed headline or spark never restarts its series.
 */
export declare class FieldStore {
    #private;
    constructor(keyed: ReadonlySet<string>, pinned?: ReadonlyMap<string, ReadonlySet<string>>);
    push(name: string, key: string, match: SeriesMatch): void;
    /** The merged series without `key`, else that key's; an empty series for an unseen field or key. */
    series(name: string, key?: string): WidgetSeries;
    /** How many keys a field holds a series for. */
    keyCount(name: string): number;
    /** A field's newest `limit` keys by first sight, oldest first, with their series. */
    keys(name: string, limit: number): [string, WidgetSeries][];
}
//# sourceMappingURL=field-state.d.ts.map