From 890d02a6165177a79711a84b3e6c9555286ee3b0 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Wed, 2 Mar 2022 22:24:18 +0000 Subject: [PATCH] Add seeds, fix last value bug --- client/src/App.js | 77 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/client/src/App.js b/client/src/App.js index 160120e..5b0861b 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -89,7 +89,20 @@ function ChartContainer({name, data, lastFormatter, loading, children, topMargin ); } - const last = data.length ? lastFormatter(data.slice(-1)[0]) : null; + if (data.length === 0) { + return false; + } + + const dataGood = (x) => !['undefined', 'null'].some(y => lastFormatter(x).includes(y)); + let last = null; + if (data.length) { + const data_end = data.slice(-2); + if (dataGood(data_end[1])) { + last = lastFormatter(data_end[1]); + } else if (dataGood(data_end[0])) { + last = lastFormatter(data_end[0]); + } + } return (
@@ -280,6 +293,67 @@ function BedroomTemperature({end, duration}) { ); } +function SeedsTemperature({end, duration}) { + const [data, loading, tickFormatter] = useSensor('temperature', 'Seeds', end, duration); + + return ( + x.temperature_C?.toFixed(1) + ' °C'} + loading={loading} + > + + + + + + + v.toFixed(1) + ' °C'} + labelFormatter={timeStr => moment(timeStr).tz('America/Edmonton').format('ddd MMM DD h:mm A')} + separator=': ' + /> + + + + + + + + ); +} + function Thermostat({end, duration}) { const [data, loading, tickFormatter] = useSensor('thermostat', 'Venstar', end, duration); @@ -534,6 +608,7 @@ function Graphs({end, duration}) { +