diff --git a/server/models/views/lib/process-imtd-thresholds.js b/server/models/views/lib/process-imtd-thresholds.js index 741c35a9b..54852fe8b 100644 --- a/server/models/views/lib/process-imtd-thresholds.js +++ b/server/models/views/lib/process-imtd-thresholds.js @@ -80,5 +80,6 @@ function calculateAlertThreshold (imtdThresholds, stationStageDatum, stationSubt } module.exports = { - processImtdThresholds + processImtdThresholds, + processThreshold } diff --git a/server/models/views/station.js b/server/models/views/station.js index ba2051761..f7a8107d9 100644 --- a/server/models/views/station.js +++ b/server/models/views/station.js @@ -5,7 +5,7 @@ const Station = require('./station-data') const Forecast = require('./station-forecast') const util = require('../../util') const tz = 'Europe/London' -const { processImtdThresholds } = require('./lib/process-imtd-thresholds') +const { processImtdThresholds, processThreshold } = require('./lib/process-imtd-thresholds') const processWarningThresholds = require('./lib/process-warning-thresholds') const filterImtdThresholds = require('./lib/find-min-threshold') @@ -289,7 +289,7 @@ class ViewModel { } // Retrieve the applicable threshold for chartThreshold - const chartThreshold = [getThresholdByThresholdId(tid, imtdThresholds, thresholds)].filter(Boolean) + const chartThreshold = [getThresholdByThresholdId(tid, imtdThresholds, thresholds, this.station.stageDatum, this.station.subtract, this.station.post_process)].filter(Boolean) // Set chartThreshold property this.chartThreshold = chartThreshold @@ -450,13 +450,14 @@ function telemetryForecastBuilder (telemetryRawData, forecastRawData, stationTyp } // Function to retrieve a threshold by tid or fall back to 'pc5' or 'alertThreshold' -const getThresholdByThresholdId = (tid, imtdThresholds, thresholds) => { +const getThresholdByThresholdId = (tid, imtdThresholds, thresholds, stationStageDatum, stationSubtract, postProcess) => { // Check if a threshold exists based on tid const tidThreshold = tid && imtdThresholds?.find(thresh => thresh.station_threshold_id === tid) if (tidThreshold) { + const thresholdValue = processThreshold(tidThreshold.value, stationStageDatum, stationSubtract, postProcess) return { id: tidThreshold.station_threshold_id, - value: Number(tidThreshold.value).toFixed(2), + value: thresholdValue, description: `${tidThreshold.value}m ${tidThreshold.ta_name || ''}`, shortname: tidThreshold.ta_name || 'Target Area Threshold' }