All files / shared labStats.ts

100% Statements 15/15
60% Branches 6/10
100% Functions 10/10
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35    1x                           1x 24x   1x 4x 4x 2x     4x 4x 4x 4x     4x      
import type { LabRunSummary } from './types'
 
const MINUTES_PER_HOUR = 60
 
export interface LabStats {
  runs: number
  shippedShare: number
  hours: number
  subagents: number
  turns: number
  minutesPerRun: number
  costPerRun: number
  costPerShipped: number | null
  toolErrorsPerRun: number
}
 
const sum = (runs: LabRunSummary[], pick: (run: LabRunSummary) => number) =>
  runs.reduce((total, run) => total + pick(run), 0)
 
export const labStats = (runs: LabRunSummary[]): LabStats => {
  const shipped = runs.filter((run) => run.outcome === 'deployed').length
  const cost = sum(runs, (run) => run.cost_usd)
  return {
    runs: runs.length,
    shippedShare: runs.length ? shipped / runs.length : 0,
    hours: sum(runs, (run) => run.minutes) / MINUTES_PER_HOUR,
    subagents: sum(runs, (run) => run.subagents),
    turns: sum(runs, (run) => run.turns),
    minutesPerRun: runs.length ? sum(runs, (run) => run.minutes) / runs.length : 0,
    costPerRun: runs.length ? cost / runs.length : 0,
    costPerShipped: shipped ? cost / shipped : null,
    toolErrorsPerRun: runs.length ? sum(runs, (run) => run.tool_errors) / runs.length : 0,
  }
}