mirror of
https://github.com/ConnectedHumber/Air-Quality-Web
synced 2024-11-23 06:33:00 +00:00
Starbeamrainbowlabs
3fe326b02d
Goodbye, old friend :-( That heatmap thingy took several revisions and lots fo hard work, but it just didn't work out :-( :-( :'(
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
"use strict";
|
|
|
|
import Config from './Config.mjs';
|
|
|
|
import GetFromUrl from './Helpers/GetFromUrl.mjs';
|
|
|
|
class ReadingsData {
|
|
constructor() {
|
|
|
|
}
|
|
|
|
/**
|
|
* Fetches the data from all currently active devices at a given datetime
|
|
* and for a given reading type.
|
|
* @param {string} reading_type The reading type to fetch data for.
|
|
* @param {String|Date} [datetime="now"] The datetime to fetch the data for.
|
|
* @return {Promise<Map>} A promise that resolves to a Map keyed by device IDs that contains the data objects returned by the fetch-data API action.
|
|
*/
|
|
async fetch(reading_type, datetime = "now") {
|
|
if(datetime instanceof Date)
|
|
datetime = datetime.toISOString();
|
|
// TODO: memoize this
|
|
let data = await this.__make_request(reading_type, datetime);
|
|
let result = new Map();
|
|
for(let item of data)
|
|
result.set(item.device_id, item);
|
|
|
|
return result;
|
|
}
|
|
|
|
async __make_request(reading_type, datetime) {
|
|
return JSON.parse(await GetFromUrl(
|
|
`${Config.api_root}?action=fetch-data&datetime=${encodeURIComponent(datetime)}&reading_type=${encodeURIComponent(reading_type)}`
|
|
));
|
|
}
|
|
}
|
|
|
|
export default ReadingsData;
|