39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { parseTja } from './parse';
|
|
import { factorize, Factors } from './factorize';
|
|
import { join } from 'path';
|
|
import { readFileSync } from 'fs';
|
|
|
|
async function predict() {
|
|
const args = process.argv.slice(2);
|
|
const workingDir = args[0];
|
|
const scriptDir = args[1];
|
|
const tjaPath = args[2];
|
|
const difficulty = (args[3] || 'oni').toLowerCase() as 'oni' | 'edit';
|
|
|
|
if (!tjaPath) {
|
|
console.error('Usage: bun script/predict.ts <working_dir> <script_dir> <tja_path> <difficulty>');
|
|
process.exit(1);
|
|
}
|
|
|
|
const factorJsonPath = join(scriptDir, 'factor.json');
|
|
const weights: Factors = JSON.parse(readFileSync(factorJsonPath, 'utf-8'));
|
|
|
|
const tjaContent = readFileSync(tjaPath, 'utf-8');
|
|
const parsed = parseTja(tjaContent);
|
|
|
|
if (!parsed || !parsed[difficulty]) {
|
|
console.error(`Error: Could not find difficulty '${difficulty}' in TJA.`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const factors = factorize(parsed[difficulty]!);
|
|
const prediction = Object.keys(factors).reduce((sum, key) =>
|
|
sum + (factors[key as keyof Factors] * weights[key as keyof Factors]), 0);
|
|
|
|
console.log(`Prediction for ${tjaPath} (${difficulty}):`);
|
|
console.log(`- Predicted Value: ${prediction.toFixed(4)}`);
|
|
console.log('- Factors:', factors);
|
|
}
|
|
|
|
predict();
|