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:
Or by using the network object in the Plugin SDK
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
Example
Get an asset from Magnetic Island. A tank, in this case:
getAssets()
Returns an array of Asset objects that match the given filter function. If no filter is provided, all assets are returned.
Method signature
Examples
Get all assets in Magnetic Island:
Get all assets in Magnetic Island that are tanks:
Returns an array of assets with IDs Horseshoebay
, Cocklebay
, and 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
getTanks()
Method signature
Returns an array of Tank objects that match the given filter function. If no filter is provided, all tanks are returned.
getPipes()
Returns an array of Pipe objects that match the given filter function. If no filter is provided, all pipes are returned.
Method signature
getPumps()
Returns an array of Pump objects that match the given filter function. If no filter is provided, all pumps are returned.
Method signature
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.
getValves()
Method signature
Returns an array of Valve objects that match the given filter function. If no filter is provided, all valves are returned.
Zone Queries
getZone()
Method signature
Returns a Zone object representing the zone with the given ID, or undefined
if it doesn’t exist.
Example
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
Example
Get all zones in the network:
Get zones with ID Arcadia DMA
or 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
isSimulationLoading()
Returns true
if the simulation is still loading, or false
if it has finished loading.
Method signature
isSimulationPeriodCompleted()
Returns true
if the current simulation period has finished, or false
if it hasn’t.
Method signature
isSimulationError()
Returns true
if there was an error during the simulation, or false
if there wasn’t.
Method signature
getMetadata()
Returns an object with the network metadata:
Method signature
getUnits()
Returns a Units object with the units used in the network.
getBounds()
Returns the bounds of the network.
Method signature
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
getStartTime()
Returns a Time object representing the start time of the simulation.
Method signature
getNeighborAssets()
Returns an array of all the assets that are directly connected to the asset with the given ID.
Method signature
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):
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
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
:
To retrieve all the valves that are reachable from the “Horseshoebay” tank in Magnetic Island:
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
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.
Find the path with the widest diameter pipes between the “Nellybay” and the “Cocklebay” tanks in Magnetic Island:
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).:
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
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.
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
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.
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
Provided startDate
will be automatically adjusted depending on the network configuration.
Example
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
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
.