LoRaWAN-Signal-Mapping/common/Normalisers.mjs

72 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-07-30 17:46:07 +00:00
"use strict";
2019-07-30 14:42:37 +00:00
import { normalise, clamp } from './Math.mjs';
function normalise_lat(lat) {
return normalise(lat,
{ min: -90, max: +90 },
{ min: 0, max: 1 }
);
}
function normalise_lng(lng) {
return normalise(lng,
{ min: -180, max: +180 },
{ min: 0, max: 1 }
);
}
function unnormalise_lat(nlat) {
return normalise(nlat,
{ min: 0, max: 1 },
{ min: -90, max: +90 }
);
}
function unnormalise_lng(nlng) {
return normalise(nlng,
{ min: 0, max: 1 },
{ min: -180, max: +180 }
);
}
function normalise_gateway_distance(distance) {
return clamp(normalise(distance,
{ min: 0, max: 20000 },
{ min: 0, max: 1 }
2019-07-30 17:46:07 +00:00
), 0, 1);
2019-07-30 14:42:37 +00:00
}
function unnormalise_gateway_distance(ndistance) {
2019-07-30 17:46:07 +00:00
return normalise(ndistance,
2019-07-30 14:42:37 +00:00
{ min: 0, max: 1 },
{ min: 0, max: 20000 }
2019-07-30 17:46:07 +00:00
);
2019-07-30 14:42:37 +00:00
}
function normalise_rssi(rssi) {
return clamp(normalise(rssi,
{ min: -150, max: 0 },
{ min: 0, max: 1 }
), 0, 1)
}
function unnormalise_rssi(rssi) {
2019-07-30 17:46:07 +00:00
return normalise(rssi,
2019-07-30 14:42:37 +00:00
{ min: 0, max: 1 },
{ min: -150, max: 0 }
2019-07-30 17:46:07 +00:00
);
2019-07-30 14:42:37 +00:00
}
export {
normalise_lat,
normalise_lng,
unnormalise_lat,
unnormalise_lng,
normalise_gateway_distance,
unnormalise_gateway_distance,
normalise_rssi,
unnormalise_rssi
};