diff --git a/server/models/views/lib/find-min-threshold.js b/server/models/views/lib/find-min-threshold.js
new file mode 100644
index 000000000..6ed5b12cb
--- /dev/null
+++ b/server/models/views/lib/find-min-threshold.js
@@ -0,0 +1,37 @@
+function getMinFromType (arr, type) {
+ const filtered = arr.filter(item => item.threshold_type === type)
+ if (filtered.length) {
+ return filtered.reduce((min, curr) => parseFloat(curr.value) < parseFloat(min.value) ? curr : min)
+ }
+ return null
+}
+
+function findMinValueByLogic (arr, type) {
+ if (type === 'A') {
+ // Logic for Type A
+ return getMinFromType(arr, 'FW RES FAL') ||
+ getMinFromType(arr, 'FW ACT FAL') ||
+ getMinFromType(arr, 'FW ACTCON FAL')
+ } else if (type === 'W') {
+ // Logic for Type W
+ return getMinFromType(arr, 'FW RES FW') ||
+ getMinFromType(arr, 'FW ACT FW') ||
+ getMinFromType(arr, 'FW ACTCON FW')
+ }
+ return null
+}
+
+function filterImtdThresholds (imtdThresholds) {
+ const typeA = imtdThresholds.filter(item => item.fwis_type === 'A')
+ const typeW = imtdThresholds.filter(item => item.fwis_type === 'W')
+
+ const minObjectA = findMinValueByLogic(typeA, 'A')
+ const minObjectW = findMinValueByLogic(typeW, 'W')
+
+ return {
+ alert: minObjectA ? minObjectA.value : null,
+ warning: minObjectW ? minObjectW.value : null
+ }
+}
+
+module.exports = filterImtdThresholds
diff --git a/server/models/views/station.js b/server/models/views/station.js
index 2e448980a..77fc2959f 100644
--- a/server/models/views/station.js
+++ b/server/models/views/station.js
@@ -1,4 +1,3 @@
-// const hoek = require('@hapi/hoek')
const moment = require('moment-timezone')
const config = require('../../config')
const severity = require('../severity')
@@ -7,6 +6,7 @@ const Forecast = require('./station-forecast')
const util = require('../../util')
const tz = 'Europe/London'
const processImtdThresholds = require('./lib/process-imtd-thresholds')
+const filterImtdThresholds = require('./lib/find-min-threshold')
class ViewModel {
constructor (options) {
@@ -31,7 +31,6 @@ class ViewModel {
trend: river.trend
})
// Group warnings/alerts by severity level
-
const warningsAlertsGroups = util.groupBy(warningsAlerts, 'severity_value')
const numAlerts = warningsAlertsGroups['1'] ? warningsAlertsGroups['1'].length : 0
const numWarnings = warningsAlertsGroups['2'] ? warningsAlertsGroups['2'].length : 0
@@ -248,8 +247,12 @@ class ViewModel {
})
}
+ this.imtdThresholds = imtdThresholds?.length > 0
+ ? filterImtdThresholds(imtdThresholds)
+ : []
+
const processedImtdThresholds = processImtdThresholds(
- imtdThresholds,
+ this.imtdThresholds,
this.station.stageDatum,
this.station.subtract,
this.station.post_process
diff --git a/test/data/forcastStationModelData.json b/test/data/forcastStationModelData.json
index 919ed1b98..465211408 100644
--- a/test/data/forcastStationModelData.json
+++ b/test/data/forcastStationModelData.json
@@ -4,6 +4,7 @@
"ffoi_station_threshold_id": 507,
"ffoi_station_id": 87,
"fwis_code": "062WAF28Mimmshal",
+ "fwis_type": "FW ACTCON FAL",
"value": 0.96,
"fwa_name": "Mimmshall Brook",
"fwa_type": "a",
@@ -13,6 +14,7 @@
"ffoi_station_threshold_id": 508,
"ffoi_station_id": 87,
"fwis_code": "062WAF28UpColne",
+ "fwis_type": "FW ACTCON FAL",
"value": 2.3,
"fwa_name": "Upper River Colne and Radlett Brook",
"fwa_type": "a",
@@ -22,6 +24,7 @@
"ffoi_station_threshold_id": 509,
"ffoi_station_id": 87,
"fwis_code": "062FWF28Warrengt",
+ "fwis_type": "FW ACTCON FW",
"value": 2.24,
"fwa_name": "Mimmshall Brook at Warrengate Road",
"fwa_type": "w",
@@ -31,6 +34,7 @@
"ffoi_station_threshold_id": 510,
"ffoi_station_id": 87,
"fwis_code": "062FWF28CHeath",
+ "fwis_type": "FW ACTCON FAL",
"value": 2.7,
"fwa_name": "River Colne at Colney Heath",
"fwa_type": "w",
@@ -88,4 +92,4 @@
}
]
}
-}
\ No newline at end of file
+}
diff --git a/test/data/stationForecastData.json b/test/data/stationForecastData.json
index 70e7e94b0..e753acc45 100644
--- a/test/data/stationForecastData.json
+++ b/test/data/stationForecastData.json
@@ -48,6 +48,7 @@
"ffoi_station_threshold_id":507,
"ffoi_station_id":87,
"fwis_code":"062WAF28Mimmshal",
+ "fwis_type": "FW ACTCON FAL",
"value":0.96,
"fwa_name":"Mimmshall Brook",
"fwa_type":"a",
@@ -57,6 +58,7 @@
"ffoi_station_threshold_id":508,
"ffoi_station_id":87,
"fwis_code":"062WAF28UpColne",
+ "fwis_type": "FW ACTCON FAL",
"value":2.3,
"fwa_name":"Upper River Colne and Radlett Brook",
"fwa_type":"a",
@@ -66,6 +68,7 @@
"ffoi_station_threshold_id":509,
"ffoi_station_id":87,
"fwis_code":"062FWF28Warrengt",
+ "fwis_type": "FW ACTCON FW",
"value":2.24,
"fwa_name":"Mimmshall Brook at Warrengate Road",
"fwa_type":"w",
@@ -75,6 +78,7 @@
"ffoi_station_threshold_id":510,
"ffoi_station_id":87,
"fwis_code":"062FWF28CHeath",
+ "fwis_type": "FW ACTCON FAL",
"value":2.7,
"fwa_name":"River Colne at Colney Heath",
"fwa_type":"w",
@@ -297,5 +301,60 @@
"geometry":"{\"type\":\"Point\",\"coordinates\":[-3.03674273776571,53.8811798090409]}"
}
],
- "imtdThresholds": { "alert": "44.91", "warning": "43.91" }
+ "imtdThresholds": [
+ {
+ "station_threshold_id": "1503831",
+ "station_id": "1001",
+ "fwis_code": "065WAF434",
+ "fwis_type": "A",
+ "direction": "u",
+ "value": "3.5",
+ "threshold_type": "FW ACTCON FAL"
+ },
+ {
+ "station_threshold_id": "1503832",
+ "station_id": "1001",
+ "fwis_code": "065WAF434",
+ "fwis_type": "A",
+ "direction": "u",
+ "value": "3.88",
+ "threshold_type": "FW ACT FAL"
+ },
+ {
+ "station_threshold_id": "1503833",
+ "station_id": "1001",
+ "fwis_code": "065FWF5402",
+ "fwis_type": "W",
+ "direction": "u",
+ "value": "3.9",
+ "threshold_type": "FW ACTCON FW"
+ },
+ {
+ "station_threshold_id": "1503834",
+ "station_id": "1001",
+ "fwis_code": "065FWF5402",
+ "fwis_type": "W",
+ "direction": "u",
+ "value": "4",
+ "threshold_type": "FW ACTCON FW"
+ },
+ {
+ "station_threshold_id": "1503835",
+ "station_id": "1001",
+ "fwis_code": "065FWF5402",
+ "fwis_type": "W",
+ "direction": "u",
+ "value": "4.2",
+ "threshold_type": "FW ACT FW"
+ },
+ {
+ "station_threshold_id": "1503836",
+ "station_id": "1001",
+ "fwis_code": "065FWF5402",
+ "fwis_type": "W",
+ "direction": "u",
+ "value": "4.3",
+ "threshold_type": "FW ACT FW"
+ }
+ ]
}
diff --git a/test/data/stationRiver.json b/test/data/stationRiver.json
index 8fdc138bb..01c9fd90b 100644
--- a/test/data/stationRiver.json
+++ b/test/data/stationRiver.json
@@ -1,90 +1,145 @@
{
- "station":{
- "rloi_id":1001,
- "station_type":"S",
- "qualifier":"u",
- "telemetry_context_id":"1364571",
- "telemetry_id":"E9140",
- "wiski_id":"253110011",
- "post_process":true,
- "subtract":"0.66",
- "region":"Southern",
- "area":"Solent and South Downs",
- "catchment":"Adur",
- "display_region":"South East",
- "display_area":"Solent and South Downs",
- "display_catchment":"Adur and Ouse",
- "agency_name":"Beeding Bridge",
- "external_name":"Beeding Bridge",
- "location_info":"Upper Beeding",
- "x_coord_actual":519204,
- "y_coord_actual":110626,
- "actual_ngr":"",
- "x_coord_display":519204,
- "y_coord_display":110626,
- "site_max":"4",
- "wiski_river_name":"River Adur",
- "date_open":"1998-01-01T00:00:00.000Z",
- "stage_datum":"0.66",
- "period_of_record":"to date",
- "por_max_value":"3.35",
- "date_por_max":"2013-12-06T01:45:00.000Z",
- "highest_level":"4.007",
- "date_highest_level":"2013-12-06T02:00:00.000Z",
- "por_min_value":"0",
- "date_por_min":"2005-03-21T04:30:00.000Z",
- "percentile_5":"2.84",
- "percentile_95":"0.353",
- "comments":"",
- "status":"Active",
- "status_reason":"",
- "status_date":"2019-01-16T12:22:00.000Z",
- "coordinates":"{\"type\":\"Point\",\"coordinates\":[-0.306835309255374,50.8828385361225]}",
- "geography":"0101000020E6100000CCA1A09030A3D3BFB42568DA00714940",
- "centroid":"0101000020E6100000CCA1A09030A3D3BFB42568DA00714940"
+ "station": {
+ "rloi_id": 1001,
+ "station_type": "S",
+ "qualifier": "u",
+ "telemetry_context_id": "1364571",
+ "telemetry_id": "E9140",
+ "wiski_id": "253110011",
+ "post_process": true,
+ "subtract": "0.66",
+ "region": "Southern",
+ "area": "Solent and South Downs",
+ "catchment": "Adur",
+ "display_region": "South East",
+ "display_area": "Solent and South Downs",
+ "display_catchment": "Adur and Ouse",
+ "agency_name": "Beeding Bridge",
+ "external_name": "Beeding Bridge",
+ "location_info": "Upper Beeding",
+ "x_coord_actual": 519204,
+ "y_coord_actual": 110626,
+ "actual_ngr": "",
+ "x_coord_display": 519204,
+ "y_coord_display": 110626,
+ "site_max": "4",
+ "wiski_river_name": "River Adur",
+ "date_open": "1998-01-01T00:00:00.000Z",
+ "stage_datum": "0.66",
+ "period_of_record": "to date",
+ "por_max_value": "3.35",
+ "date_por_max": "2013-12-06T01:45:00.000Z",
+ "highest_level": "4.007",
+ "date_highest_level": "2013-12-06T02:00:00.000Z",
+ "por_min_value": "0",
+ "date_por_min": "2005-03-21T04:30:00.000Z",
+ "percentile_5": "2.84",
+ "percentile_95": "0.353",
+ "comments": "",
+ "status": "Active",
+ "status_reason": "",
+ "status_date": "2019-01-16T12:22:00.000Z",
+ "coordinates": "{\"type\":\"Point\",\"coordinates\":[-0.306835309255374,50.8828385361225]}",
+ "geography": "0101000020E6100000CCA1A09030A3D3BFB42568DA00714940",
+ "centroid": "0101000020E6100000CCA1A09030A3D3BFB42568DA00714940"
+ },
+ "telemetry": [
+ {
+ "_": 0.805,
+ "err": false,
+ "ts": "2020-07-13T12:00Z"
},
- "telemetry":[
- {
- "_":0.805,
- "err":false,
- "ts":"2020-07-13T12:00Z"
- },
- {
- "_":0.805,
- "err":false,
- "ts":"2020-07-13T11:45Z"
- }
- ],
- "impacts":[],
- "river":{
- "river_id":"river-adur",
- "river_name":"River Adur",
- "navigable":true,
- "view_rank":3,
- "rank":2,
- "rloi_id":1001,
- "up":1006,
- "down":1032,
- "telemetry_id":"E9140",
- "region":"Southern",
- "catchment":"Adur",
- "wiski_river_name":"River Adur",
- "agency_name":"Beeding Bridge",
- "external_name":"Beeding Bridge",
- "station_type":"S",
- "status":"Active",
- "qualifier":"u",
- "iswales":false,
- "value":"0.805",
- "value_timestamp":"2020-07-13T12:00:00.000Z",
- "value_erred":false,
- "trend":"steady",
- "percentile_5":"2.84",
- "percentile_95":"0.353",
- "centroid":"0101000020E6100000CCA1A09030A3D3BFB42568DA00714940",
- "lon":-0.306835309255374,
- "lat":50.8828385361225
- },
- "warningsAlerts":[],
- "imtdThresholds": { "alert": 1.222, "warning": 2.111 }
+ {
+ "_": 0.805,
+ "err": false,
+ "ts": "2020-07-13T11:45Z"
+ }
+ ],
+ "impacts": [],
+ "river": {
+ "river_id": "river-adur",
+ "river_name": "River Adur",
+ "navigable": true,
+ "view_rank": 3,
+ "rank": 2,
+ "rloi_id": 1001,
+ "up": 1006,
+ "down": 1032,
+ "telemetry_id": "E9140",
+ "region": "Southern",
+ "catchment": "Adur",
+ "wiski_river_name": "River Adur",
+ "agency_name": "Beeding Bridge",
+ "external_name": "Beeding Bridge",
+ "station_type": "S",
+ "status": "Active",
+ "qualifier": "u",
+ "iswales": false,
+ "value": "0.805",
+ "value_timestamp": "2020-07-13T12:00:00.000Z",
+ "value_erred": false,
+ "trend": "steady",
+ "percentile_5": "2.84",
+ "percentile_95": "0.353",
+ "centroid": "0101000020E6100000CCA1A09030A3D3BFB42568DA00714940",
+ "lon": -0.306835309255374,
+ "lat": 50.8828385361225
+ },
+ "warningsAlerts": [],
+ "imtdThresholds": [
+ {
+ "station_threshold_id": "1503831",
+ "station_id": "1001",
+ "fwis_code": "065WAF434",
+ "fwis_type": "A",
+ "direction": "u",
+ "value": "3.5",
+ "threshold_type": "FW ACTCON FAL"
+ },
+ {
+ "station_threshold_id": "1503832",
+ "station_id": "1001",
+ "fwis_code": "065WAF434",
+ "fwis_type": "A",
+ "direction": "u",
+ "value": "3.88",
+ "threshold_type": "FW RES FAL"
+ },
+ {
+ "station_threshold_id": "1503833",
+ "station_id": "1001",
+ "fwis_code": "065FWF5402",
+ "fwis_type": "W",
+ "direction": "u",
+ "value": "3.9",
+ "threshold_type": "FW ACTCON FW"
+ },
+ {
+ "station_threshold_id": "1503834",
+ "station_id": "1001",
+ "fwis_code": "065FWF5402",
+ "fwis_type": "W",
+ "direction": "u",
+ "value": "4",
+ "threshold_type": "FW ACTCON FW"
+ },
+ {
+ "station_threshold_id": "1503835",
+ "station_id": "1001",
+ "fwis_code": "065FWF5402",
+ "fwis_type": "W",
+ "direction": "u",
+ "value": "4.2",
+ "threshold_type": "FW ACT FW"
+ },
+ {
+ "station_threshold_id": "1503836",
+ "station_id": "1001",
+ "fwis_code": "065FWF5402",
+ "fwis_type": "W",
+ "direction": "u",
+ "value": "4.3",
+ "threshold_type": "FW RES FW"
+ }
+ ]
}
diff --git a/test/data/stationRiverACTCON.json b/test/data/stationRiverACTCON.json
new file mode 100644
index 000000000..b5abb6ffa
--- /dev/null
+++ b/test/data/stationRiverACTCON.json
@@ -0,0 +1,109 @@
+{
+ "station": {
+ "rloi_id": 1001,
+ "station_type": "S",
+ "qualifier": "u",
+ "telemetry_context_id": "1364571",
+ "telemetry_id": "E9140",
+ "wiski_id": "253110011",
+ "post_process": true,
+ "subtract": "0.66",
+ "region": "Southern",
+ "area": "Solent and South Downs",
+ "catchment": "Adur",
+ "display_region": "South East",
+ "display_area": "Solent and South Downs",
+ "display_catchment": "Adur and Ouse",
+ "agency_name": "Beeding Bridge",
+ "external_name": "Beeding Bridge",
+ "location_info": "Upper Beeding",
+ "x_coord_actual": 519204,
+ "y_coord_actual": 110626,
+ "actual_ngr": "",
+ "x_coord_display": 519204,
+ "y_coord_display": 110626,
+ "site_max": "4",
+ "wiski_river_name": "River Adur",
+ "date_open": "1998-01-01T00:00:00.000Z",
+ "stage_datum": "0.66",
+ "period_of_record": "to date",
+ "por_max_value": "3.35",
+ "date_por_max": "2013-12-06T01:45:00.000Z",
+ "highest_level": "4.007",
+ "date_highest_level": "2013-12-06T02:00:00.000Z",
+ "por_min_value": "0",
+ "date_por_min": "2005-03-21T04:30:00.000Z",
+ "percentile_5": "2.84",
+ "percentile_95": "0.353",
+ "comments": "",
+ "status": "Active",
+ "status_reason": "",
+ "status_date": "2019-01-16T12:22:00.000Z",
+ "coordinates": "{\"type\":\"Point\",\"coordinates\":[-0.306835309255374,50.8828385361225]}",
+ "geography": "0101000020E6100000CCA1A09030A3D3BFB42568DA00714940",
+ "centroid": "0101000020E6100000CCA1A09030A3D3BFB42568DA00714940"
+ },
+ "telemetry": [
+ {
+ "_": 0.805,
+ "err": false,
+ "ts": "2020-07-13T12:00Z"
+ },
+ {
+ "_": 0.805,
+ "err": false,
+ "ts": "2020-07-13T11:45Z"
+ }
+ ],
+ "impacts": [],
+ "river": {
+ "river_id": "river-adur",
+ "river_name": "River Adur",
+ "navigable": true,
+ "view_rank": 3,
+ "rank": 2,
+ "rloi_id": 1001,
+ "up": 1006,
+ "down": 1032,
+ "telemetry_id": "E9140",
+ "region": "Southern",
+ "catchment": "Adur",
+ "wiski_river_name": "River Adur",
+ "agency_name": "Beeding Bridge",
+ "external_name": "Beeding Bridge",
+ "station_type": "S",
+ "status": "Active",
+ "qualifier": "u",
+ "iswales": false,
+ "value": "0.805",
+ "value_timestamp": "2020-07-13T12:00:00.000Z",
+ "value_erred": false,
+ "trend": "steady",
+ "percentile_5": "2.84",
+ "percentile_95": "0.353",
+ "centroid": "0101000020E6100000CCA1A09030A3D3BFB42568DA00714940",
+ "lon": -0.306835309255374,
+ "lat": 50.8828385361225
+ },
+ "warningsAlerts": [],
+ "imtdThresholds": [
+ {
+ "station_threshold_id": "1503831",
+ "station_id": "1001",
+ "fwis_code": "065WAF434",
+ "fwis_type": "A",
+ "direction": "u",
+ "value": "3.5",
+ "threshold_type": "FW ACTCON FAL"
+ },
+ {
+ "station_threshold_id": "1503832",
+ "station_id": "1001",
+ "fwis_code": "065WAF434",
+ "fwis_type": "W",
+ "direction": "u",
+ "value": "3.88",
+ "threshold_type": "FW ACTCON FW"
+ }
+ ]
+}
diff --git a/test/models/station.js b/test/models/station.js
index fdfa33cfd..24f507c75 100644
--- a/test/models/station.js
+++ b/test/models/station.js
@@ -34,20 +34,57 @@ lab.experiment('Station model test', () => {
Code.expect(Result.pageTitle).to.equal('River Adur level at Beeding Bridge')
Code.expect(Result.dataOverHourOld).to.equal(true)
Code.expect(Result.postTitle).to.equal('Latest river level information for the River Adur at Beeding Bridge ')
- Code.expect(Result.thresholds[2].values).to.equal([
+ Code.expect(Result.thresholds[0].values).to.equal([
{
id: 'warningThreshold',
- value: '1.45',
description: 'Property flooding is possible above this level. One or more flood warnings may be issued',
- shortname: 'Possible flood warnings'
+ shortname: 'Possible flood warnings',
+ value: '3.64'
+ }
+ ])
+ Code.expect(Result.thresholds[2].values).to.equal([
+ {
+ id: 'alertThreshold',
+ description: 'Low lying land flooding is possible above this level. One or more flood alerts may be issued',
+ shortname: 'Possible flood alerts',
+ value: '3.22'
}
])
Code.expect(Result.thresholds[4].values).to.equal([
+ {
+ id: 'latest',
+ value: '0.81',
+ description: 'Latest level',
+ shortname: ''
+ }
+ ])
+ })
+ lab.test('Test station viewModel river station 1001 only has FW ATCON thresholds', async () => {
+ const stationData = data.stationRiverACTCON
+ const viewModel = new ViewModel(stationData)
+
+ const Result = viewModel
+
+ Code.expect(Result.thresholds[1].values).to.equal([
+ {
+ id: 'warningThreshold',
+ description: 'Property flooding is possible above this level. One or more flood warnings may be issued',
+ shortname: 'Possible flood warnings',
+ value: '3.22'
+ }
+ ])
+ Code.expect(Result.thresholds[2].values).to.equal([
{
id: 'alertThreshold',
- value: '0.56',
description: 'Low lying land flooding is possible above this level. One or more flood alerts may be issued',
- shortname: 'Possible flood alerts'
+ shortname: 'Possible flood alerts',
+ value: '2.84'
+ },
+ {
+ description: 'This is the top of the normal range',
+ id: 'pc5',
+ shortname: 'Top of normal range',
+ value: '2.84'
}
])
})
@@ -142,7 +179,7 @@ lab.experiment('Station model test', () => {
const viewModel = new ViewModel(data.stationCoastal)
Code.expect(viewModel.station.plotNegativeValues).to.equal(true)
})
- lab.test('Test station viewModel FFOI station with Impacts', async () => {
+ lab.test('Test station viewModel FFOI station with Impacts ', async () => {
const stationData = data.stationForecastData
const today = moment().format('YYYY-MM-DD')
@@ -183,7 +220,28 @@ lab.experiment('Station model test', () => {
Code.expect(Result.station.id).to.equal(7177)
Code.expect(Result.station.hasImpacts).to.equal(true)
Code.expect(Result.station.formattedPorMaxDate).to.equal('10/02/09')
- Code.expect(Result.thresholds[0].level).to.equal('44.91')
+
+ // Should have FW ACT FAL 3.88 and FW ACT FW 4.20 thresholds as the are no FW RES FAL and FW RES FW in imtdThresholds
+ Code.expect(Result.thresholds[0].values).to.equal(
+ [
+ {
+ description: 'Property flooding is possible above this level. One or more flood warnings may be issued',
+ id: 'warningThreshold',
+ shortname: 'Possible flood warnings',
+ value: '4.20'
+ }
+ ]
+ )
+ Code.expect(Result.thresholds[1].values).to.equal(
+ [
+ {
+ id: 'alertThreshold',
+ description: 'Low lying land flooding is possible above this level. One or more flood alerts may be issued',
+ shortname: 'Possible flood alerts',
+ value: '3.88'
+ }
+ ]
+ )
Code.expect(Result.isUpstream).to.equal(true)
Code.expect(Result.isDownstream).to.equal(false)
Code.expect(Result.severeBanner).to.equal('Severe flood warning for Coast from Fleetwood to Blackpool')
diff --git a/test/routes/station-csv.js b/test/routes/station-csv.js
index ad72d36fd..33087c9b0 100644
--- a/test/routes/station-csv.js
+++ b/test/routes/station-csv.js
@@ -70,6 +70,7 @@ lab.experiment('Routes test - station-csv', () => {
ffoi_station_threshold_id: 133,
ffoi_station_id: 19,
fwis_code: '031WAF213',
+ fwis_type: 'FW ACTCON FAL',
value: 2,
fwa_name: 'River Leadon Catchment',
fwa_type: 'a',
diff --git a/test/routes/station.js b/test/routes/station.js
index 6c33d1fdf..3b722d171 100644
--- a/test/routes/station.js
+++ b/test/routes/station.js
@@ -235,7 +235,7 @@ lab.experiment('Test - /station/{id}', () => {
const fakeStationForecastData = () => []
const fakeWarningsAlertsData = () => []
- const fakeStationThresholdData = () => { return { alert: null, warning: null } }
+ const fakeStationThresholdData = () => []
sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData)
sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData)
@@ -367,7 +367,7 @@ lab.experiment('Test - /station/{id}', () => {
const fakeImpactsData = () => []
const fakeThresholdsData = () => []
const fakeTargetAreasData = () => []
- const fakeStationThresholdData = () => { return { alert: null, warning: null } }
+ const fakeStationThresholdData = () => []
sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData)
sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverData)
@@ -504,7 +504,7 @@ lab.experiment('Test - /station/{id}', () => {
const fakeImpactsData = () => []
const fakeThresholdsData = () => []
const fakeWarningsAlertsData = () => []
- const fakeStationThresholdData = () => { return { alert: null, warning: null } }
+ const fakeStationThresholdData = () => []
sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData)
sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverData)
@@ -638,7 +638,7 @@ lab.experiment('Test - /station/{id}', () => {
const fakeImpactsData = () => []
const fakeThresholdsData = () => []
const fakeWarningsAlertsData = () => []
- const fakeStationThresholdData = () => { return { alert: null, warning: null } }
+ const fakeStationThresholdData = () => []
sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData)
sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverData)
@@ -737,7 +737,7 @@ lab.experiment('Test - /station/{id}', () => {
const fakeThresholdsData = () => []
const fakeWarningsAlertsData = () => []
const fakeRiverStationData = () => []
- const fakeStationThresholdData = () => { return { alert: null, warning: null } }
+ const fakeStationThresholdData = () => []
sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData)
sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData)
@@ -870,7 +870,7 @@ lab.experiment('Test - /station/{id}', () => {
const fakeImpactsData = () => []
const fakeThresholdsData = () => []
const fakeWarningsAlertsData = () => []
- const fakeStationThresholdData = () => { return { alert: null, warning: null } }
+ const fakeStationThresholdData = () => []
sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData)
sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverData)
@@ -1006,7 +1006,7 @@ lab.experiment('Test - /station/{id}', () => {
const fakeImpactsData = () => []
const fakeThresholdsData = () => []
const fakeWarningsAlertsData = () => []
- const fakeStationThresholdData = () => { return { alert: null, warning: null } }
+ const fakeStationThresholdData = () => []
sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData)
sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverData)
@@ -1253,7 +1253,7 @@ lab.experiment('Test - /station/{id}', () => {
const fakeStationForecastData = () => data.fakeStationForecastData
const fakeWarningsAlertsData = () => []
- const fakeStationThresholdData = () => { return { alert: null, warning: null } }
+ const fakeStationThresholdData = () => []
sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData)
sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData)
@@ -1502,7 +1502,7 @@ lab.experiment('Test - /station/{id}', () => {
const fakeStationForecastData = () => data.fakeStationForecastDataMax
const fakeWarningsAlertsData = () => []
- const fakeStationThresholdData = () => { return { alert: null, warning: null } }
+ const fakeStationThresholdData = () => []
fakeStationForecastData().SetofValues[0].Value[0].$.date = moment().utc().add(1, 'hours').format('YYYY-MM-DD')
fakeStationForecastData().SetofValues[0].Value[0].$.time = moment().utc().add(1, 'hours').format('HH:mm:ss')
@@ -1642,7 +1642,7 @@ lab.experiment('Test - /station/{id}', () => {
const fakeImpactsData = () => []
const fakeThresholdsData = () => []
const fakeTargetAreasData = () => []
- const fakeStationThresholdData = () => { return { alert: null, warning: null } }
+ const fakeStationThresholdData = () => []
sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData)
sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverData)
@@ -1932,7 +1932,7 @@ lab.experiment('Test - /station/{id}', () => {
const fakeImpactsData = () => []
const fakeThresholdsData = () => []
const fakeTargetAreasData = () => []
- const fakeStationThresholdData = () => { return { alert: null, warning: null } }
+ const fakeStationThresholdData = () => []
sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData)
sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverData)
@@ -1973,136 +1973,6 @@ lab.experiment('Test - /station/{id}', () => {
Code.expect(response.payload).to.contain('Upstream')
Code.expect(response.payload).to.contain('Download data CSV (12KB)')
})
- lab.test('GET station/5146 with Normal river level shows IMTD thresholds if present', async () => {
- const floodService = require('../../server/services/flood')
-
- const fakeStationData = () => {
- return {
- rloi_id: 5146,
- station_type: 'S',
- qualifier: 'u',
- telemetry_context_id: '1146588',
- telemetry_id: '713030',
- wiski_id: '713030',
- post_process: false,
- subtract: null,
- region: 'North West',
- area: 'Cumbria and Lancashire',
- catchment: 'Ribble Douglas and Crossens',
- display_region: 'North West',
- display_area: '',
- display_catchment: '',
- agency_name: 'Walton-Le-Dale',
- external_name: 'Walton-Le-Dale',
- location_info: 'Preston',
- x_coord_actual: 355230,
- y_coord_actual: 428720,
- actual_ngr: '',
- x_coord_display: 355230,
- y_coord_display: 428720,
- site_max: '5',
- wiski_river_name: 'River Ribble',
- date_open: '2001-01-01T00:00:00.000Z',
- stage_datum: '3.642',
- period_of_record: 'to date',
- por_max_value: '5.488',
- date_por_max: '2020-02-09T18:15:00.000Z',
- highest_level: '3.469',
- date_highest_level: '2012-09-26T01:15:00.000Z',
- por_min_value: '-0.07',
- date_por_min: '2009-04-22T12:45:00.000Z',
- percentile_5: '3.5',
- percentile_95: '0.15',
- comments: '',
- status: 'Active',
- status_reason: '',
- status_date: null,
- coordinates: '{"type":"Point","coordinates":[-2.68044442027032,53.7529105624953]}',
- geography: '0101000020E61000001A741ED88C7105C0755D915F5FE04A40',
- centroid: '0101000020E61000001A741ED88C7105C0755D915F5FE04A40'
- }
- }
-
- const fakeRiverData = () => {
- return {
- river_id: 'river-ribble',
- river_name: 'River Ribble',
- navigable: true,
- view_rank: 3,
- rank: 9,
- rloi_id: 5146,
- up: 5122,
- down: null,
- telemetry_id: '713030',
- region: 'North West',
- catchment: 'Ribble Douglas and Crossens',
- wiski_river_name: 'River Ribble',
- agency_name: 'Walton-Le-Dale',
- external_name: 'Walton-Le-Dale',
- station_type: 'S',
- status: 'Active',
- qualifier: 'u',
- iswales: false,
- value: '9.567',
- value_timestamp: '2020-03-17T04:30:00.000Z',
- value_erred: false,
- percentile_5: '3.5',
- percentile_95: '0.15',
- centroid: '0101000020E61000001A741ED88C7105C0755D915F5FE04A40',
- lon: -2.68044442027032,
- lat: 53.7529105624953
- }
- }
-
- const fakeTelemetryData = () => [
- {
- ts: '2020-03-13T01:30Z',
- _: 1.354,
- err: false
- }
- ]
-
- const fakeImpactsData = () => []
- const fakeThresholdsData = () => []
- const fakeTargetAreasData = () => []
- const fakeStationThresholdData = () => { return { alert: 1.11, warning: 2.11 } }
-
- sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData)
- sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverData)
- sandbox.stub(floodService, 'getStationTelemetry').callsFake(fakeTelemetryData)
- sandbox.stub(floodService, 'getImpactData').callsFake(fakeImpactsData)
- sandbox.stub(floodService, 'getStationForecastThresholds').callsFake(fakeThresholdsData)
- sandbox.stub(floodService, 'getStationImtdThresholds').callsFake(fakeStationThresholdData)
- sandbox.stub(floodService, 'getWarningsAlertsWithinStationBuffer').callsFake(fakeTargetAreasData)
-
- const stationPlugin = {
- plugin: {
- name: 'station',
- register: (server, options) => {
- server.route(require('../../server/routes/station'))
- }
- }
- }
-
- await server.register(require('../../server/plugins/views'))
- await server.register(require('../../server/plugins/session'))
- await server.register(stationPlugin)
- // Add Cache methods to server
- const registerServerMethods = require('../../server/services/server-methods')
- registerServerMethods(server)
-
- await server.initialize()
- const options = {
- method: 'GET',
- url: '/station/5146'
- }
-
- const response = await server.inject(options)
-
- Code.expect(response.statusCode).to.equal(200)
- Code.expect(response.payload).to.contain('Low lying land flooding is possible above this level. One or more flood alerts may be issued')
- Code.expect(response.payload).to.contain('Property flooding is possible above this level. One or more flood warnings may be issued')
- })
lab.test('GET station/5146 with Normal river level does no show IMTD thresholds if not present', async () => {
const floodService = require('../../server/services/flood')
@@ -2326,7 +2196,7 @@ lab.experiment('Test - /station/{id}', () => {
const fakeImpactsData = () => []
const fakeThresholdsData = () => []
const fakeTargetAreasData = () => []
- const fakeStationThresholdData = () => { return { alert: null, warning: null } }
+ const fakeStationThresholdData = () => []
sandbox.stub(floodService, 'getStationById').callsFake(fakeStationData)
sandbox.stub(floodService, 'getRiverStationByStationId').callsFake(fakeRiverData)