const xlsx = require('xlsx'); const fs = require('fs'); const DecisionTree = require('ml-decision-tree'); const inquirer = require('inquirer'); inquirer .prompt([ { type: 'input', name: 'fileName', message: 'Enter the name of the Excel file:', }, ]) .then(answers => { // Load the Excel workbook const workbook = xlsx.readFile(answers.fileName); // Select the first sheet const sheet = workbook.Sheets[workbook.SheetNames[0]]; // Get the maximum number of rows in the sheet const maxRow = xlsx.utils.decode_range(sheet['!ref']).e.r; // Initialize a list to store the data from the sheet const data = []; // Loop through the rows in the sheet for (let row = 2; row <= maxRow; row++) { const game = []; for (let col = 65; col < 71; col++) { game.push(sheet[String.fromCharCode(col) + row].v); } data.push(game); } // Read the data from the JSON file let storedData = {}; if (fs.existsSync('games.json')) { storedData = JSON.parse(fs.readFileSync('games.json', 'utf8')); } // Train the decision tree model const samples = storedData.samples || data; const labels = Array.from({ length: samples.length }, (_, i) => i % 60 + 1); const decisionTree = new DecisionTree(samples, labels, { gainFunction: 'gini' }); // Generate 10 possibilities based on the decision tree model const possibilities = []; for (let i = 0; i < 10; i++) { possibilities.push(decisionTree.predict(data[data.length - 1])); } // Write the updated data to the JSON file storedData.samples = samples.concat(data); fs.writeFileSync('games.json', JSON.stringify(storedData)); console.log(possibilities); });