Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FSR-965 | IMTD Logic change #552

Merged
merged 4 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions server/models/views/lib/find-min-threshold.js
Original file line number Diff line number Diff line change
@@ -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
9 changes: 6 additions & 3 deletions server/models/views/station.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// const hoek = require('@hapi/hoek')
const moment = require('moment-timezone')
const config = require('../../config')
const severity = require('../severity')
Expand All @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion test/data/forcastStationModelData.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -88,4 +92,4 @@
}
]
}
}
}
61 changes: 60 additions & 1 deletion test/data/stationForecastData.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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"
}
]
}
Loading
Loading