Warnings
The warnings API lets you read the warning thresholds configured for the assets of the network.
getThreshold()
Section titled “getThreshold()”Returns the warning threshold configured for an asset, or undefined if the asset has no threshold.
Method signature
Section titled “Method signature”type AssetWarningThreshold = { metric: "pressure" | "flow" | "level"; min?: number; max?: number;}
getThreshold(assetId: string): AssetWarningThreshold | undefinedParameters
Section titled “Parameters”assetId: The ID of the asset.
Returns
Section titled “Returns”An AssetWarningThreshold object with:
metric: The metric the threshold applies to:pressure,floworlevel.min: Optional. The minimum value of the metric before a warning is raised.max: Optional. The maximum value of the metric before a warning is raised.
Values use the same units as the asset’s simulation values. See getUnits().
Example
Section titled “Example”Find the junctions whose simulated pressure is below their minimum threshold:
const lowPressureJunctions = sdk.network.getJunctions((junction) => { const threshold = sdk.warnings.getThreshold(junction.id) const pressure = junction.simulation?.pressure
return ( threshold?.metric === "pressure" && threshold.min !== undefined && pressure !== undefined && pressure < threshold.min )})