aboutsummaryrefslogtreecommitdiffstats
path: root/tools/compare-models/src/interactive.ts
blob: b93fc1d76db13dcf3922e13f8592c1c2cfe73978 (plain) (blame)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import * as readline from "node:readline";
import chalk from "chalk";

import type { ComparisonResult } from "./types";

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

export async function askQuestion(question: string): Promise<string> {
  return new Promise((resolve) => {
    rl.question(question, (answer) => {
      resolve(answer.trim());
    });
  });
}

export function displayComparison(
  index: number,
  total: number,
  result: ComparisonResult,
  blind: boolean = true,
): void {
  const divider = chalk.gray("".repeat(80));
  const header = chalk.bold.cyan(`\n=== Bookmark ${index}/${total} ===`);
  const title = chalk.bold.white(result.bookmark.title || "Untitled");
  const url = result.bookmark.content.url
    ? chalk.gray(result.bookmark.content.url)
    : "";
  const content = chalk.gray(
    result.bookmark.content.description
      ? result.bookmark.content.description.substring(0, 200) + "..."
      : "",
  );

  const modelAName = blind ? "Model A" : result.modelA;
  const modelBName = blind ? "Model B" : result.modelB;

  const modelATags = result.modelATags
    .map((tag) => chalk.green(`${tag}`))
    .join("\n");
  const modelBTags = result.modelBTags
    .map((tag) => chalk.yellow(`${tag}`))
    .join("\n");

  console.log(header);
  console.log(title);
  if (url) console.log(url);
  if (content) console.log(content);
  console.log(divider);
  console.log();
  console.log(chalk.green(`${modelAName}:`));
  if (modelATags) {
    console.log(modelATags);
  } else {
    console.log(chalk.gray("  (no tags)"));
  }
  console.log();
  console.log(chalk.yellow(`${modelBName}:`));
  if (modelBTags) {
    console.log(modelBTags);
  } else {
    console.log(chalk.gray("  (no tags)"));
  }
  console.log();
}

export function displayError(message: string): void {
  console.log(chalk.red(`\n✗ Error: ${message}\n`));
}

export function displayProgress(message: string): void {
  process.stdout.write(chalk.gray(message));
}

export function clearProgress(): void {
  process.stdout.write("\r\x1b[K");
}

export function close(): void {
  rl.close();
}

export function displayFinalResults(results: {
  model1Name: string;
  model2Name: string;
  model1Votes: number;
  model2Votes: number;
  skipped: number;
  errors: number;
  total: number;
}): void {
  const winner =
    results.model1Votes > results.model2Votes
      ? results.model1Name
      : results.model2Votes > results.model1Votes
        ? results.model2Name
        : "TIE";

  const divider = chalk.gray("".repeat(80));
  const header = chalk.bold.cyan("\n=== FINAL RESULTS ===");
  const model1Line = chalk.green(
    `${results.model1Name}: ${results.model1Votes} votes`,
  );
  const model2Line = chalk.yellow(
    `${results.model2Name}: ${results.model2Votes} votes`,
  );
  const skippedLine = chalk.gray(`Skipped: ${results.skipped}`);
  const errorsLine = chalk.red(`Errors: ${results.errors}`);
  const totalLine = chalk.bold(`Total bookmarks tested: ${results.total}`);
  const winnerLine =
    winner === "TIE"
      ? chalk.bold.cyan(`\n🏁 RESULT: TIE`)
      : chalk.bold.green(`\n🏆 WINNER: ${winner}`);

  console.log(divider);
  console.log(header);
  console.log(divider);
  console.log(model1Line);
  console.log(model2Line);
  console.log(skippedLine);
  console.log(errorsLine);
  console.log(divider);
  console.log(totalLine);
  console.log(winnerLine);
  console.log(divider);
}