-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GitOrigin-RevId: e0f6d40a13463dd73d6a0b228a7701ba9d6263b2
- Loading branch information
1 parent
2f7bc48
commit ea62440
Showing
5 changed files
with
121 additions
and
53 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Rerun summarize 5x using a CSV file as input and outputting the summaries to another CSV. | ||
// Run like: | ||
// npx ts-node ./evaluations/rerunner.ts --outputFile "data1.csv" \ | ||
// --vertexProject "<your project name here>" \ | ||
// --inputFile "/usr/local/google/home/achvasta/Downloads/comments-with-vote-tallies.csv" | ||
// --rerunCount 3 | ||
|
||
import { Command } from "commander"; | ||
import { createObjectCsvWriter } from "csv-writer"; | ||
import { getCommentsFromCsv, getSummary } from "./runner_utils"; | ||
|
||
interface outputCsvFormat { | ||
run: number; | ||
summaryType: string; | ||
text: string; | ||
} | ||
|
||
async function main(): Promise<void> { | ||
// Parse command line arguments. | ||
const program = new Command(); | ||
program | ||
.option("-o, --outputFile <file>", "The output file name.") | ||
.option("-i, --inputFile <file>", "The input file name.") | ||
.option("-r, --rerunCount <count>", "The number of times to rerun.") | ||
.option("-v, --vertexProject <project>", "The Vertex Project name."); | ||
program.parse(process.argv); | ||
const options = program.opts(); | ||
|
||
const comments = await getCommentsFromCsv(options.inputFile); | ||
|
||
let outputTexts: outputCsvFormat[] = []; | ||
const csvWriter = createObjectCsvWriter({ | ||
path: options.outputFile, | ||
header: ["run", "summaryType", "text"], | ||
}); | ||
|
||
for (let i = 0; i < options.rerunCount; i++) { | ||
const summary = await getSummary(options.vertexProject, comments); | ||
outputTexts = outputTexts.concat([ | ||
{ | ||
run: i, | ||
summaryType: "VoteTally", | ||
text: summary.getText("MARKDOWN"), | ||
}, | ||
]); | ||
} | ||
|
||
csvWriter.writeRecords(outputTexts).then(() => console.log("CSV file written successfully.")); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Run the summarizer based on a CSV input and output the result as an hmtl page. | ||
|
||
import { Command } from "commander"; | ||
import * as fs from "fs"; | ||
import { marked } from "marked"; | ||
import { getCommentsFromCsv, getSummary } from "./runner_utils"; | ||
|
||
async function main(): Promise<void> { | ||
// Parse command line arguments. | ||
const program = new Command(); | ||
program | ||
.option("-o, --outputFile <file>", "The output file name.") | ||
.option("-i, --inputFile <file>", "The input file name.") | ||
.option("-v, --vertexProject <project>", "The Vertex Project name."); | ||
program.parse(process.argv); | ||
const options = program.opts(); | ||
|
||
const comments = await getCommentsFromCsv(options.inputFile); | ||
|
||
const summary = await getSummary(options.vertexProject, comments); | ||
const markdownContent = summary.getText("MARKDOWN"); | ||
const htmlContent = ` | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Summary</title> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
line-height: 1.6; | ||
max-width: 800px; | ||
margin: 0 auto; | ||
padding: 20px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
${marked(markdownContent)} | ||
</body> | ||
</html>`; | ||
|
||
const outputPath = `${options.outputFile}.html`; | ||
fs.writeFileSync(outputPath, htmlContent); | ||
console.log(`Written summary to ${outputPath}`); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters