Write index JSON file to AI output directory

This commit is contained in:
Starbeamrainbowlabs 2019-07-22 12:40:19 +01:00
parent 92574bc98c
commit d9cf650019

View file

@ -41,7 +41,7 @@ class AITrainer {
}
async train_all() {
let index = {};
for(let gateway of this.repo_gateway.iterate()) {
let filename = path.join(this.root_dir, "..", this.settings.ai.output_directory, `${gateway.id}`);
console.log(filename);
@ -49,11 +49,27 @@ class AITrainer {
if(!fs.existsSync(path.dirname(filename)))
await fs.promises.mkdir(path.dirname(filename), { recursive: true });
await this.train_gateway(
gateway.id,
filename
);
if(!await this.train_gateway(gateway.id, filename)) {
this.l.warn(`Warning: Failed to train AI for ${gateway.id}.`);
continue;
}
index[gateway.id] = {
path: path.relative(
"./app",
this.settings.ai.output_directory
)
};
}
await fs.promises.writeFile(
path.join(
path.dirname(this.root_dir),
this.settings.ai.output_directory,
"index.json"
),
JSON.stringify(index)
);
}
/**
@ -85,6 +101,8 @@ class AITrainer {
await this.model.save(`file://${destination_filename}`);
console.log(result);
return true;
}
}