Round dates when making heatmap api requests

This commit is contained in:
Starbeamrainbowlabs 2019-07-31 19:31:05 +01:00
parent 2a65f223c1
commit 5ef5cec040
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
4 changed files with 27 additions and 2 deletions

View file

@ -1,13 +1,15 @@
The data displayed has been produced by low-cost devices developed by [Connected Humber](https://www.connectedhumber.org/) members as part of a community driven effort to build a network of smart sensors in the Humber Region.
# Changelog
This is the changelog for the air quality web interface and its associated HTTP API.
- `[API]` refers to changes to the [HTTP API](https://aq.connectedhumber.org/__nightdocs/05-API-Docs.html).
- `[Code]` refers to internal changes to the code that have no direct impact on the web interface or the HTTP API, but are significant enough to warrant note.
- `[Docs]` refers to changes to the [documentation](https://aq.connectedhumber.org/__nightdocs/00-Welcome.html).
## v0.13
- Round dates before making API requests to improve caching potential
## v0.12
- Added loading animation while the map is loading
- Added device sensor information to the device info tab in the popup

View file

@ -10,6 +10,10 @@ export default {
// The default zoom level to use when loading the page.
default_zoom: 12,
// The number of minutes to round dates to when making time-based HTTP API requests.
// Very useful for improving cache hit rates.
date_rounding_interval: 6,
heatmap: {
// The radius fo blobs on the heatmap
blob_radius: 0.02

View file

@ -46,7 +46,23 @@ function human_time(seconds)
}
}
/**
* Rounds a Date to match the specified number of minutes.
* Useful when making API requests to improve caching.
* @param {Date} date The date to round.
* @param {int} interval_minutes The number of minutes to round it to. Should be less than 60.
* @return {void} Doesn't return anything - it mutates the original Date object instead.
*/
function round_date_interval(date, interval_minutes) {
date.setSeconds(0);
date.setMilliseconds(0);
date.setMinutes(
Math.floor(date.getMinutes() / interval_minutes) * interval_minutes
);
}
export {
human_duration_unit,
human_time_since, human_time
human_time_since, human_time,
round_date_interval
};

View file

@ -12,6 +12,7 @@ import Specs from './OverlaySpecs.mjs';
import Vector2 from '../Helpers/Vector2.mjs';
import GetFromUrl from '../Helpers/GetFromUrl.mjs';
import { round_date_interval } from '../Helpers/DateHelper.mjs';
class VoronoiManager {
@ -52,6 +53,8 @@ class VoronoiManager {
this.last_datetime = datetime;
this.last_reading_type = reading_type;
round_date_interval(this.last_datetime, Config.date_rounding_interval);
this.spec = Specs[reading_type] || Specs["unknown"];
if(typeof this.spec.chroma == "undefined")
this.spec.chroma = chroma.scale(Object.values(this.spec.gradient))