|
|
|
@ -36,6 +36,11 @@ class GatewayRepo { |
|
|
|
|
return count > 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns a garteway by it's id. |
|
|
|
|
* @param {string} id The id to fetcht he gateway for. |
|
|
|
|
* @return {object} The information recorded about the gateway with the specified id . |
|
|
|
|
*/ |
|
|
|
|
get_by_id(id) { |
|
|
|
|
return this.db.prepare(`SELECT * FROM gateways WHERE id = :id`).get({ id }); |
|
|
|
|
} |
|
|
|
@ -48,6 +53,24 @@ class GatewayRepo { |
|
|
|
|
iterate() { |
|
|
|
|
return this.db.prepare(`SELECT * FROM gateways`).iterate(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the average location of allt he currently registered gateways. |
|
|
|
|
* @return {{latitude: number, longitude: number}} The lat longg coordinates of the average location of all the gateways. |
|
|
|
|
*/ |
|
|
|
|
get_average_location() { |
|
|
|
|
let count = 0, lat_sum = 0, lng_sum = 0; |
|
|
|
|
for(let gateway of this.iterate()) { |
|
|
|
|
lat_sum += gateway.latitude; |
|
|
|
|
lng_sum += gateway.longitude; |
|
|
|
|
count++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
latitude: lat_sum / count, |
|
|
|
|
longitude: lng_sum / count |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export default GatewayRepo; |
|
|
|
|