parent
c36f3a4df9
commit
26c82ac7e6
@ -1,17 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* The received signal strength of a message from a single gateway.
|
||||
* @param {number} 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;
|
@ -1,40 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
import RSSIRepo from '../Repos.SQLite/RSSIRepo.mjs';
|
||||
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;
|
@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
|
||||
import { get_instance } from '../Helpers/Database.mjs';
|
||||
|
||||
|
||||
class GatewayRepo {
|
||||
constructor() {
|
||||
this.db = get_instance();
|
||||
}
|
||||
|
||||
add(...gateways) {
|
||||
if(typeof this.query_insert == "undefined")
|
||||
this.query_insert = this.db.prepare(`INSERT INTO gateways (
|
||||
id,
|
||||
lat, long,
|
||||
altitude
|
||||
) VALUES (
|
||||
:id,
|
||||
:lat, :long,
|
||||
:altitude
|
||||
)`);
|
||||
|
||||
for(let gateway of gateways)
|
||||
this.insert_query.run(gateway);
|
||||
}
|
||||
|
||||
iterate() {
|
||||
return this.db.prepare(`SELECT * FROM gateways`).iterate();
|
||||
}
|
||||
}
|
||||
|
||||
export default ReadingRepo;
|
@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
|
||||
import { get_instance } from '../Helpers/Database.mjs';
|
||||
|
||||
|
||||
class RSSIRepo {
|
||||
constructor() {
|
||||
this.db = get_instance();
|
||||
}
|
||||
|
||||
add(...rssis) {
|
||||
if(typeof this.query_insert == "undefined")
|
||||
this.query_insert = this.db.prepare(`INSERT INTO rssis (
|
||||
id,
|
||||
reading_id,
|
||||
rssi, snr,
|
||||
channel
|
||||
) VALUES (
|
||||
:id,
|
||||
:reading_id,
|
||||
:rssi, :snr,
|
||||
:channel
|
||||
)`);
|
||||
|
||||
for(let rssi of rssis)
|
||||
this.insert_query.run(rssi);
|
||||
}
|
||||
|
||||
iterate() {
|
||||
return this.db.prepare(`SELECT * FROM rssis`).iterate();
|
||||
}
|
||||
}
|
||||
|
||||
export default ReadingRepo;
|
Loading…
Reference in new issue