-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into feature/FSR-1294-Station-Chart-Label-…
…Wrapping
- Loading branch information
Showing
52 changed files
with
1,006 additions
and
423 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,82 @@ | ||
function processThreshold (threshold, stationStageDatum, stationSubtract, postProcess) { | ||
if (threshold) { | ||
if (postProcess) { | ||
if (stationStageDatum > 0) { | ||
threshold = threshold - stationStageDatum | ||
} else if (stationStageDatum <= 0 && stationSubtract > 0) { | ||
threshold = threshold - stationSubtract | ||
} else { | ||
return parseFloat(threshold).toFixed(2) | ||
} | ||
} | ||
return parseFloat(threshold).toFixed(2) | ||
} | ||
return null | ||
} | ||
const processThreshold = require('./process-threshold') | ||
|
||
function processImtdThresholds (imtdThresholds, stationStageDatum, stationSubtract, postProcess) { | ||
const TOP_OF_NORMAL_RANGE = 'Top of normal range' | ||
|
||
function processImtdThresholds (imtdThresholds, stationStageDatum, stationSubtract, postProcess, pc5) { | ||
const thresholds = [] | ||
|
||
const imtdThresholdWarning = processThreshold(imtdThresholds?.warning, stationStageDatum, stationSubtract, postProcess) | ||
const imtdThresholdWarning = calculateWarningThreshold(imtdThresholds, stationStageDatum, stationSubtract, postProcess) | ||
const imtdThresholdAlert = calculateAlertThreshold(imtdThresholds, stationStageDatum, stationSubtract, postProcess, pc5) | ||
|
||
if (imtdThresholdWarning) { | ||
// Correct threshold value if value > zero (Above Ordnance Datum) [FSR-595] | ||
thresholds.push(imtdThresholdWarning) | ||
} | ||
|
||
if (imtdThresholdAlert.length > 0) { | ||
for (const alert of imtdThresholdAlert) { | ||
thresholds.push(alert) | ||
} | ||
} else if (pc5) { | ||
thresholds.push({ | ||
id: 'pc5', | ||
description: 'Top of normal range. Low lying land flooding possible above this level', | ||
shortname: TOP_OF_NORMAL_RANGE, | ||
value: pc5 | ||
}) | ||
} else { return thresholds } | ||
|
||
return thresholds | ||
} | ||
|
||
function calculateWarningThreshold (imtdThresholds, stationStageDatum, stationSubtract, postProcess) { | ||
const imtdThresholdWarning = processThreshold(imtdThresholds?.warning?.value, stationStageDatum, stationSubtract, postProcess) | ||
|
||
if (imtdThresholdWarning) { | ||
return { | ||
id: 'warningThreshold', | ||
description: 'Property flooding is possible above this level. One or more flood warnings may be issued', | ||
description: 'Property flooding is possible above this level', | ||
shortname: 'Possible flood warnings', | ||
value: imtdThresholdWarning | ||
}) | ||
} | ||
} | ||
|
||
return null | ||
} | ||
|
||
function calculateAlertThreshold (imtdThresholds, stationStageDatum, stationSubtract, postProcess, pc5) { | ||
const imtdThresholdAlert = processThreshold(imtdThresholds?.alert, stationStageDatum, stationSubtract, postProcess) | ||
const imtdThresholdAlerts = [] | ||
if (imtdThresholdAlert) { | ||
thresholds.push({ | ||
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: imtdThresholdAlert | ||
}) | ||
// First condition: if imtdThresholdAlert is not equal to Top of Normal Range (pc5) | ||
if (Number(imtdThresholdAlert) !== Number(pc5)) { | ||
imtdThresholdAlerts.push({ | ||
id: 'alertThreshold', | ||
description: 'Low lying land flooding possible above this level. One or more flood alerts may be issued', | ||
shortname: 'Possible flood alerts', | ||
value: imtdThresholdAlert | ||
}) | ||
} | ||
// Second condition: if imtdThresholdAlert is equal to Top of Normal Range (pc5) | ||
if (Number(imtdThresholdAlert) === Number(pc5)) { | ||
imtdThresholdAlerts.push({ | ||
id: 'alertThreshold', | ||
description: 'Top of normal range. Low lying land flooding possible above this level. One or more flood alerts may be issued', | ||
shortname: TOP_OF_NORMAL_RANGE, | ||
value: imtdThresholdAlert | ||
}) | ||
} else if (Number(pc5)) { | ||
imtdThresholdAlerts.push({ | ||
id: 'pc5', | ||
description: TOP_OF_NORMAL_RANGE, | ||
shortname: TOP_OF_NORMAL_RANGE, | ||
value: parseFloat(Number(pc5)).toFixed(2) | ||
}) | ||
} else { | ||
return imtdThresholdAlerts | ||
} | ||
} | ||
return thresholds | ||
|
||
return imtdThresholdAlerts | ||
} | ||
|
||
module.exports = processImtdThresholds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const processThreshold = (threshold, stationStageDatum, stationSubtract, postProcess) => { | ||
if (threshold) { | ||
if (postProcess) { | ||
if (stationStageDatum > 0) { | ||
threshold = threshold - stationStageDatum | ||
} else if (stationStageDatum <= 0 && stationSubtract > 0) { | ||
threshold = threshold - stationSubtract | ||
} else { | ||
return parseFloat(threshold).toFixed(2) | ||
} | ||
} | ||
return parseFloat(threshold).toFixed(2) | ||
} | ||
return null | ||
} | ||
|
||
module.exports = processThreshold |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const processThreshold = require('./process-threshold') | ||
|
||
const FLOOD_WARNING_THRESHOLD = 2 | ||
const SEVERE_FLOOD_WARNING_THRESHOLD = 3 | ||
function filterThresholdsBySeverity (thresholds) { | ||
return thresholds.filter(item => | ||
item.fwis_type === 'W' && | ||
item.severity_value !== null && | ||
(item.severity_value === FLOOD_WARNING_THRESHOLD || item.severity_value === SEVERE_FLOOD_WARNING_THRESHOLD) | ||
) | ||
} | ||
|
||
function getMaxForEachFwisCode (thresholds) { | ||
const maxValuesByFwisCode = {} | ||
|
||
thresholds.forEach(threshold => { | ||
const fwisCode = threshold.fwis_code | ||
const severityValue = threshold.severity_value | ||
const thresholdValue = threshold.value | ||
|
||
// Check if there's already a threshold for this fwis_code | ||
if (!maxValuesByFwisCode[fwisCode]) { | ||
// If it's the first threshold for this fwis_code, store it | ||
maxValuesByFwisCode[fwisCode] = threshold | ||
} else { | ||
const currentMax = maxValuesByFwisCode[fwisCode] | ||
|
||
// Compare based on severity_value first, or if severity_value is the same, compare based on the threshold value | ||
if (severityValue > currentMax.severity_value || | ||
(severityValue === currentMax.severity_value && parseFloat(thresholdValue) > parseFloat(currentMax.value))) { | ||
maxValuesByFwisCode[fwisCode] = threshold | ||
} | ||
} | ||
}) | ||
|
||
return Object.values(maxValuesByFwisCode) | ||
} | ||
|
||
function createWarningObject (threshold, stationStageDatum, stationSubtract, postProcess) { | ||
const warningType = | ||
threshold.severity_value === SEVERE_FLOOD_WARNING_THRESHOLD | ||
? 'Severe flood warning' | ||
: 'Flood warning' | ||
|
||
const imtdThresholdWarning = processThreshold(parseFloat(threshold.threshold_value).toFixed(2), stationStageDatum, stationSubtract, postProcess) | ||
|
||
return { | ||
id: 'warningThreshold', | ||
description: `${warningType} issued: <a href="/target-area/${threshold.fwis_code}">${threshold.ta_name}</a>`, | ||
shortname: `${threshold.ta_name}`, | ||
value: imtdThresholdWarning | ||
} | ||
} | ||
function processWarningThresholds (imtdThresholds, stationStageDatum, stationSubtract, postProcess) { | ||
const filteredThresholds = filterThresholdsBySeverity(imtdThresholds) | ||
const maxThresholdsByFwisCode = getMaxForEachFwisCode(filteredThresholds) | ||
|
||
const warningObjects = maxThresholdsByFwisCode.map(threshold => | ||
createWarningObject(threshold, stationStageDatum, stationSubtract, postProcess) | ||
) | ||
|
||
return warningObjects | ||
} | ||
|
||
module.exports = processWarningThresholds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.