LoRaWAN-Signal-Mapping/server/Models/Reading.mjs

40 lines
1,019 B
JavaScript
Raw Normal View History

2019-05-20 13:48:41 +00:00
"use strict";
import RSSI from './RSSI.mjs';
/**
* A single data reading received over the TTN.
* @param {string} id The id of this reading.
* @param {number} lat The latitude at which this reading was taken.
* @param {number} long The longitude at which this reading was taken.
* @param {RSSI[]} rssis An array of RSSI objects containing the signal strengths, as reported by 1 or mroe gateways.
*/
class Reading {
constructor(id, lat, long, rssis) {
/** @type {string} */
this.id = id;
/** @type {number} */
this.lat = lat;
/** @type {number} */
this.long = long;
/** @type {RSSI[]} */
this.rssis = rssis;
}
/**
* Returns the RSSI reading for the strongest received signal strength.
* @return {RSSI|null} The RSSI object that contains the strongest received signal strength.
*/
get best_rssi() {
if(this.rssis.length == 0)
return null;
return this.rssis.reduce(
(prev, next) => prev.rssi > next.rssi ? prev : next,
this.rssis[0]
);
}
}
export default Reading;