Skip to content

Commit

Permalink
FSR-1237: Update logic to exclude Welsh station with no data
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyurx11 committed Aug 16, 2024
1 parent 1b358aa commit 637a906
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions server/models/views/lib/latest-levels.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const { formatElapsedTime } = require('../../../util')

const WARNING_THRESHOLD_TYPES = ['FW RES FW', 'FW ACT FW', 'FW ACTCON FW']
const EXCLUDED_STATUSES = ['ukcmf', 'Closed']

function getThresholdsForTargetArea (thresholds) {
const filteredThresholds = thresholds.filter(threshold => !EXCLUDED_STATUSES.includes(threshold.status))
const filteredThresholds = thresholds.filter(threshold =>
threshold.status !== 'Closed' && !(threshold.iswales && threshold.latest_level === null)
)

const warningThresholds = findPrioritizedThresholds(filteredThresholds, WARNING_THRESHOLD_TYPES)
return warningThresholds.map(formatThresholdTimestamp)
}
Expand Down
12 changes: 6 additions & 6 deletions test/models/lib/latest-levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ lab.experiment('getThresholdsForTargetArea', () => {
expect(result[0].formatted_time).to.equal('More than 2 hours ago')
})

lab.test('should exclude thresholds with status ukcmf or closed', () => {
lab.test('should exclude thresholds with status Closed', () => {
const thresholds = [
{ rloi_id: 1, threshold_type: 'FW RES FW', status: 'ukcmf', value_timestamp: '2024-08-12T11:45:00.000Z' },
{ rloi_id: 1, threshold_type: 'FW RES FW', status: 'Closed', value_timestamp: '2024-08-12T11:45:00.000Z' },
{ rloi_id: 2, threshold_type: 'FW RES FW', status: 'Active', value_timestamp: '2024-08-12T10:45:00.000Z' }
]

Expand All @@ -74,16 +74,16 @@ lab.experiment('getThresholdsForTargetArea', () => {
expect(result[0].formatted_time).to.equal('More than 2 hours ago')
})

lab.test('should exclude thresholds with status Closed', () => {
lab.test('should exclude Welsh stations with no data', () => {
const thresholds = [
{ rloi_id: 1, threshold_type: 'FW RES FW', status: 'ukcmf', value_timestamp: '2024-08-12T11:45:00.000Z' },
{ rloi_id: 2, threshold_type: 'FW RES FW', status: 'Active', value_timestamp: '2024-08-12T10:45:00.000Z' }
{ rloi_id: 1, threshold_type: 'FW RES FW', status: 'Active', iswales: true, latest_level: null, value_timestamp: '2024-08-12T11:45:00.000Z' },
{ rloi_id: 2, threshold_type: 'FW RES FW', status: 'Active', iswales: false, latest_level: '0.5', value_timestamp: '2024-08-12T10:45:00.000Z' }
]

const result = getThresholdsForTargetArea(thresholds)

expect(result).to.have.length(1)
expect(result[0].status).to.equal('Active')
expect(result[0].rloi_id).to.equal(2)
expect(result[0].formatted_time).to.equal('More than 2 hours ago')
})

Expand Down

0 comments on commit 637a906

Please sign in to comment.