2019-05-29 10:35:10 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
class RSSIRepo {
|
2019-07-09 13:05:42 +00:00
|
|
|
constructor({ database }) {
|
|
|
|
this.db = database;
|
2019-05-29 10:35:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
add(...rssis) {
|
2019-07-10 13:32:58 +00:00
|
|
|
const statement = this.db.prepare(`INSERT INTO rssis (
|
|
|
|
id,
|
|
|
|
reading_id, gateway_id,
|
|
|
|
rssi, snr,
|
|
|
|
channel
|
|
|
|
) VALUES (
|
|
|
|
:id,
|
|
|
|
:reading_id, :gateway_id,
|
|
|
|
:rssi, :snr,
|
|
|
|
:channel
|
|
|
|
)`);
|
2019-07-10 13:44:52 +00:00
|
|
|
for(let rssi of rssis) {
|
|
|
|
// console.log(`Storing`, rssi);
|
2019-07-10 13:32:58 +00:00
|
|
|
statement.run(rssi);
|
2019-07-10 13:44:52 +00:00
|
|
|
}
|
2019-05-29 10:35:10 +00:00
|
|
|
}
|
|
|
|
|
2019-07-17 14:15:31 +00:00
|
|
|
iterate_gateway(gateway_id) {
|
|
|
|
return this.db.prepare(`SELECT
|
|
|
|
rssis.*,
|
|
|
|
readings.latitude,
|
|
|
|
readings.longitude
|
|
|
|
FROM rssis
|
2019-07-18 16:22:37 +00:00
|
|
|
JOIN readings ON rssis.reading_id = readings.id
|
2019-07-17 14:15:31 +00:00
|
|
|
WHERE gateway_id = :gateway_id`).iterate({
|
|
|
|
gateway_id
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-05-29 10:35:10 +00:00
|
|
|
iterate() {
|
2019-08-02 13:00:31 +00:00
|
|
|
return this.db.prepare(`SELECT
|
|
|
|
rssis.*,
|
|
|
|
readings.latitude,
|
|
|
|
readings.longitude
|
|
|
|
FROM rssis
|
|
|
|
JOIN readings ON rssis.reading_id = readings.id`).iterate();
|
2019-05-29 10:35:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-29 10:36:36 +00:00
|
|
|
export default RSSIRepo;
|