Skip to content

Commit

Permalink
FSR-1295: Add logic to show correct value on chart for stations with …
Browse files Browse the repository at this point in the history
…stageDatum (#863)
  • Loading branch information
Keyurx11 authored Oct 22, 2024
1 parent e985dec commit c5f25f1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion server/models/views/lib/process-imtd-thresholds.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,6 @@ function calculateAlertThreshold (imtdThresholds, stationStageDatum, stationSubt
}

module.exports = {
processImtdThresholds
processImtdThresholds,
processThreshold
}
9 changes: 5 additions & 4 deletions server/models/views/station.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
}
Expand Down

0 comments on commit c5f25f1

Please sign in to comment.