#!/usr/bin/env bun
import { join } from "node:path";

import { collectLeaderboardRows, loadSearchSpace } from "../lib/results";

const repoRoot = join(import.meta.dir, "../../../..");
const searchSpace = await loadSearchSpace(repoRoot);
const leaderboard = await collectLeaderboardRows(repoRoot);
const byCandidateId = new Map(
  leaderboard.map((row) => [row.candidateId, row] as const)
);

console.log(`# ${searchSpace.id}`);
for (const candidate of searchSpace.candidates) {
  const row = byCandidateId.get(candidate.id);
  const status = row ? row.decision : "pending";
  const score =
    row && Number.isFinite(row.weightedScore)
      ? ` score=${row.weightedScore.toFixed(2)}`
      : "";
  const confirmation = row?.confirmation ? ` ${row.confirmation}` : "";
  console.log(
    `- ${candidate.id}: status=${status}${confirmation}${score}, mix=${candidate.mix}, prompt=${candidate.promptProfile}, lr=${candidate.learningRate}${candidate.seed ? `, seed=${candidate.seed}` : ""}`
  );
}
