Create initial model classes
This commit is contained in:
parent
fcceb7de46
commit
0a05e00c11
2 changed files with 56 additions and 0 deletions
17
server/Models/RSSI.mjs
Normal file
17
server/Models/RSSI.mjs
Normal file
|
@ -0,0 +1,17 @@
|
|||
"use strict";
|
||||
|
||||
/**
|
||||
* The received signal strength of a message from a single gateway.
|
||||
* @param {string} id The id of this rssi measurement.
|
||||
* @param {number} gateway_id The id of this gateway.
|
||||
* @param {number} rssi The rssi measurement.
|
||||
*/
|
||||
class RSSI {
|
||||
constructor(id, gateway_id, rssi) {
|
||||
this.id = id;
|
||||
this.gateway_id = gateway_id;
|
||||
this.rssi = rssi;
|
||||
}
|
||||
}
|
||||
|
||||
export default RSSI;
|
39
server/Models/Reading.mjs
Normal file
39
server/Models/Reading.mjs
Normal file
|
@ -0,0 +1,39 @@
|
|||
"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;
|
Loading…
Reference in a new issue