feature
Event count
Counts how often a definition fired and lists each event’s time + payload fields.
What it studies
Frequency of bull-bar events — a metric total and a row table.
Key decisions
Piece | Why it matters |
|---|---|
| Binds Collect data; |
| Scratch buckets — not the same as |
| Aggregates after every event has been seen. |
Guard | Ignore other flows if the run attaches more than one. |
Full script
meta({ name: "Bull bar count", kind: "study" });
flows.declare({
slug: "bull-bar",
as: "bull",
});
results.declare({
id: "summary",
kind: "metric",
title: "Event count",
});
results.declare({
id: "rows",
kind: "table",
title: "Events",
});
export function onEvent(ctx) {
if (ctx.event.flow !== "bull") return;
ctx.collect("n", 1);
ctx.collect("rows", {
time: ctx.event.time,
range: ctx.event.payload.range,
});
}
export function onFinish(ctx) {
const n = ctx.collected("n").length;
ctx.publish("summary", { value: n, label: "Events" });
ctx.publish("rows", ctx.collected("rows"));
}