at the beginning of my code, I create a new instance of my global variable DT, but when I try to reassign it a new object in a method my global variable doesn't change.
const functions = require('firebase-functions');
const DecisionTree = require("decision-tree")
var firebase = require('firebase-admin');
const cors = require('cors')({origin: true});
......
var boards;
var dt;
var training_dat;
var class_name = "NextMove";
var features = ["C1", "C2", "C3", "C4", "C5", "C6", "C7", "C7", "C9"];
ref.once('value').then(function(snap) {
boards = snap.val(); // query all data
training_data = new Array();
for(var B in boards){
training_data.push(boards[B]);
}
dt = new DecisionTree(training_data, class_name, features);
// HERE dt is a model with 500 rows.
});
exports.train = functions.https.onRequest((request, response) => {
.....
dt=new DecisionTree(new_training_data, class_name, features);
//HERE dt is a model with 1000 rows
response.send({output: "Training"});
});
exports.DOSOMETHING = functions.https.onRequest((request, response) => {
// if i call dt here it is still a model with 500 rows.
response.send({output: "Done"});
});
So I start my script, I get that dt is 500 rows. If I call "train" I get that it is 1000 rows. But when I call "DOSOMETHING" my variable dt has still 500 rows, like the precedent method didn't affect him.
I'm sorry it may sound stupid but I can't figure it out;