Anomaly Detection Helpers (cycle/anomaly.ts)

mperkins0155/gbrain · analytics, anomaly, statistics, cohort, detection

Pure functions that compute mean, stddev and detect statistical anomalies from daily‑count buckets for the find_anomalies operation.

// Source: https://github.com/mperkins0155/gbrain | License: MIT | Copyright 2026 Garry Tan
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * v0.29 — Anomaly detection: statistical helpers for the `find_anomalies` op.
 *
 * Pure functions over densified daily-count buckets. The engine layer runs the
 * SQL (CTE-shaped, with `generate_series` zero-fill so rare cohorts don't get
 * sparse-day biased baselines per codex C4#6) and hands the results here. This
 * keeps `findAnomalies` mostly testable without a database.
 *
 * Cohort kinds: tag, type. Year cohort is deferred to v0.30 pending proper
 * frontmatter date-field detection.
 */

import type { AnomalyResult } from '../types.ts';

/** One row of the densified daily-count series for a single cohort key. */
export in

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key