MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / durationBucketSeries

Function durationBucketSeries

telemetry-dashboard/src/api.ts:697–744  ·  view source on GitHub ↗

"Session run length over time": one series per duration bucket, bucket-ordered.

(env: Env, range: Range)

Source from the content-addressed store, hash-verified

695
696/** "Session run length over time": one series per duration bucket, bucket-ordered. */
697async function durationBucketSeries(env: Env, range: Range): Promise<ApiResult> {
698 const batch = await env.DB.batch([
699 env.DB.prepare(
700 `SELECT day, value, sum(count) AS n
701 FROM daily_dim_counts
702 WHERE dim = 'duration_bucket' AND event = 'index' AND day BETWEEN ? AND ?
703 GROUP BY day, value`,
704 ).bind(range.from, range.to),
705 env.DB.prepare(COVERAGE_SQL),
706 ]);
707 const results = rowsOf<{ day: string; value: string; n: number }>(batch[0]);
708 const coveredThrough = firstOf<{ day: string | null }>(batch[1])?.day ?? null;
709
710 const labels = dayList(range);
711 const perBucket = new Map<string, Map<string, number>>();
712 for (const row of results) {
713 let series = perBucket.get(row.value);
714 if (!series) perBucket.set(row.value, (series = new Map()));
715 series.set(row.day, row.n ?? 0);
716 }
717
718 // Fixed buckets first and always present (a bucket with no runs is a real zero,
719 // and dropping it would silently renumber the ordinal colour ramp); anything
720 // unexpected from an older client is appended rather than hidden.
721 const extra = [...perBucket.keys()].filter((v) => !DURATION_BUCKETS.includes(v as never)).sort();
722 const order = [...DURATION_BUCKETS, ...extra];
723
724 const datasets = order.map((bucket) => ({
725 label: bucket,
726 data: densifyCovered(labels, perBucket.get(bucket) ?? new Map(), coveredThrough),
727 }));
728
729 return {
730 body: {
731 range,
732 metric: 'duration_buckets',
733 title: 'Indexing run length over time',
734 covered_through: coveredThrough,
735 labels,
736 datasets,
737 rows: labels.map((day, i) => ({
738 day,
739 ...Object.fromEntries(datasets.map((d) => [d.label, d.data[i] ?? null])),
740 })),
741 },
742 cacheControl: CACHE_CONTROL,
743 };
744}
745
746// ---------------------------------------------------------------------------
747// /api/breakdown — the bars and pies

Callers 1

timeseriesFunction · 0.85

Calls 10

firstOfFunction · 0.85
dayListFunction · 0.85
densifyCoveredFunction · 0.85
bindMethod · 0.80
mapMethod · 0.80
rowsOfFunction · 0.70
prepareMethod · 0.65
getMethod · 0.65
batchMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected