Create the rest of the repositories, but it isn't tested yet.

This commit is contained in:
Starbeamrainbowlabs 2019-05-29 11:35:10 +01:00
parent c36f3a4df9
commit 26c82ac7e6
6 changed files with 87 additions and 76 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -2,14 +2,16 @@
import { get_instance } from '../Helpers/Database.mjs';
import Reading from '../Models/Reading.mjs';
class ReadingRepo {
constructor(in_RSSIRepo) {
this.db = get_instance();
this.RSSIRepo = in_RSSIRepo;
this.insert_query = this.db.prepare(`INSERT INTO readings (
}
add(reading) {
if(typeof this.query_insert == "undefined")
this.query_insert = this.db.prepare(`INSERT INTO readings (
id,
lat, long,
data_rate_id, code_rate, bit_rate
@ -19,10 +21,14 @@ class ReadingRepo {
:long,
:data_rate_id, :code_rate, :bit_rate
)`);
this.insert_query.run(reading);
this.RSSIRepo.add(...reading.rssis);
}
add(reading) {
this.insert_query
iterate() {
return this.db.prepare(`SELECT * FROM readings`).iterate();
}
}

View File

@ -3,7 +3,7 @@ CREATE TABLE readings IF NOT EXISTS (
id INTEGER PRIMARY KEY, -- Random unique integer
lat FLOAT NOT NULL, -- Latitude component of GPS co-ordinates of reading
long FLOAT NOT NULL, -- Longitude component of GPS co-ordinates of reading,
data_rate_id INTEGER, -- The id of the data rate code in the data_rates table that describes the data rate at which the message was transmitted
data_rate TEXT NOT NULL, -- The id of the data rate code in the data_rates table that describes the data rate at which the message was transmitted
code_rate TEXT, -- The coding rate at which the message was transmitted. FUTURE: This may need to be an INTEGER field - not sure
bit_rate INTEGER, -- The bit rate at which the message was transmitted
);
@ -18,13 +18,9 @@ CREATE TABLE rssis IF NOT EXISTS (
CREATE TABLE gateways IF NOT EXISTS (
id TEXT PRIMARY KEY, -- The gateway's name
lat FLOAT, -- Latitude component of the claimed GPS co-ordinates of the gateway
long FLOAT -- Longitude component of the claimed GPS co-ordinates of the gateway
long FLOAT, -- Longitude component of the claimed GPS co-ordinates of the gateway
altitude FLOAT -- Claimed alitude of the gateway
);
CREATE TABLE data_rates IF NOT EXISTS (
id INTEGER PRIMARY KEY, -- Random unique integer,
codename TEXT NOT NULL,
);
-- UPDATE 1 --