[server/DatasetFetcher] Don't include distance in unified training mode

This commit is contained in:
Starbeamrainbowlabs 2019-08-06 12:46:07 +01:00
parent 858f53c588
commit 6d21146b05

View file

@ -30,19 +30,18 @@ class DatasetFetcher {
let iterator = gateway_id == null ? this.repo_rssi.iterate() : this.repo_rssi.iterate_gateway(gateway_id); let iterator = gateway_id == null ? this.repo_rssi.iterate() : this.repo_rssi.iterate_gateway(gateway_id);
// Add the readings where we did get a signal // Add the readings where we did get a signal
for(let rssi of iterator) { for(let rssi of iterator) {
if(gateway_id == null)
gateway_location = this.repo_gateway.get_by_id(rssi.gateway_id);
let item = { let item = {
input: { input: {
latitude: rssi.latitude, latitude: rssi.latitude,
longitude: rssi.longitude, longitude: rssi.longitude
distance: haversine(gateway_location, rssi)
}, },
output: [ output: [
rssi.rssi rssi.rssi
] ]
}; };
if(gateway_id !== null)
item.input.distance = haversine(gateway_location, rssi);
if(extended) { if(extended) {
item.ext = { item.ext = {
gateway: rssi.gateway_id, gateway: rssi.gateway_id,
@ -57,11 +56,13 @@ class DatasetFetcher {
let item = { let item = {
input: { input: {
latitude: reading.latitude, latitude: reading.latitude,
longitude: reading.longitude, longitude: reading.longitude
distance: haversine(gateway_location, reading)
}, },
output: [ -150 ] output: [ -150 ]
}; };
if(gateway_id !== null)
item.input.distance = haversine(gateway_location, reading);
if(extended) { if(extended) {
item.ext = { item.ext = {
gateway: "(none)", gateway: "(none)",
@ -89,15 +90,17 @@ class DatasetFetcher {
for(let item of result) { for(let item of result) {
item.input.latitude = normalise_lat(item.input.latitude); item.input.latitude = normalise_lat(item.input.latitude);
item.input.longitude = normalise_lng(item.input.longitude); item.input.longitude = normalise_lng(item.input.longitude);
item.input.distance = normalise_gateway_distance(item.input.distance); if(typeof item.input.distance == "number")
item.input.distance = normalise_gateway_distance(item.input.distance);
item.output[0] = normalise_rssi(item.output[0]); item.output[0] = normalise_rssi(item.output[0]);
} }
// Scan the resulting dataset for invalid items
this.scan_for_corruption(result);
// Shuffle the dataset // Shuffle the dataset
shuffle_fisher_yates(result); shuffle_fisher_yates(result);
// Scan the resulting dataset for invalid items
this.scan_for_corruption(result);
return result; return result;
} }
@ -125,7 +128,7 @@ class DatasetFetcher {
next_item.input, next_item.input,
comp_item.input comp_item.input
); );
if(isNaN(distance)) if(Number.isNaN(distance))
throw new Error(`Error: Got NaN when checking zapping distance.`); throw new Error(`Error: Got NaN when checking zapping distance.`);
if(distance < max_distance_metres) { if(distance < max_distance_metres) {
@ -146,13 +149,9 @@ class DatasetFetcher {
scan_for_corruption(dataset) { scan_for_corruption(dataset) {
// Scan the input data to make sure it is't corrupt // Scan the input data to make sure it is't corrupt
for(let row of dataset) { for(let row of dataset) {
if(isNaN(row.output[0]) || isNaN(row.input.latitude) || isNaN(row.input.longitude) || isNaN(row.input.distance)) { if(Number.isNaN(row.output[0]) || Number.isNaN(row.input.latitude) || Number.isNaN(row.input.longitude) || Number.isNaN(row.input.distance)) {
console.error(row); console.error(row);
throw new Error("Error: Found NaN in input data"); throw new Error("Error: Found invalid value in input data");
}
if(typeof row.output[0] !== "number" || typeof row.input.latitude !== "number" || typeof row.input.longitude !== "number" || typeof row.input.distance !== "number") {
console.error(row);
throw new Error("Error: Found item with an invalid type in the input data");
} }
} }