Skip to content
We're currently creating a lot of content. Sign up to get notified when it's ready.

Network

The network API gives you access to all assets in a network, along with their readings and other metadata. Many extensions make use of it, so it’s a great starting point to get familiar with Qatium’s SDK.

Accessing the network

At the moment, you can only operate on the currently loaded network. Once it is loaded, you can access it by using the window.qatium.network object in your browser console:

const sdk = window.qatium
const network = sdk.network

Or by using the network object in the Plugin SDK

import type { SDK } from '@qatium/sdk'
import type { Plugin } from '@qatium/sdk/plugin'
class MyPlugin implements Plugin {
run() {
const network = sdk.network;
}
}

In the following sections, we will refer to the Network object as network without the window.qatium prefix.

Asset Queries

getAsset()

Returns an Asset object representing the asset with the given ID, or undefined if it doesn’t exist.

Method signature

getAsset<T extends Asset = Asset>(assetId: string) : T | undefined

Example

Get an asset from Magnetic Island. A tank, in this case:

const tank = network.getAsset<Tank>('Horseshoebay')

getAssets()

Returns an array of Asset objects that match the given filter function. If no filter is provided, all assets are returned.

Method signature

getAssets(filter?: function) : Asset[]

Examples

Get all assets in Magnetic Island:

const allAssets = network.getAssets()

Get all assets in Magnetic Island that are tanks:

const tanks = network.getAssets((asset) => asset.type === 'Tank')

Returns an array of assets with IDs Horseshoebay, Cocklebay, and Nellybay:

[
{
"id": "Horseshoebay",
...
},
{
"id": "Cocklebay",
...
},
{
"id": "Nellybay",
...
}
]

For your convenience, the following methods return an array of specific types of assets:

getJunctions()

Returns an array of Junction objects that match the given filter function. If no filter is provided, all junctions are returned.

Method signature

getJunctions(filter?: function) : Junction[]

getTanks()

Method signature

Returns an array of Tank objects that match the given filter function. If no filter is provided, all tanks are returned.

getTanks(filter?: function) : Tank[]

getPipes()

Returns an array of Pipe objects that match the given filter function. If no filter is provided, all pipes are returned.

Method signature

getPipes(filter?: function) : Pipe[]

getPumps()

Returns an array of Pump objects that match the given filter function. If no filter is provided, all pumps are returned.

Method signature

getPumps(filter?: function) : Pump[]

getSupplySources()

Method signature

Returns an array of SupplySource objects that match the given filter function. If no filter is provided, all supply sources are returned.

getSupplySource(filter?: function) : SupplySource[]

getValves()

Method signature

Returns an array of Valve objects that match the given filter function. If no filter is provided, all valves are returned.

getValves(filter?: function) : Valve[]

Zone Queries

getZone()

Method signature

Returns a Zone object representing the zone with the given ID, or undefined if it doesn’t exist.

getZone(zoneId: string) : Zone | undefined

Example

const zone = network.getZone('Z1')

getZones()

Returns an array of Zone objects that match the given filter function. If no filter is provided, all zones are returned. If no zones are defined in the network, an empty array is returned.

Method signature

getZones(filter?: function) : Zone[]

Example

Get all zones in the network:

const allZones = network.getZones()

Get zones with ID Arcadia DMA or Horseshoe Bay DMA:

const zones = sdk.network.getZones(
(zone) => zone.id === 'Arcadia DMA' || zone.id === 'Horseshoe Bay DMA'
)

Network Queries

isScenarioActive()

Returns true if a network version scenario is active, or false if the base network version is active.

Method signature

isScenarioActive(): boolean

isSimulationLoading()

Returns true if the simulation is still loading, or false if it has finished loading.

Method signature

isSimulationLoading(): boolean

isSimulationPeriodCompleted()

Returns true if the current simulation period has finished, or false if it hasn’t.

Method signature

isSimulationPeriodCompleted(): boolean

isSimulationError()

Returns true if there was an error during the simulation, or false if there wasn’t.

Method signature

isSimulationError(): boolean

getMetadata()

Returns an object with the network metadata:

{
"name": "Magnetic Island",
"id": "af70f5d8-7902-4803-8b49-3cfa50a9823e"
}

Method signature

getMetadata(): NetworkMetadata

getUnits()

Returns a Units object with the units used in the network.

getBounds()

Returns the bounds of the network.

type Bounds = {
ne: { lng: number; lat: number };
sw: { lng: number; lat: number };
};

Method signature

getBounds(): Bounds

getTime()

Returns a Time object representing the current time in the simulation. The timezone property is the timezone of the actual network, so for Magnetic Island, it’s Australia/Brisbane.

Method signature

getTime(): Time

getStartTime()

Returns a Time object representing the start time of the simulation.

Method signature

getStartTime(): Time

getNeighborAssets()

Returns an array of all the assets that are directly connected to the asset with the given ID.

Method signature

getNeighborAssets(assetId: string) : Asset[]

If you want to filter the returned assets, it’s better to use the getConnectedAssets method.

For example, in Magnetic Island, if you call the getNeighborAssets method on the “Nellybay” tank, you will get an array of all the pipes that are connected to it (5 in this case):

const neighborAssets = network.getNeighborAssets('Nellybay')
console.log(neighborAssets.length) // 5

getConnectedAssets()

Returns an array of assets that are connected (i.e: can be reached traversing the network) to the given assets, and satisfy the given stop condition. The original assets are returned as well.

Method signature

getConnectedAssets(startIds: string[], stopCondition: function) : Asset[]

The stopCondition function is called for each asset that is connected to the assets with the given IDs. If the function returns true, the method will stop traversing the network and any subsequent assets will not be returned. If the function returns false, the method will continue traversing the network.

Examples

You can list all the assets that are reachable from an asset using a stopCondition function that always return false:

const reachableAssets = network.getConnectedAssets(['Nellybay'], () => false)
console.log(reachableAssets.length) // 3179

To retrieve all the valves that are reachable from the “Horseshoebay” tank in Magnetic Island:

const connectedAssets = network.getConnectedAssets(
['Horseshoebay'],
(asset) => {
return asset.type === 'Valve'
}
)

getShortestPath()

Returns the shortest path between the given assets, and satisfies the given stop condition. The shortest path is the one that has the highest amount of connection weight.

Method signature

getShortestPath(fromId: string, toAsset: function, connectionWeight: function) : Asset[]
getShortestPath(fromId: string, toAsset: function, connectionWeight: function) : Asset[]

The toAsset function is called for each asset in the network. If the function returns true, the method will stop traversing the network and any subsequent assets will not be returned.

The connectionWeight function is called for each possible connection, with two parameters: the current asset that is being traversed, and the asset that is being evaluated. It should return a number representing the weight of the connection. If multiple connections are possible, higher weights are preferred. If the function returns the same number, the connection with the lowest ID is preferred. See the examples below for more details.

Example

To retrieve the shortest path between the “Nellybay” and the “Cocklebay” tanks in Magnetic Island. The weight of all connections is 1, so the path is the shortest.

const path = network.getShortestPath(
'Nellybay',
(asset) => asset.id === 'Cocklebay',
(start, end) => 1
)

Find the path with the widest diameter pipes between the “Nellybay” and the “Cocklebay” tanks in Magnetic Island:

const widerPath = network.getShortestPath(
'Nellybay',
(asset) => asset.id === 'Cocklebay',
(start, end) => {
return asset1.diameter > asset2.diameter
}
)

Find the path with the thinest diameter pipes between the “Nellybay” and the “Cocklebay” tanks in Magnetic Island. Note that this path is shorter than the previous one (37 vs 233 nodes).:

const thinnestPath = network.getShortestPath(
'Nellybay',
(asset) => asset.id === 'Cocklebay',
(asset1, asset2) => {
return asset1.diameter < asset2.diameter
}
)

Network Manipulation

setDemand()

Sets the demand of a junction to the given value. Returns success if the demand was successfully set, or failure if the junction doesn’t exist or the demand could not be set.

Method signature

setDemand(junctionId: string, demand: number, startDate?: Date) : string

Provided startDate will be automatically adjusted depending on the network configuration.

restoreDemand()

Method signature

Restores the demand of a junction to its default value. Returns success if the demand was successfully restored, or failure if the junction doesn’t exist or the demand could not be restored.

restoreDemand(junctionId: string, startDate?: Date) : string

Provided startDate will be automatically adjusted depending on the network configuration.

setJunctionPressure()

Sets the residual pressure of a junction to the given value. Returns success if the residual pressure was successfully set, or failure if the junction doesn’t exist or the residual pressure could not be set.

Method signature

setJunctionPressure(junctionId: string, pressure: number, startDate?: Date) : string

Provided startDate will be automatically adjusted depending on the network configuration.

restoreJunctionPressure()

Method signature

Restores the residual pressure of a junction to its default value. Returns success if the residual pressure was successfully restored, or failure if the junction doesn’t exist or the residual pressure could not be restored.

restoreJunctionPressure(junctionId: string, startDate?: Date) : string

Provided startDate will be automatically adjusted depending on the network configuration.

setSetting()

Sets the setting of a valve (the loss coefficient, in this case) to the given value. Returns success if the setting was successfully set, or failure if the valve doesn’t exist or the setting could not be set.

Method signature

setSetting(valveId: string, setting: number, startDate?: Date) : string

Provided startDate will be automatically adjusted depending on the network configuration.

Example

network.setSetting('V_29279191', 0.5)

setStatus()

Sets the status of an asset to the given value. Returns success if the status was successfully set, or failure if the asset doesn’t exist or the status could not be set.

Method signature

setStatus(assetId: string, status: PipeStatus | PumpStatus | ValveStatus, startDate?: Date) : string

The different values for status are:

  • For Pipes:
    • OPEN
    • CLOSED
  • For Pumps:
    • OPEN
    • CLOSED
  • For Valves:
    • OPEN
    • CLOSED
    • ACTIVE

Provided startDate will be automatically adjusted depending on the network configuration.

setTime()

Sets the network date and time to the non localized provided time.

Method signature

setTime(time: Date) : void

Example

network.setTime(new Date("2024-06-12T16:00:00Z" ))