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

Function durationBucketSeries

telemetry-dashboard/src/api.ts:498–545  ·  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

496
497/** "Session run length over time": one series per duration bucket, bucket-ordered. */
498async function durationBucketSeries(env: Env, range: Range): Promise<ApiResult> {
499 const batch = await env.DB.batch([
500 env.DB.prepare(
501 `SELECT day, value, sum(count) AS n
502 FROM daily_dim_counts
503 WHERE dim = 'duration_bucket' AND event = 'index' AND day BETWEEN ? AND ?
504 GROUP BY day, value`,
505 ).bind(range.from, range.to),
506 env.DB.prepare(COVERAGE_SQL),
507 ]);
508 const results = rowsOf<{ day: string; value: string; n: number }>(batch[0]);
509 const coveredThrough = firstOf<{ day: string | null }>(batch[1])?.day ?? null;
510
511 const labels = dayList(range);
512 const perBucket = new Map<string, Map<string, number>>();
513 for (const row of results) {
514 let series = perBucket.get(row.value);
515 if (!series) perBucket.set(row.value, (series = new Map()));
516 series.set(row.day, row.n ?? 0);
517 }
518
519 // Fixed buckets first and always present (a bucket with no runs is a real zero,
520 // and dropping it would silently renumber the ordinal colour ramp); anything
521 // unexpected from an older client is appended rather than hidden.
522 const extra = [...perBucket.keys()].filter((v) => !DURATION_BUCKETS.includes(v as never)).sort();
523 const order = [...DURATION_BUCKETS, ...extra];
524
525 const datasets = order.map((bucket) => ({
526 label: bucket,
527 data: densifyCovered(labels, perBucket.get(bucket) ?? new Map(), coveredThrough),
528 }));
529
530 return {
531 body: {
532 range,
533 metric: 'duration_buckets',
534 title: 'Indexing run length over time',
535 covered_through: coveredThrough,
536 labels,
537 datasets,
538 rows: labels.map((day, i) => ({
539 day,
540 ...Object.fromEntries(datasets.map((d) => [d.label, d.data[i] ?? null])),
541 })),
542 },
543 cacheControl: CACHE_CONTROL,
544 };
545}
546
547// ---------------------------------------------------------------------------
548// /api/breakdown — the bars and pies

Callers 1

timeseriesFunction · 0.85

Calls 10

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

Tested by

no test coverage detected