2019-07-17 14:15:31 +00:00
|
|
|
"use strict";
|
|
|
|
|
2019-07-29 13:17:28 +00:00
|
|
|
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';
|
2019-07-17 14:15:31 +00:00
|
|
|
|
|
|
|
class DatasetFetcher {
|
2019-07-29 13:17:28 +00:00
|
|
|
constructor({ settings, GatewayRepo, RSSIRepo, ReadingRepo }) {
|
2019-07-17 14:15:31 +00:00
|
|
|
this.settings = settings;
|
2019-07-29 13:17:28 +00:00
|
|
|
this.repo_gateway = GatewayRepo;
|
2019-07-17 14:15:31 +00:00
|
|
|
this.repo_rssi = RSSIRepo;
|
2019-07-29 13:17:28 +00:00
|
|
|
this.repo_reading = ReadingRepo;
|
2019-07-17 14:15:31 +00:00
|
|
|
}
|
|
|
|
|
2019-07-29 13:17:28 +00:00
|
|
|
fetch_all(gateway_id) {
|
|
|
|
let gateway_location = this.repo_gateway.get_by_id(gateway_id);
|
|
|
|
|
2019-07-29 16:02:34 +00:00
|
|
|
let result = [];
|
2019-07-18 15:34:25 +00:00
|
|
|
for(let rssi of this.repo_rssi.iterate_gateway(gateway_id)) {
|
2019-07-29 16:02:34 +00:00
|
|
|
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)
|
|
|
|
]
|
2019-07-29 16:02:34 +00:00
|
|
|
});
|
2019-07-18 15:34:25 +00:00
|
|
|
}
|
2019-07-29 13:17:28 +00:00
|
|
|
|
|
|
|
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
|
|
|
});
|
2019-07-29 13:17:28 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2019-07-17 14:15:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default DatasetFetcher;
|