tscircuit/autorouting-dataset-01

This code manages the hardware and electronic components for circuit design and PCB layout, defining components like resistors, capacitors, transistors, connectors, and footprints, and providing tools for component placement, PCB topology, and electrical connections.

Version
1.0.102
License
unset
Stars
4

scripts/run-benchmark/outputTabled.ts

import { buildBenchmarkTableRows } from "scripts/run-benchmark/buildBenchmarkTableRows"
import type { BenchmarkRow } from "types/run-benchmark/BenchmarkRow"
import type { Scenario } from "types/run-benchmark/Scenario"

/**
 * Render benchmark results as a table.
 */
const outputTabled = (inputs: {
  resultRowList: BenchmarkRow[]
  scenarioList: Scenario[]
}): string => {
  const { resultRowList, scenarioList } = inputs
  const { tableHeaderList, tableRowList } = buildBenchmarkTableRows({
    resultRowList,
  })

  const columnWidths = tableHeaderList.map((header, columnIndex) => {
    let maxWidth = header.length
    for (const rowCells of tableRowList) {
      const cellText = rowCells[columnIndex]
      if (cellText.length > maxWidth) {
        maxWidth = cellText.length
      }
    }
    return maxWidth
  })

  const separator = `+${columnWidths
    .map((width) => "-".repeat(width + 2))
    .join("+")}+`

  const headerLine = `| ${tableHeaderList
    .map((header, columnIndex) => header.padEnd(columnWidths[columnIndex]))
    .join(" | ")} |`

  const bodyLines = tableRowList.map(
    (rowCells) =>
      `| ${rowCells
        .map((cellText, columnIndex) =>
          cellText.padEnd(columnWidths[columnIndex]),
        )
        .join(" | ")} |`,
  )

  const tableText = [
    separator,
    headerLine,
    separator,
    ...bodyLines,
    separator,
  ].join("\n")

  const outputLines = [tableText, "", `Scenarios: ${scenarioList.length}`]

  return outputLines.join("\n")
}

export { outputTabled }