|
|
|
@ -1,6 +1,5 @@
@@ -1,6 +1,5 @@
|
|
|
|
|
"use strict"; |
|
|
|
|
|
|
|
|
|
import path from 'path'; |
|
|
|
|
|
|
|
|
|
import brain from 'brain.js'; |
|
|
|
|
import haversine from 'haversine-distance'; |
|
|
|
@ -13,7 +12,6 @@ import {
@@ -13,7 +12,6 @@ import {
|
|
|
|
|
unnormalise_rssi |
|
|
|
|
} from '../../../common/Normalisers.mjs'; |
|
|
|
|
|
|
|
|
|
import GetFromUrl from '../Helpers/GetFromUrl.mjs'; |
|
|
|
|
|
|
|
|
|
class AIWrapper { |
|
|
|
|
constructor() { |
|
|
|
@ -36,15 +34,14 @@ class AIWrapper {
@@ -36,15 +34,14 @@ class AIWrapper {
|
|
|
|
|
// WebGL isn't available inside WebWorkers yet :-(
|
|
|
|
|
|
|
|
|
|
for(let gateway of this.index.index) { |
|
|
|
|
let net = new brain.NeuralNetwork(); |
|
|
|
|
let net = new brain.NeuralNetwork(/*gateway.net_settings*/); |
|
|
|
|
net.fromJSON( |
|
|
|
|
// TODO: Move this to the UI thread & do it only once?
|
|
|
|
|
await GetFromUrl(`${path.dirname(self.location.href)}/${path.dirname(this.Config.ai_index_file)}/${gateway.filename}`) |
|
|
|
|
gateway.frozen_net |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
this.gateways.set( |
|
|
|
|
gateway.id, |
|
|
|
|
net |
|
|
|
|
{ ai: net, latitude: gateway.latitude, longitude: gateway.longitude } |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
console.log("Model setup complete."); |
|
|
|
@ -64,21 +61,27 @@ class AIWrapper {
@@ -64,21 +61,27 @@ class AIWrapper {
|
|
|
|
|
for(let lng = this.map_bounds.west; lng < this.map_bounds.east; lng += this.Config.step.lng) { |
|
|
|
|
let max_predicted_rssi = -Infinity; |
|
|
|
|
|
|
|
|
|
for(let [gateway_id, ai] of this.gateways) { |
|
|
|
|
for(let [gateway_id, gateway] of this.gateways) { |
|
|
|
|
let distance_from_gateway = haversine( |
|
|
|
|
{ latitude: lat, longitude: lng }, |
|
|
|
|
this.gateways.get(gateway_id) |
|
|
|
|
gateway |
|
|
|
|
); |
|
|
|
|
let next_value = gateway.ai.run({ |
|
|
|
|
latitude: normalise_lat(lat), |
|
|
|
|
longitude: normalise_lng(lng), |
|
|
|
|
distance: normalise_gateway_distance( |
|
|
|
|
distance_from_gateway |
|
|
|
|
), |
|
|
|
|
}); |
|
|
|
|
if(isNaN(next_value[0])) { |
|
|
|
|
console.log(next_value); |
|
|
|
|
throw new Error("Error: Neural Network returned NaN"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// console.log(next_value);
|
|
|
|
|
max_predicted_rssi = Math.max( |
|
|
|
|
max_predicted_rssi, |
|
|
|
|
ai.run({ |
|
|
|
|
latitude: normalise_lat(lat), |
|
|
|
|
longitude: normalise_lng(lng), |
|
|
|
|
distance: normalise_gateway_distance( |
|
|
|
|
distance_from_gateway |
|
|
|
|
), |
|
|
|
|
})[0] |
|
|
|
|
next_value[0] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|