From 6b5ad244e5d77466b167131993e9a48b0b364052 Mon Sep 17 00:00:00 2001 From: Steven Huss-Lederman Date: Fri, 26 Feb 2021 09:45:17 -0600 Subject: [PATCH 1/5] fix timezone being null By default, timezone is null. This caused the meter page not to be able to save changes if the timezone was not set. The new validation allows for null. Did same to pereferences but it did not fail before the change for reasons I do not understand. --- src/server/routes/meters.js | 13 +++++++++---- src/server/routes/preferences.js | 7 +++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/server/routes/meters.js b/src/server/routes/meters.js index 78e6cfcc6..d22153cc0 100644 --- a/src/server/routes/meters.js +++ b/src/server/routes/meters.js @@ -109,7 +109,12 @@ router.post('/edit', async (req, res) => { id: { type: 'integer' }, enabled: { type: 'bool' }, displayable: { type: 'bool' }, - timeZone: { type: 'string' }, + timeZone: { + oneOf: [ + { type: 'string' }, + { type: 'null' } + ] + }, gps: { oneOf: [ { @@ -117,10 +122,10 @@ router.post('/edit', async (req, res) => { required: ['latitude', 'longitude'], properties: { latitude: { type: 'number', minimum: '-90', maximum: '90' }, - longitude: { type: 'number', minimum: '-180', maximum: '180'} + longitude: { type: 'number', minimum: '-180', maximum: '180' } } }, - {type: 'null'} + { type: 'null' } ] } } @@ -137,7 +142,7 @@ router.post('/edit', async (req, res) => { meter.enabled = req.body.enabled; meter.displayable = req.body.displayable; meter.meterTimezone = req.body.timeZone; - meter.gps = (req.body.gps)? new Point(req.body.gps.longitude, req.body.gps.latitude): null; + meter.gps = (req.body.gps) ? new Point(req.body.gps.longitude, req.body.gps.latitude) : null; await meter.update(conn); } catch (err) { log.error('Failed to edit meter', err); diff --git a/src/server/routes/preferences.js b/src/server/routes/preferences.js index 25fdbefc6..e1b402a58 100644 --- a/src/server/routes/preferences.js +++ b/src/server/routes/preferences.js @@ -50,8 +50,11 @@ router.post('/', async (req, res) => { type: 'string' }, defaultTimezone: { - type: 'string' - } + oneOf: [ + { type: 'string' }, + { type: 'null' } + ] + }, } } }; From b408c952395b804a8514c97af2ab3cc797fb2faa Mon Sep 17 00:00:00 2001 From: Steven Huss-Lederman Date: Fri, 26 Feb 2021 11:26:09 -0600 Subject: [PATCH 2/5] fixes units displayed on graphics While the OED upgrade on resource types will fix this in a more general way, this corrects the units. Line graphics are kW and all the others are kWh since they are over time. --- src/client/app/containers/BarChartContainer.ts | 6 +++--- src/client/app/containers/CompareChartContainer.ts | 8 ++++---- src/client/app/containers/MapChartContainer.ts | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/client/app/containers/BarChartContainer.ts b/src/client/app/containers/BarChartContainer.ts index 19547f06f..0cc518d5d 100644 --- a/src/client/app/containers/BarChartContainer.ts +++ b/src/client/app/containers/BarChartContainer.ts @@ -35,7 +35,7 @@ function mapStateToProps(state: State) { `${moment(barReading.startTimestamp).utc().format('MMM DD, YYYY')} - ${moment(barReading.endTimestamp).utc().format('MMM DD, YYYY')}`; xData.push(timeReading); yData.push(barReading.reading); - hoverText.push(` ${timeReading}
${label}: ${barReading.reading} kW`); + hoverText.push(` ${timeReading}
${label}: ${barReading.reading} kWh`); }); // This variable contains all the elements (x and y values, bar type, etc.) assigned to the data parameter of the Plotly object @@ -72,7 +72,7 @@ function mapStateToProps(state: State) { `${moment(barReading.startTimestamp).utc().format('MMM DD, YYYY')} - ${moment(barReading.endTimestamp).utc().format('MMM DD, YYYY')}`; xData.push(timeReading); yData.push(barReading.reading); - hoverText.push(` ${timeReading}
${label}: ${barReading.reading} kW`); + hoverText.push(` ${timeReading}
${label}: ${barReading.reading} kWh`); }); // This variable contains all the elements (x and y values, bar chart, etc.) assigned to the data parameter of the Plotly object @@ -103,7 +103,7 @@ function mapStateToProps(state: State) { orientation: 'h' }, yaxis: { - title: 'kW', + title: 'kWh', showgrid: true, gridcolor: '#ddd' }, diff --git a/src/client/app/containers/CompareChartContainer.ts b/src/client/app/containers/CompareChartContainer.ts index b8bf8e5c7..4bdda0a9e 100644 --- a/src/client/app/containers/CompareChartContainer.ts +++ b/src/client/app/containers/CompareChartContainer.ts @@ -43,13 +43,13 @@ function mapStateToProps(state: State, ownProps: CompareChartContainerProps): IP x: [periodLabels.prev, periodLabels.current], y: [previousPeriod, currentPeriod], hovertext: [ - `${previousPeriod} KW ${translate('used.this.time')}
${periodLabels.prev.toLowerCase()}`, - `${currentPeriod} KW ${translate('used.so.far')}
${periodLabels.current.toLowerCase()}` + `${previousPeriod} KWh ${translate('used.this.time')}
${periodLabels.prev.toLowerCase()}`, + `${currentPeriod} KWh ${translate('used.so.far')}
${periodLabels.current.toLowerCase()}` ], hoverinfo: 'text', type: 'bar', marker: {color: barColor}, - text: [ `${previousPeriod} kW`, `${currentPeriod} kW`], + text: [ `${previousPeriod} kWh`, `${currentPeriod} kWh`], textposition: 'auto', textfont: { color: 'rgba(0,0,0,1)' @@ -71,7 +71,7 @@ function mapStateToProps(state: State, ownProps: CompareChartContainerProps): IP legend: { }, yaxis: { - title: 'kW', + title: 'kWh', showgrid: true, gridcolor: '#ddd' }, diff --git a/src/client/app/containers/MapChartContainer.ts b/src/client/app/containers/MapChartContainer.ts index c681c63bd..84650b5ae 100644 --- a/src/client/app/containers/MapChartContainer.ts +++ b/src/client/app/containers/MapChartContainer.ts @@ -63,7 +63,7 @@ function mapStateToProps(state: State) { `${moment(mapReading.startTimestamp).utc().format('MMM DD, YYYY')} - ${moment(mapReading.endTimestamp).utc().format('MMM DD, YYYY')}`; const averagedReading = mapReading.reading / barDuration.asDays(); // average total reading by days of duration size.push(averagedReading); - texts.push(` ${timeReading}
${label}: ${averagedReading} kW/day`); + texts.push(` ${timeReading}
${label}: ${averagedReading} kWh/day`); } } } From 873a4410ab790b9d885be73992549e7d3a0f82d2 Mon Sep 17 00:00:00 2001 From: Steven Huss-Lederman Date: Fri, 26 Feb 2021 11:39:41 -0600 Subject: [PATCH 3/5] SQL migrations - Creates migration for new identifier and make sure set value. - Add new migration from 0.5.0 to 0.6.0 for release --- .../0.5.0-0.6.0/sql/meter/add_idenifier_column.sql | 8 ++++++++ src/server/migrations/registerMigration.js | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/server/migrations/0.5.0-0.6.0/sql/meter/add_idenifier_column.sql diff --git a/src/server/migrations/0.5.0-0.6.0/sql/meter/add_idenifier_column.sql b/src/server/migrations/0.5.0-0.6.0/sql/meter/add_idenifier_column.sql new file mode 100644 index 000000000..38c9aba6b --- /dev/null +++ b/src/server/migrations/0.5.0-0.6.0/sql/meter/add_idenifier_column.sql @@ -0,0 +1,8 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +ALTER TABLE meters + ADD COLUMN IF NOT EXISTS identifier TEXT; + +UPDATE meters SET identifier=name WHERE identifier IS NULL or identifier=''; diff --git a/src/server/migrations/registerMigration.js b/src/server/migrations/registerMigration.js index ac53fad96..150867fa9 100644 --- a/src/server/migrations/registerMigration.js +++ b/src/server/migrations/registerMigration.js @@ -8,7 +8,8 @@ const migrations = [ /* eslint-disable global-require */ //require('./0.2.0-0.3.0-Template/indexTemplate'), - require('./0.3.0-0.5.0') + require('./0.3.0-0.5.0'), + require('./0.5.0-0.6.0') /* eslint-disable global-require */ ]; From 0ebac7ad4cce605de473548a6551f9f8a1df6f52 Mon Sep 17 00:00:00 2001 From: Steven Huss-Lederman Date: Fri, 26 Feb 2021 11:41:05 -0600 Subject: [PATCH 4/5] Update OED version to 0.6.0 I guess this means we are upgrading to 0.6.0. Celebrate! --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3e2687856..4daac4237 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Open-Energy-Dashboard", - "version": "0.5.0", + "version": "0.6.0", "private": false, "license": "MPL-2.0", "repository": "https://github.com/OpenEnergyDashboard/OED", From 75e865b4dcc27579d8829310192b7410dd46013e Mon Sep 17 00:00:00 2001 From: Steven Huss-Lederman Date: Fri, 26 Feb 2021 11:48:38 -0600 Subject: [PATCH 5/5] fix lint issue --- src/server/routes/preferences.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/routes/preferences.js b/src/server/routes/preferences.js index e1b402a58..30f3db98c 100644 --- a/src/server/routes/preferences.js +++ b/src/server/routes/preferences.js @@ -54,7 +54,7 @@ router.post('/', async (req, res) => { { type: 'string' }, { type: 'null' } ] - }, + } } } };