Aerostack
bar_chart

data-aggregate-stats Edge Function — Data

Data

Computes descriptive statistics (count, sum, min, max, mean, median, stdDev, variance, percentiles) for an array of numbers.

navin @navin verified
Updated Mar 12, 2026
GitHub

Edge function data-aggregate-stats Computes descriptive statistics (count, sum, min, max, mean, median, stdDev, variance, percentiles) for an array of numbers.. Deployed on Cloudflare Workers — zero cold starts, globally distributed. Mount it via your Aerostack workspace to call it from any AI agent.

terminal — aerostack cli
$ npx aerostack add navin/data-aggregate-stats
smart_toy

Use with AI Assistants

MCP

Connect Claude, Cursor, or any MCP-compatible client — then call this function by slug

① Add MCP Server

Add this once — access all Aerostack functions from your AI tool.

claude_desktop_config.json
{
  "mcpServers": {
    "aerostack": {
      "url": "https://mcp.aerostack.dev",
      "type": "http"
    }
  }
}

② Call this function

Ask your AI to use the call_function tool with this slug:

call_function
call_function({
  slug: "data-aggregate-stats",
  args: {
    "values": null,
    "percentiles": [
      25,
      50,
      75,
      90,
      95,
      99
    ]
  }
})

data-aggregate-stats — Descriptive statistics for numeric arrays

Computes count, sum, min, max, mean, median, stdDev, variance, and configurable percentiles for any array of numbers.


API

POST /api/data-aggregate-stats

Request body

Field Type Required Default Description
values number[] Array of numbers to analyze
percentiles number[] [25,50,75,90,95,99] Percentile points (0–100)

Success response (200)

{
  "success": true,
  "data": {
    "count": 8,
    "sum": 40,
    "min": 2,
    "max": 9,
    "mean": 5,
    "median": 4.5,
    "stdDev": 2,
    "variance": 4,
    "percentiles": { "p25": 4, "p50": 4.5, "p75": 5.75, "p90": 8.1, "p95": 8.55, "p99": 8.91 }
  }
}

Error responses

Code HTTP When
INVALID_INPUT 400 values is not a number array
INTERNAL_ERROR 500 Unexpected error

Usage

cURL
curl -X POST "$FUNCTION_URL" \
  -H "Content-Type: application/json" \
  -d '{"values": [10, 20, 30, 40, 50], "percentiles": [50, 90, 99]}'
TypeScript / JavaScript (HTTP)
const response = await fetch(FUNCTION_URL, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ values: responseTimes }),
});
const { data } = await response.json();
console.log(`p99: ${data.percentiles.p99}ms, mean: ${data.mean}ms`);
Direct import (Node / Bun / Deno)
import { aggregateStats } from '@aerostack/functions/data-aggregate-stats';

const stats = aggregateStats({ values: prices });
console.log(stats.median, stats.stdDev);

Use Cases

  • Computing API response time percentiles (p50, p95, p99) for performance dashboards
  • Summarizing revenue, pricing, or quantity data for reports
  • Analyzing sensor or telemetry data streams before storing aggregated results

Notes

  • Empty array returns null for all metrics except count (0) and sum (0)
  • Percentile computation uses linear interpolation between adjacent values
  • Percentile keys in the output are prefixed with p (e.g. p50, p99)

Metadata

upgrade Version 1.0.0
gavel License MIT
language Language typescript
cloud Provider aerostack

Tags

data
deployed_code

Build and publish your own functions

Write a TypeScript function, deploy it to the edge, and share it with thousands of developers — in minutes.

More Data Functions

Browse Data Functions →

Frequently asked questions

What does the data-aggregate-stats function do? +

data-aggregate-stats is a serverless edge function for data automation written in aerostack. Deploy it to Cloudflare Workers via your Aerostack workspace.

How do I deploy the data-aggregate-stats function? +

Install the Aerostack CLI and run: ```bash aerostack deploy function @navin/data-aggregate-stats ``` It will be live on Cloudflare Workers in seconds.

What runtime does data-aggregate-stats use? +

data-aggregate-stats runs on aerostack on the Cloudflare Workers edge runtime — zero cold starts, globally distributed.

Can I customise the data-aggregate-stats function? +

Yes. Fork the function from your Aerostack dashboard, modify the source, and redeploy. All changes are version-controlled.