Skip to content

Dwell and membership

AnalyticsHTTPSDKCLIMCPDashboardaggregateByFacetsaggregate_by_facetsdistinctBy

One call answers how long entities spent in each state over a window, or how many are in each state right now.

The situation

A plant manager asks two questions every morning: where did the fleet’s time go yesterday, and how many machines are in each state now. Both should be one query, sliceable by model.

The recipe

reports/fleet.ts
const dwell = await lt.escalations.aggregateByFacets({
query: { entity: 'serialNumber' },
groupBy: { state: true, facets: ['model'] },
measure: { kind: 'dwell', window: { from: '2026-10-22T00:00:00Z', to: '2026-10-23T00:00:00Z' } },
});
// groups: [{ state: 'running', facets: { model: 'mx-200' }, dwellSeconds, sampleCount }, ...]
const now = await lt.escalations.aggregateByFacets({
query: { entity: 'serialNumber' },
groupBy: { state: true },
measure: { kind: 'membership' },
distinctBy: 'serialNumber',
});
// one group per state, count = machines, not rows
The same from a terminal
ltc esc aggregate-facets --entity serialNumber --group-state --group-facets model \
--window '{"from":"2026-10-22T00:00:00Z","to":"2026-10-23T00:00:00Z"}'

Dwell sums open-seconds per group, clipped to the half-open window. Membership counts rows open at an instant, or distinct entities with distinctBy.

The guarantee

A row missing a grouped facet forms a real null group rather than vanishing. Fields that would silently change the meaning (status, available, query-level paging) are rejected with a 400. Results over the group cap set overflow: true. See Analytics.