Bugfix: Fix a bunch of crashes in the client-side map, but it's still not working :-/

This commit is contained in:
Starbeamrainbowlabs 2019-07-24 18:08:53 +01:00
parent bd42fa29a6
commit c6e6150d3e

View file

@ -3,7 +3,10 @@
import path from 'path';
import L from 'leaflet';
import * as tf from '@tensorflow/tfjs';
import {
loadLayersModel as tf_loadLayersModel,
tensor as tf_tensor
} from '@tensorflow/tfjs';
import chroma from 'chroma-js';
import GetFromUrl from './Helpers/GetFromUrl.mjs';
@ -18,7 +21,7 @@ class LayerAI {
north: Infinity,
south: -Infinity
};
for(let gateway of this.index) {
for(let gateway of this.index.index) {
result.east = Math.min(gateway.longitude, result.east);
result.west = Math.max(gateway.longitude, result.west);
@ -42,7 +45,7 @@ class LayerAI {
for(let gateway of this.index.index) {
this.gateways.set(
gateway.id,
await tf.loadModel(`${window.location.href}/${path.dirname(Config.ai_index_file)}/${gateway.id}`)
await tf_loadLayersModel(`${window.location.href}/${path.dirname(Config.ai_index_file)}/${gateway.id}/model.json`)
);
}
@ -51,7 +54,8 @@ class LayerAI {
}
generate_layer() {
return L.geoJSON(this.render_map(), {
let map = this.render_map();
return L.geoJSON(map, {
style: (feature) => { return {
fillColor: feature.properties.colour,
fillOpacity: 0.4
@ -69,10 +73,10 @@ class LayerAI {
map_bounds.west -= Config.border;
let coverage = [],
colour_scale = chroma.scale(
colour_scale = chroma.scale([
Config.colour_scale.min,
Config.colour_scale.max
).domain(
]).domain(
this.index.properties.rssi_min,
this.index.properties.rssi_max
);
@ -82,11 +86,12 @@ class LayerAI {
let max_predicted_rssi = -Infinity;
for(let [, ai] of this.gateways) {
let next_prediction = ai.predict(
tf_tensor([ lat, lng ], [1, 2])
);
max_predicted_rssi = Math.max(
max_predicted_rssi,
ai.predict(
tf.tensor1d([ lat, lng ])
)
next_prediction.arraySync()[0][0]
);
}
@ -110,7 +115,7 @@ class LayerAI {
]
},
properties: {
colour: colour_scale(max_predicted_rssi)
colour: colour_scale(max_predicted_rssi).toString()
}
})
}