"use strict"; import haversine from 'haversine-distance'; 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({ 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()) { result.push({ input: { latitude: normalise_lat(reading.latitude), longitude: normalise_lng(reading.longitude), distance: normalise_gateway_distance( haversine(gateway_location, reading) ) }, output: [ 0 ] }); } return result; } } export default DatasetFetcher;