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

flows.declare({ slug, as })

Binds Collect data; as is the ctx.event.flow name.

ctx.collect in onEvent only

Scratch buckets — not the same as results.declare ids.

ctx.publish in onFinish only

Aggregates after every event has been seen.

Guard ctx.event.flow !== "bull"

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"));
}

Next

  1. Examples

  2. Forward return

  3. Collect and publish