data-aggregate-stats Edge Function — Data
DataComputes descriptive statistics (count, sum, min, max, mean, median, stdDev, variance, percentiles) for an array of numbers.
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.
npx aerostack add navin/data-aggregate-stats Use with AI Assistants
MCPConnect 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.
{
"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({
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
nullfor all metrics exceptcount(0) andsum(0) - Percentile computation uses linear interpolation between adjacent values
- Percentile keys in the output are prefixed with
p(e.g.p50,p99)
Metadata
Tags
Publisher
@navin verified
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 →data-array-group-by
by @navin
Groups an array of objects into a map keyed by the value of a specified property. Zero dependencies.
data-csv-parse
by @navin
Parses a CSV string into an array of row objects with headers, handling quoted fields, custom delimiters, and escaped characters.
data-csv-to-json
by @navin
Converts a CSV string to a typed JSON array, automatically inferring numbers, booleans, and null values from string fields.
data-deep-diff
by @navin
Computes a structural deep diff between two JSON-serializable values, classifying each change as added, removed, or modified.
data-sort-objects
by @navin
Sorts an array of objects by one or more fields with configurable direction, null handling, and nested field dot-notation support.
data-dedupe-array
by @navin
Removes duplicate items from an array using strict equality for primitives, deep equality for objects, or a key field for object arrays.
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.