Pulling raw interval data from /api/v2/analytics/queues/realtime/summary to build custom OTel spans for service level tracking. The response gives me answered and abandoned counts per interval, but I’m not seeing a pre-calculated percentage field. Is the standard formula (answered / (answered + abandoned)) * 100 applied per interval then averaged, or should I sum the totals first? Here’s the snippet I’m using to aggregate the intervals:
You can’t just average the percentages. That’s a classic statistical trap. If you have one interval with 1 call answered and another with 1,000, averaging them gives equal weight to the tiny sample. You’ll get skewed data that looks worse than reality.
Sum the totals first. It’s the only way to get a true weighted average. Here’s how I structure the aggregation in my node scripts:
let totalAnswered = 0;
let totalAbandoned = 0;
intervals.forEach(interval => {
totalAnswered += interval.answered || 0;
totalAbandoned += interval.abandoned || 0;
});
const totalHandled = totalAnswered + totalAbandoned;
const serviceLevel = totalHandled > 0 ? (totalAnswered / totalHandled) * 100 : 0;
Make sure you check for division by zero if the queue is quiet. The API returns empty objects for quiet intervals sometimes, so default to zero. Also, remember this is realtime summary data. It resets every 24 hours. If you need historical SLA, you’ll need to hit the historical analytics endpoint instead. The realtime one is just for live dashboards.