Browse Source

Fix remaining bugs in unified training mode

master
Starbeamrainbowlabs 2 years ago
parent
commit
06325a80bf
  1. 23
      server/Repos.SQLite/GatewayRepo.mjs
  2. 4
      server/train-ai/AITrainer.mjs

23
server/Repos.SQLite/GatewayRepo.mjs

@ -36,6 +36,11 @@ class GatewayRepo {
return count > 0;
}
/**
* Returns a garteway by it's id.
* @param {string} id The id to fetcht he gateway for.
* @return {object} The information recorded about the gateway with the specified id .
*/
get_by_id(id) {
return this.db.prepare(`SELECT * FROM gateways WHERE id = :id`).get({ id });
}
@ -48,6 +53,24 @@ class GatewayRepo {
iterate() {
return this.db.prepare(`SELECT * FROM gateways`).iterate();
}
/**
* Returns the average location of allt he currently registered gateways.
* @return {{latitude: number, longitude: number}} The lat longg coordinates of the average location of all the gateways.
*/
get_average_location() {
let count = 0, lat_sum = 0, lng_sum = 0;
for(let gateway of this.iterate()) {
lat_sum += gateway.latitude;
lng_sum += gateway.longitude;
count++;
}
return {
latitude: lat_sum / count,
longitude: lng_sum / count
};
}
}
export default GatewayRepo;

4
server/train-ai/AITrainer.mjs

@ -28,6 +28,8 @@ class AITrainer {
let training_result = await this.train_gateway(null, filepath);
let { latitude, longitude } = this.repo_gateway.get_average_location();
await fs.promises.writeFile(
path.join(
path.dirname(this.root_dir),
@ -43,7 +45,7 @@ class AITrainer {
index: [{
id: "Unified AI (not a real gateway)",
filename: "ai.json",
latitude: 0, longitude: 0,
latitude, longitude,
net_settings: training_result.net_settings
}]
}, null, "\t")

Loading…
Cancel
Save