From ea2bc8b96b28b5a989350308f45727681aa77a23 Mon Sep 17 00:00:00 2001 From: Kelvin Ly Date: Tue, 16 May 2023 12:21:49 -0400 Subject: [PATCH] Implement customizable decimation rate, window size, and update rate --- dev/dev.htm | 94 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 84 insertions(+), 10 deletions(-) diff --git a/dev/dev.htm b/dev/dev.htm index 4d916e5..eb767e2 100644 --- a/dev/dev.htm +++ b/dev/dev.htm @@ -143,17 +143,22 @@ async function updateCharts() { volts = volts.slice(slice_idx) time = time.slice(slice_idx) + const temp_d = temp.filter((_, idx) => (idx % decimation_rate) == 0) + const humd_d = humd.filter((_, idx) => (idx % decimation_rate) == 0) + const volts_d = volts.filter((_, idx) => (idx % decimation_rate) == 0) + const time_d = time.filter((_, idx) => (idx % decimation_rate) == 0) + chart.load({ columns: [ - ["time"].concat(time), - ["temp"].concat(temp), - ["humidity"].concat(humd), + ["time"].concat(time_d), + ["temp"].concat(temp_d), + ["humidity"].concat(humd_d), ] }) chart2.load({ columns: [ - ["time"].concat(time), - ["voltage"].concat(volts), + ["time"].concat(time_d), + ["voltage"].concat(volts_d), ] }) status("charts updated") @@ -206,7 +211,10 @@ async function testAdminMode() { const msg = JSON.stringify({ auth: "password", data: { - manual_mode: true + set_params: { + name: "target_lower", + value: 0.87 + } } }) await fetch("/api/admin", { @@ -227,23 +235,89 @@ window.onload = () => { document.getElementById('autoupdate').addEventListener('click', (e) => { autoupdate = document.getElementById('autoupdate').checked }) + document.getElementsByName('decim').forEach((elem) => { + elem.addEventListener('click', (e) => { + if (elem.checked) { + decimation_rate = parseInt(elem.value) + } + }) + }) + document.getElementsByName('update').forEach((elem) => { + elem.addEventListener('click', (e) => { + if (elem.checked) { + chart_update_millis = parseInt(elem.value) + } + }) + }) + + document.getElementsByName('duration').forEach((elem) => { + elem.addEventListener('click', (e) => { + const old_millis = max_interval_millis + if (elem.checked) { + max_interval_millis = parseInt(elem.value)*1000*60 + if (max_interval_millis != old_millis) { + // reset the chart data to force a reload on the next update + cur_time_millis = 0 + time = [] + temp = [] + humd = [] + volts = [] + } + } + }) + }) + + /* document.getElementById('test-admin').addEventListener('click', (e) => { testAdminMode() }) + */ } -
+
+ Autoupdate + + + +
+
- Autoupdate - +
+ Data decimation rate + 1x + 2x + 4x + 10x + 20x +
+
+ History length + 5 minutes + 15 minutes + 1 hour + 1 day + 1 week +
+
+ Update rate + 0.1 second + 1 second + 2 seconds + 5 seconds + 10 seconds + 20 seconds +
+ + + -