From 2062ced2078f046d015ca6a2f10bc10127d985b8 Mon Sep 17 00:00:00 2001 From: LeeGordon83 Date: Wed, 18 Mar 2026 14:41:06 +0000 Subject: [PATCH 1/7] altered rloi to stop duplicate rainfall values being inserted --- lib/constructed-queries.js | 3 +++ lib/models/rloi.js | 6 ++++++ test/unit/constructed-queries.js | 3 +++ 3 files changed, 12 insertions(+) diff --git a/lib/constructed-queries.js b/lib/constructed-queries.js index 317dddf0..855e7b93 100644 --- a/lib/constructed-queries.js +++ b/lib/constructed-queries.js @@ -24,6 +24,9 @@ module.exports = { end_timestamp, parameter, qualifier, units, post_process, subtract, por_max_value, station_type, percentile_5, data_type, period) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17) + ON CONFLICT (station, region, COALESCE(qualifier, ''), start_timestamp, end_timestamp) + WHERE lower(parameter) = 'rainfall' + DO NOTHING RETURNING telemetry_value_parent_id ` return Query.fromString(sql, values) diff --git a/lib/models/rloi.js b/lib/models/rloi.js index c1a3027d..57b7445d 100644 --- a/lib/models/rloi.js +++ b/lib/models/rloi.js @@ -149,6 +149,12 @@ module.exports = { const values = [] // console.log(`Loaded parent: ${station.RLOI_ID} | ${setOfValues.$.parameter} | ${setOfValues.$.qualifier}`) + // Skip if parent was not inserted (duplicate) + if (!res.rows || !res.rows[0]) { + processed++ + return + } + for (let i = 0; i < setOfValues.Value.length; i++) { values[i] = setSlsTelemetryValueItem(i, res, station, setOfValues) } diff --git a/test/unit/constructed-queries.js b/test/unit/constructed-queries.js index 67d45892..2ff03c02 100644 --- a/test/unit/constructed-queries.js +++ b/test/unit/constructed-queries.js @@ -86,6 +86,9 @@ describe('constructedQueries', () => { // Assert expect(actual.text).to.match(/INSERT INTO sls_telemetry_value_parent/) + expect(actual.text).to.match(/ON CONFLICT \(station, region, COALESCE\(qualifier, ''\), start_timestamp, end_timestamp\)/) + expect(actual.text).to.match(/WHERE lower\(parameter\) = 'rainfall'/) + expect(actual.text).to.match(/DO NOTHING/) expect(actual.values).to.equal(values) }) }) From b45ea201dd2267e2cd2ad6d3a9b8e2aef70b937f Mon Sep 17 00:00:00 2001 From: LeeGordon83 Date: Fri, 20 Mar 2026 16:49:18 +0000 Subject: [PATCH 2/7] added more unit test coverage and refactored skip if parent not inserted lines --- lib/models/rloi.js | 2 +- test/data/rloi-test.xml | 5 ++++- test/unit/models/rloi.js | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/models/rloi.js b/lib/models/rloi.js index 57b7445d..441945d6 100644 --- a/lib/models/rloi.js +++ b/lib/models/rloi.js @@ -150,7 +150,7 @@ module.exports = { // console.log(`Loaded parent: ${station.RLOI_ID} | ${setOfValues.$.parameter} | ${setOfValues.$.qualifier}`) // Skip if parent was not inserted (duplicate) - if (!res.rows || !res.rows[0]) { + if (!res.rows?.[0]) { processed++ return } diff --git a/test/data/rloi-test.xml b/test/data/rloi-test.xml index c9175233..172f5c36 100644 --- a/test/data/rloi-test.xml +++ b/test/data/rloi-test.xml @@ -12,7 +12,10 @@ 0.0 - + + + 0.0 + 0.0 diff --git a/test/unit/models/rloi.js b/test/unit/models/rloi.js index d881eb99..0b2dc9f2 100644 --- a/test/unit/models/rloi.js +++ b/test/unit/models/rloi.js @@ -305,6 +305,24 @@ lab.experiment('rloi model', () => { sinon.assert.calledOnceWithExactly(client.query.withArgs(stationSchemaQueryMatcher), 'slsTelemetryStation', expectedStationQuery.values) }) + lab.test('Rainfall duplicate parent should skip telemetry value insert', async () => { + sinon.restore() + mockResponse.Body.transformToString.resolves('') + s3Mock.on(GetObjectCommand).resolves(mockResponse) + + const client = getStubbedDbHelper() + client.query + .withArgs(valueParentSchemaQueryMatcher, valueParentSchemaVarsMatcher) + .resolves({ rows: [] }) + + const file = await parseStringPromise(fs.readFileSync('./test/data/rloi-test-rainfall.xml')) + await rloi.save(file, 's3://devlfw', 'testkey', client, s3) + + sinon.assert.callCount(client.query.withArgs(stationSchemaQueryMatcher, stationSchemaVarsMatcher), 1) + sinon.assert.callCount(client.query.withArgs(valueParentSchemaQueryMatcher, valueParentSchemaVarsMatcher), 1) + sinon.assert.callCount(client.query.withArgs(valuesSchemaQueryMatcher), 0) + }) + lab.test('Rainfall station and value is stored in DB and station name with postfix in middle of name', async () => { sinon.restore() mockResponse.Body.transformToString.resolves('') From a082324114e44bb1b9f8c53f0add8f092bded454 Mon Sep 17 00:00:00 2001 From: LeeGordon83 Date: Fri, 20 Mar 2026 16:55:59 +0000 Subject: [PATCH 3/7] reset rloi test data --- test/data/rloi-test.xml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/data/rloi-test.xml b/test/data/rloi-test.xml index 172f5c36..c9175233 100644 --- a/test/data/rloi-test.xml +++ b/test/data/rloi-test.xml @@ -12,10 +12,7 @@ 0.0 - - - 0.0 - + 0.0 From c3674d28a3ce57089e5d4acc4477b5de36018fd0 Mon Sep 17 00:00:00 2001 From: LeeGordon83 Date: Mon, 23 Mar 2026 16:57:11 +0000 Subject: [PATCH 4/7] refactored rloi.json to reduce complexity and pass sonar, added instructions to readme to setup local rloi debug, added test script, data, and debug setup --- .gitignore | 1 + .vscode/launch.json | 120 ----------------- lib/models/rloi.js | 145 ++++++++++++--------- readme.md | 59 +++++++++ test/data/rloi-test-rainfall-duplicate.xml | 15 +++ test/debug-rloi-local.js | 63 +++++++++ test/test-duplicate-detection.sh | 40 ++++++ 7 files changed, 259 insertions(+), 184 deletions(-) delete mode 100644 .vscode/launch.json create mode 100644 test/data/rloi-test-rainfall-duplicate.xml create mode 100644 test/debug-rloi-local.js create mode 100755 test/test-duplicate-detection.sh diff --git a/.gitignore b/.gitignore index 7f01a689..2799c3a3 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ coverage/lcov.info config/config.js +.vscode/ diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index a381ecb2..00000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,120 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - - { - "type": "node", - "request": "launch", - "name": "run ffoiProcess function", - "program": "${workspaceFolder}/node_modules/.bin/sls", - "args": [ - "invoke", - "local", - "-f", - "ffoiProcess", - "--path", - "./test/events/ffoi-event.json" - ] - }, - { - "type": "node", - "request": "launch", - "name": "run rloiProcess function", - "program": "${workspaceFolder}/node_modules/.bin/sls", - "args": [ - "invoke", - "local", - "-f", - "rloiProcess", - "--path", - "./test/events/rloi-event.json" - ] - }, - { - "type": "node", - "request": "launch", - "name": "run stationProcess function", - "program": "${workspaceFolder}/node_modules/.bin/sls", - "args": [ - "invoke", - "local", - "-f", - "stationProcess", - "--path", - "./test/events/station-event.json" - ] - }, { - "type": "node", - "request": "launch", - "name": "debug unit tests", - "program": "${workspaceFolder}/node_modules/.bin/lab", - "args": [ - "test/unit" - ] - }, { - "type": "node", - "request": "launch", - "name": "debug integration tests", - "program": "${workspaceFolder}/node_modules/.bin/lab", - "args": [ - "test/integration" - ] - },{ - "type": "node", - "request": "launch", - "name": "run fwisProcess function", - "program": "${workspaceFolder}/node_modules/.bin/sls", - "args": [ - "invoke", - "local", - "-f", - "fwisProcess", - "--path", - "./test/events/fwis-event.json" - ] - }, { - "type": "node", - "request": "launch", - "name": "run rloiRefresh function", - "program": "${workspaceFolder}/node_modules/.bin/sls", - "args": [ - "invoke", - "local", - "-f", - "rloiRefresh", - "--path", - "./test/events/fwis-event.json" - ] - }, { - "type": "node", - "request": "launch", - "name": "run fgsProcess function", - "program": "${workspaceFolder}/node_modules/.bin/sls", - "args": [ - "invoke", - "local", - "-f", - "fgsProcess", - "--path", - "./test/events/fwis-event.json" - ] - }, { - "type": "node", - "request": "launch", - "name": "run imtdProcess function", - "program": "${workspaceFolder}/node_modules/.bin/sls", - "args": [ - "invoke", - "local", - "-f", - "imtdProcess", - "--path", - "./test/events/imtd-event.json", - "-- --inspect-brk" - ] - } - ] -} diff --git a/lib/models/rloi.js b/lib/models/rloi.js index 441945d6..d5d4edbb 100644 --- a/lib/models/rloi.js +++ b/lib/models/rloi.js @@ -90,6 +90,74 @@ function setSlsTelemetryParent (key, station, item, setOfValues) { ] } +function normaliseStationRegion (item) { + // Keep region consistent with station data due to known telemetry source differences. + item.$.telemetryRegion = item.$.region + item.$.region = regions[item.$.region] ? regions[item.$.region] : item.$.region +} + +async function getStationOrNull (s3, bucket, item) { + try { + const result = await fetchStation(s3, bucket, `rloi/${item.$.region}/${item.$.stationReference}/station.json`) + const bodyContents = await result.Body.transformToString() + return JSON.parse(bodyContents) + } catch (err) { + // Intentionally quiet: missing station files are expected for many telemetry objects. + return null + } +} + +function shouldProcessValues (setOfValues, station) { + return parameters.includes(setOfValues.$.parameter) || (station && setOfValues.$.parameter === 'Water Level') +} + +async function ensureStation (client, item, station) { + if (station) { + return station + } + + const defaultStation = { + RLOI_ID: -1, + Region: item.$.region, + Post_Process: 'n', + Station_Type: 'R' + } + + const telemetryStation = setSlsTelemetryStation(item) + await client.query('slsTelemetryStation', telemetryStation) + + return defaultStation +} + +function logDuplicateParentSkipped (station, setOfValues) { + console.log(`Duplicate telemetry parent skipped: station=${station.RLOI_ID} parameter=${setOfValues.$.parameter} qualifier=${setOfValues.$.qualifier || ''} start=${setOfValues.$.startDate}T${setOfValues.$.startTime} end=${setOfValues.$.endDate}T${setOfValues.$.endTime}`) +} + +function setSlsTelemetryValues (res, station, setOfValues) { + return setOfValues.Value.map((_, index) => setSlsTelemetryValueItem(index, res, station, setOfValues)) +} + +async function processSetOfValues ({ client, s3, bucket, key, item, setOfValues }) { + let station = await getStationOrNull(s3, bucket, item) + + if (!shouldProcessValues(setOfValues, station)) { + return + } + + station = await ensureStation(client, item, station) + + const parent = setSlsTelemetryParent(key, station, item, setOfValues) + const res = await client.query('slsTelemetryValueParent', parent) + + if (!res.rows?.[0]) { + logDuplicateParentSkipped(station, setOfValues) + return + } + + const values = setSlsTelemetryValues(res, station, setOfValues) + await client.query('slsTelemetryValues', values) +} + module.exports = { async save (value, bucket, key, client, s3) { let processed = 0 @@ -104,70 +172,19 @@ module.exports = { } for (const item of value.EATimeSeriesDataExchangeFormat.Station) { - if (item.SetofValues) { - // Update region to match station region as telemetry file region slightly differs, - // so keep consistent with station data - item.$.telemetryRegion = item.$.region - item.$.region = regions[item.$.region] ? regions[item.$.region] : item.$.region - - await directly(concurrence, item.SetofValues.map(setOfValues => async () => { - let station - - try { - const result = await fetchStation(s3, bucket, `rloi/${item.$.region}/${item.$.stationReference}/station.json`) - const bodyContents = await result.Body.transformToString() - station = JSON.parse(bodyContents) - } catch (err) { - // the console log is commented out so as not to spam the cloudwatch lambda - // logging, as the s3.getObject throws an error when it can't find the object, and there - // are a significant number of telemetry objects that we don't have a matching station - // for, and also hence the need to catch the error here. - // console.log({ err }) - } - - // only process the values if parameter in array or we have a station and Water level match (fsr-123) - if (parameters.indexOf(setOfValues.$.parameter) > -1 || (station && setOfValues.$.parameter === 'Water Level')) { - // if not rloi then Upsert station details to u_flood.sls_telemetry_station, with defaults for rloi specific values - if (!station) { - // dummy values - station = { - RLOI_ID: -1, - Region: item.$.region, - Post_Process: 'n', - Station_Type: 'R' - } - - const telemetryStation = setSlsTelemetryStation(item) - - await client.query('slsTelemetryStation', telemetryStation) - } - - // Store parent details in sls_telemetry_value_parent - const parent = setSlsTelemetryParent(key, station, item, setOfValues) - - const res = await client.query('slsTelemetryValueParent', parent) - const values = [] - // console.log(`Loaded parent: ${station.RLOI_ID} | ${setOfValues.$.parameter} | ${setOfValues.$.qualifier}`) - - // Skip if parent was not inserted (duplicate) - if (!res.rows?.[0]) { - processed++ - return - } - - for (let i = 0; i < setOfValues.Value.length; i++) { - values[i] = setSlsTelemetryValueItem(i, res, station, setOfValues) - } - - // Note: this previously passed a single parameter as a query built using sql-node - await client.query('slsTelemetryValues', values) - // console.log(`Loaded station values: ${station.RLOI_ID} | ${setOfValues.$.parameter} | ${setOfValues.$.qualifier}`) - } - processed++ - })) - if (processed === valuesCount) { - console.log('all values processed') - } + if (!item.SetofValues) { + continue + } + + normaliseStationRegion(item) + + await directly(concurrence, item.SetofValues.map(setOfValues => async () => { + await processSetOfValues({ client, s3, bucket, key, item, setOfValues }) + processed++ + })) + + if (processed === valuesCount) { + console.log('all values processed') } } }, diff --git a/readme.md b/readme.md index 10a1f345..1f131724 100644 --- a/readme.md +++ b/readme.md @@ -41,6 +41,65 @@ Uses the exports context file from sharepoint to update the stations in the data This will use [localstack](https://docs.localstack.cloud/) and the supporting files and documentation to follow. +## Local Debugging - RLOI Process + +To test the `rloi-process` Lambda locally against a real database, use the debug runner: + +### Setup + +1. Ensure your local database is running (PostgreSQL at `127.0.0.1:5433`) +2. Set the database connection: + ```bash + export LFW_DATA_DB_CONNECTION=postgres://u_flood:secret@127.0.0.1:5433/temp_flood_db + ``` + +### Running Single Debug Session + +```bash +# Automatically generates a unique station reference each run +DEBUG_XML_FILE="./test/data/rloi-test.xml" node test/debug-rloi-local.js + +# Or use a fixed station reference to test idempotency +DEBUG_STATION_REF="TEST_STATION_001" DEBUG_XML_FILE="./test/data/rloi-test.xml" node test/debug-rloi-local.js +``` + +### Testing Duplicate Detection + +To verify that `ON CONFLICT DO NOTHING` correctly prevents duplicate rainfall inserts across separate XML files: + +```bash +bash test/test-duplicate-detection.sh +``` + +This script runs two consecutive imports with the same station reference and rainfall data. Expected behavior: +- **Run 1**: Rainfall parent inserted (1 row affected) +- **Run 2**: Duplicate blocked, logged as: `Duplicate telemetry parent skipped: ...` + +### Using VS Code Debugger + +Add this configuration to `.vscode/launch.json` (not committed to git): + +```json +{ + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "debug rloiProcess (local DB)", + "program": "${workspaceFolder}/test/debug-rloi-local.js", + "env": { + "LFW_DATA_DB_CONNECTION": "postgres://u_flood:secret@127.0.0.1:5433/temp_flood_db", + "DEBUG_STATION_REF": "DEBUG_TEST_001", + "DEBUG_XML_FILE": "./test/data/rloi-test.xml" + } + } + ] +} +``` + +Then press `F5` to start debugging with breakpoints. + ## Deployment This is installed using terraforms/terragrunt which is managed by WebOps diff --git a/test/data/rloi-test-rainfall-duplicate.xml b/test/data/rloi-test-rainfall-duplicate.xml new file mode 100644 index 00000000..fceb1ba2 --- /dev/null +++ b/test/data/rloi-test-rainfall-duplicate.xml @@ -0,0 +1,15 @@ + + + Environment Agency + EA South East Regional Telemetry System (Duplicate) + Automated telemetry data export process + SCX 6 + 2018-06-29 + 11:03:48 + SEKMHSCXAS1-DUP + + + 0.0 + + + diff --git a/test/debug-rloi-local.js b/test/debug-rloi-local.js new file mode 100644 index 00000000..568c0160 --- /dev/null +++ b/test/debug-rloi-local.js @@ -0,0 +1,63 @@ +'use strict' + +const fs = require('fs') +const proxyquire = require('proxyquire') + +async function main () { + process.env.LFW_DATA_DB_CONNECTION = process.env.LFW_DATA_DB_CONNECTION || 'postgres://u_flood:secret@127.0.0.1:5433/temp_flood_db' + + const event = { + Records: [ + { + s3: { + bucket: { name: 'local-bucket' }, + object: { key: 'local/rloi-debug.xml' } + } + } + ] + } + + // By default, use a unique station each run (prevents duplicates). + // To test duplicates across files, set DEBUG_STATION_REF to a fixed value. + let stationRef = process.env.DEBUG_STATION_REF + if (!stationRef) { + stationRef = String(960000 + Math.floor(Math.random() * 10000)) + } + + // By default use rloi-test.xml, but allow override via DEBUG_XML_FILE + const xmlFile = process.env.DEBUG_XML_FILE || './test/data/rloi-test.xml' + let telemetryXml = fs.readFileSync(xmlFile, 'utf8') + telemetryXml = telemetryXml.replace(/stationReference="[^"]*"/g, `stationReference="${stationRef}"`) + + const mockS3 = { + async getObject ({ Key }) { + if (Key && Key.endsWith('/station.json')) { + throw new Error('No station file for local debug run') + } + + return { + Body: { + async transformToString () { + return telemetryXml + } + } + } + } + } + + const { handler } = proxyquire('../lib/functions/rloi-process', { + '../helpers/s3': mockS3 + }) + + console.log('Running local rloi debug with:') + console.log(` stationReference=${stationRef}`) + console.log(` xmlFile=${xmlFile}`) + console.log(' Note: Set DEBUG_STATION_REF to fixed value to test duplicates across files') + await handler(event) + console.log('rloi debug run complete') +} + +main().catch((err) => { + console.error(err) + process.exit(1) +}) diff --git a/test/test-duplicate-detection.sh b/test/test-duplicate-detection.sh new file mode 100755 index 00000000..6f70d798 --- /dev/null +++ b/test/test-duplicate-detection.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# Test script to verify duplicate rainfall detection across separate XML files +# This script runs rloi-process twice with the same station reference but different XML files +# Expected behavior: First run inserts parent, second run skips it (ON CONFLICT) + +set -e + +STATION_REF="TEST_DUP_12345" +DB_CONNECTION="postgres://u_flood:secret@127.0.0.1:5433/temp_flood_db" + +echo "========================================" +echo "Testing Duplicate Detection Across Files" +echo "========================================" +echo "" +echo "Using fixed station reference: $STATION_REF" +echo "Database: $DB_CONNECTION" +echo "" + +echo "--- RUN 1: Processing rloi-test.xml ---" +echo "Expected: Parent should be inserted (1 row)" +DEBUG_STATION_REF="$STATION_REF" \ +DEBUG_XML_FILE="./test/data/rloi-test.xml" \ +LFW_DATA_DB_CONNECTION="$DB_CONNECTION" \ +node test/debug-rloi-local.js + +echo "" +echo "--- RUN 2: Processing rloi-test-rainfall-duplicate.xml ---" +echo "Expected: Parent should NOT be inserted (0 rows) - ON CONFLICT DO NOTHING" +DEBUG_STATION_REF="$STATION_REF" \ +DEBUG_XML_FILE="./test/data/rloi-test-rainfall-duplicate.xml" \ +LFW_DATA_DB_CONNECTION="$DB_CONNECTION" \ +node test/debug-rloi-local.js + +echo "" +echo "========================================" +echo "Duplicate test complete!" +echo "Check the logs above to verify:" +echo " Run 1: 1 parent inserted" +echo " Run 2: 0 parents inserted (duplicate blocked)" +echo "========================================" From 860a49cd851c8e9175b0f3297f3a2de507909d37 Mon Sep 17 00:00:00 2001 From: LeeGordon83 Date: Tue, 7 Apr 2026 14:36:15 +0100 Subject: [PATCH 5/7] added local rloi debug setup in test --- test/debug-rloi-local.js | 9 +++++++-- test/test-duplicate-detection.sh | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/test/debug-rloi-local.js b/test/debug-rloi-local.js index 568c0160..aa5f0c25 100644 --- a/test/debug-rloi-local.js +++ b/test/debug-rloi-local.js @@ -1,6 +1,7 @@ 'use strict' const fs = require('fs') +const path = require('path') const proxyquire = require('proxyquire') async function main () { @@ -25,7 +26,11 @@ async function main () { } // By default use rloi-test.xml, but allow override via DEBUG_XML_FILE - const xmlFile = process.env.DEBUG_XML_FILE || './test/data/rloi-test.xml' + // Always resolve from repo root to allow running from anywhere + const rootDir = path.join(__dirname, '..') + const xmlFileArg = process.env.DEBUG_XML_FILE || './test/data/rloi-test.xml' + const xmlFile = path.join(rootDir, xmlFileArg) + let telemetryXml = fs.readFileSync(xmlFile, 'utf8') telemetryXml = telemetryXml.replace(/stationReference="[^"]*"/g, `stationReference="${stationRef}"`) @@ -51,7 +56,7 @@ async function main () { console.log('Running local rloi debug with:') console.log(` stationReference=${stationRef}`) - console.log(` xmlFile=${xmlFile}`) + console.log(` xmlFile=${xmlFileArg}`) console.log(' Note: Set DEBUG_STATION_REF to fixed value to test duplicates across files') await handler(event) console.log('rloi debug run complete') diff --git a/test/test-duplicate-detection.sh b/test/test-duplicate-detection.sh index 6f70d798..463ecb08 100755 --- a/test/test-duplicate-detection.sh +++ b/test/test-duplicate-detection.sh @@ -5,6 +5,11 @@ set -e +# Ensure we're running from the repo root +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(dirname "$SCRIPT_DIR")" +cd "$REPO_ROOT" + STATION_REF="TEST_DUP_12345" DB_CONNECTION="postgres://u_flood:secret@127.0.0.1:5433/temp_flood_db" From 40f01677d34dbd3e8cf98d52b4164fea57f96286 Mon Sep 17 00:00:00 2001 From: LeeGordon83 Date: Tue, 7 Apr 2026 16:28:21 +0100 Subject: [PATCH 6/7] sonar fix --- lib/models/rloi.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/models/rloi.js b/lib/models/rloi.js index d5d4edbb..8693c1db 100644 --- a/lib/models/rloi.js +++ b/lib/models/rloi.js @@ -5,7 +5,7 @@ const util = require('../helpers/util') const directly = require('directly') // telemetry parameters to import (Water level is if rloi station exists) -const parameters = ['Rainfall'] +const parameters = new Set(['Rainfall']) const processedValueDecimalPlace = 3 @@ -108,7 +108,7 @@ async function getStationOrNull (s3, bucket, item) { } function shouldProcessValues (setOfValues, station) { - return parameters.includes(setOfValues.$.parameter) || (station && setOfValues.$.parameter === 'Water Level') + return parameters.has(setOfValues.$.parameter) || (station && setOfValues.$.parameter === 'Water Level') } async function ensureStation (client, item, station) { From 9099dec03db1e2372155beaf962b72dacfd2841d Mon Sep 17 00:00:00 2001 From: LeeGordon83 Date: Tue, 7 Apr 2026 16:30:13 +0100 Subject: [PATCH 7/7] removed trailing space --- test/debug-rloi-local.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/debug-rloi-local.js b/test/debug-rloi-local.js index aa5f0c25..5b0dd8d7 100644 --- a/test/debug-rloi-local.js +++ b/test/debug-rloi-local.js @@ -30,7 +30,7 @@ async function main () { const rootDir = path.join(__dirname, '..') const xmlFileArg = process.env.DEBUG_XML_FILE || './test/data/rloi-test.xml' const xmlFile = path.join(rootDir, xmlFileArg) - + let telemetryXml = fs.readFileSync(xmlFile, 'utf8') telemetryXml = telemetryXml.replace(/stationReference="[^"]*"/g, `stationReference="${stationRef}"`)