My LoRaWAN Signal Mapping MSc summer project. This is a copy of the actual repository with personal information removed.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

94 lines
2.3 KiB

"use strict";
import haversine from 'haversine-distance';
import { normalise, clamp } from '../../common/Math.mjs';
class DatasetFetcher {
constructor({ settings, GatewayRepo, RSSIRepo, ReadingRepo }) {
this.settings = settings;
this.repo_gateway = GatewayRepo;
this.repo_rssi = RSSIRepo;
this.repo_reading = ReadingRepo;
}
normalise_latlng(lat, lng) {
return [
normalise(lat,
{ min: -90, max: +90 },
{ min: 0, max: 1 }
),
normalise(lng,
{ min: -180, max: +180 },
{ min: 0, max: 1 }
)
];
}
fetch_all(gateway_id) {
let gateway_location = this.repo_gateway.get_by_id(gateway_id);
let result = {
input: [],
output: []
};
for(let rssi of this.repo_rssi.iterate_gateway(gateway_id)) {
let next_input = this.normalise_latlng(rssi.latitude, rssi.longitude);
let distance_from_gateway = haversine(gateway_location, rssi);
next_input.push(clamp(
normalise(distance_from_gateway,
{ min: 0, max: 20000 },
{ min: 0, max: 1 }
),
0, 1))
result.input.push(next_input);
console.log(`Distance from gateway: ${haversine(gateway_location, rssi)}m`);
result.output.push([
clamp(normalise(rssi.rssi,
{ min: this.settings.ai.rssi_min, max: this.settings.ai.rssi_max },
{ min: 0, max: 1 }
), 0, 1)
]);
}
for(let reading of this.repo_reading.iterate_unreceived()) {
result.input.push(this.normalise_latlng(
reading.latitude,
reading.longitude
));
result.output.push([ 0 ]);
}
return result;
}
*fetch_input(gateway_id) {
for(let rssi of this.repo_rssi.iterate_gateway(gateway_id))
yield this.normalise_latlng(rssi.latitude, rssi.longitude);
for(let rssi of this.repo_reading.iterate_unreceived())
yield this.normalise_latlng(rssi.latitude, rssi.longitude);
}
*fetch_output(gateway_id) {
for(let rssi of this.repo_rssi.iterate_gateway(gateway_id)) {
yield [
clamp(normalise(rssi.rssi,
{ min: this.settings.ai.rssi_min, max: this.settings.ai.rssi_max },
{ min: 0, max: 1 }
), 0, 1)
];
}
// Yield 0 for every unreceived message, since we want to train it to predict a *terrible* signal where the gateway is not
for(let rssi of this.repo_reading.iterate_unreceived()) {
yield [ 0 ];
}
}
}
export default DatasetFetcher;