Implement visualizer

This commit is contained in:
Lukas | AstroGD 2024-06-10 18:23:13 +02:00
parent 11d807f289
commit c87d537951
Signed by: AstroGD
GPG Key ID: 82A5E6C236C535AA
3 changed files with 38 additions and 2 deletions

1
.gitignore vendored
View File

@ -138,3 +138,4 @@ userdata
# output
output.cnf
result.cnf

View File

@ -8,7 +8,8 @@
"bin": "dist/bin/"
},
"scripts": {
"start": "pnpm run build && node --enable-source-maps .",
"generate": "pnpm run build && node --enable-source-maps dist/generateRules.js",
"visualize": "pnpm run build && node --enable-source-maps dist/visualizeResult.js",
"test": "pnpm run build && pnpm run test:style",
"format": "prettier --write .",
"build": "tsc",
@ -35,4 +36,4 @@
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
}
}
}

View File

@ -0,0 +1,34 @@
// Sources used: https://stackoverflow.com/a/32599033
import { createReadStream } from "fs";
import { createInterface } from "readline";
import { visualizeValues } from "./src/visualizeValues";
async function parseInputFile(): Promise<number[]> {
const fileStream = createReadStream("./result.cnf");
const rl = createInterface({
input: fileStream,
crlfDelay: Infinity,
});
const result: number[] = [];
for await (const line of rl) {
if (!line.startsWith("v")) continue;
const values = line.split(" ").slice(1).map(Number);
for (const value of values) {
if (value <= 0) continue;
result.push(value);
}
}
return result;
}
async function main(): Promise<void> {
const values = await parseInputFile();
console.log("Result:");
visualizeValues(values);
}
main();