LoRaWAN-Signal-Mapping/server/train-ai/DatasetFetcher.mjs

56 lines
1.2 KiB
JavaScript
Raw Normal View History

"use strict";
import haversine from 'haversine-distance';
2019-07-30 14:42:37 +00:00
import {
normalise_lat,
normalise_lng,
normalise_rssi,
normalise_gateway_distance,
} from '../../common/Normalisers.mjs';
class DatasetFetcher {
constructor({ settings, GatewayRepo, RSSIRepo, ReadingRepo }) {
this.settings = settings;
this.repo_gateway = GatewayRepo;
this.repo_rssi = RSSIRepo;
this.repo_reading = ReadingRepo;
}
fetch_all(gateway_id) {
let gateway_location = this.repo_gateway.get_by_id(gateway_id);
let result = [];
for(let rssi of this.repo_rssi.iterate_gateway(gateway_id)) {
result.push({
2019-07-30 14:42:37 +00:00
input: {
latitude: normalise_lat(rssi.latitude),
longitude: normalise_lng(rssi.longitude),
distance: normalise_gateway_distance(
haversine(gateway_location, rssi)
)
},
output: [
normalise_rssi(rssi.rssi)
]
});
}
for(let reading of this.repo_reading.iterate_unreceived()) {
2019-07-30 14:15:34 +00:00
result.push({
2019-07-30 14:42:37 +00:00
input: {
latitude: normalise_lat(reading.latitude),
longitude: normalise_lng(reading.longitude),
distance: normalise_gateway_distance(
haversine(gateway_location, reading)
)
},
2019-07-30 14:28:31 +00:00
output: [ 0 ]
2019-07-30 14:15:34 +00:00
});
}
return result;
}
}
export default DatasetFetcher;