Web Objects (Complex Models)¶
-
class
hydra_server.server.complexmodels.
Attr
(parent=None)¶ id Integer(default=None)
name Unicode(default=None)
dimension_id Unicode(default=None)
description Unicode(default=None)
cr_date Unicode(default=None)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
AttrGroup
(parent=None)¶ id Integer(default=None)
project_id Integer(default=None)
name Unicode(default=None)
layout AnyDict(min_occurs=0, max_occurs=1, default=None))
description Unicode(default=None)
exclusive Unicode(min_occurs=0, default=’N’)
cr_date Unicode(default=None)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
AttrGroupItem
(parent=None)¶ group_id Integer(default=None)
attr_id Integer(default=None)
network_id Integer(default=None)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
AttributeData
(*args, **kwargs)¶ A class which is returned by the server when a request is made for the data associated with an attribute.
resourceattrs SpyneArray(ResourceAttr)
resourcescenarios SpyneArray(ResourceScenario)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
Dataset
(parent=None, include_metadata=True)¶ id Integer(min_occurs=0, default=None)
type Unicode
dimension Unicode(min_occurs=1, default=’dimensionless’)
unit Unicode(min_occurs=1, default=None)
name Unicode(min_occurs=1, default=None)
value Unicode(min_occurs=1, default=None)
hidden Unicode(min_occurs=0, default=’N pattern=”[YN]”)
created_by Integer(min_occurs=0, default=None)
cr_date Unicode(min_occurs=0, default=None)
metadata Unicode(min_occurs=0, default=’{}’)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
DatasetCollection
(parent=None)¶ name Unicode(default=None)
id Integer(default=None)
dataset_ids SpyneArray(Integer)
cr_date Unicode(default=None)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
DatasetOwner
(parent=None)¶ dataset_id Integer
user_id Integer
edit Unicode
view Unicode)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
Dimension
(parent=None)¶ A dimension, with name and units
id Integer
name Unicode
units SpyneArray(Unicode)
description Unicode
project_id Integer
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
HydraComplexModel
(*args, **kwargs)¶ This is the superclass from which most hydra complex models inherit. It contains the namespace ‘server.complexmodels’, which all hydra complex models need.
-
class
Attributes
¶
-
class
-
class
hydra_server.server.complexmodels.
Link
(parent=None, summary=False)¶ id Integer(default=None)
name Unicode(default=None)
description Unicode(min_occurs=1, default=”“)
layout AnyDict(min_occurs=0, max_occurs=1, default=None)
node_1_id Integer(default=None)
node_2_id Integer(default=None))
status Unicode(default=’A** pattern=”[AX]”)
attributes SpyneArray(ResourceAttr)
types SpyneArray(TypeSummary)
cr_date Unicode(default=None)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
Network
(parent=None, summary=False)¶ project_id Integer(default=None)
id Integer(default=None)
name Unicode(default=None)
description Unicode(min_occurs=1, default=None)
created_by Integer(default=None)
cr_date Unicode(default=None)
layout AnyDict(min_occurs=0, max_occurs=1, default=None)
status Unicode(default=’A’)
attributes SpyneArray(ResourceAttr)
scenarios SpyneArray(Scenario)
nodes SpyneArray(Node)
links SpyneArray(Link)
resourcegroups SpyneArray(ResourceGroup)
types SpyneArray(TypeSummary)
projection Unicode(default=None)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
NetworkExtents
(parent=None)¶ network_id Integer(default=None)
min_x Decimal(default=0)
min_y Decimal(default=0)
max_x Decimal(default=0)
max_y Decimal(default=0)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
NetworkOwner
(parent=None)¶ network_id Integer
user_id Integer
edit Unicode
view Unicode)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
Node
(parent=None, summary=False)¶ id Integer(default=None)
name Unicode(default=None)
description Unicode(min_occurs=1, default=”“)
layout AnyDict(min_occurs=0, max_occurs=1, default=None)
x Double(min_occurs=1, default=0)
y Double(min_occurs=1, default=0)
status Unicode(default=’A** pattern=”[AX]”)
attributes SpyneArray(ResourceAttr)
types SpyneArray(TypeSummary)
cr_date Unicode(default=None)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
Note
(parent=None)¶ id Integer
ref_key Unicode
ref_id Integer
value Unicode
created_by Integer
cr_date Unicode
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
Perm
(parent=None)¶ id Integer
name Unicode
code Unicode
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
Plugin
(parent=None)¶ name Unicode
location Unicode
params SpyneArray(PluginParam)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
PluginParam
(parent=None)¶ name Unicode
value Unicode
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
Project
(parent=None)¶ id Integer(default=None)
name Unicode(default=None)
description Unicode(default=None)
status Unicode(default=’A’)
cr_date Unicode(default=None)
created_by Integer(default=None)
attributes SpyneArray(ResourceAttr)
attribute_data SpyneArray(ResourceScenario)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
ProjectOwner
(parent=None)¶ project_id Integer
user_id Integer
edit Unicode
view Unicode)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
ProjectSummary
(parent=None)¶ id Integer(default=None)
name Unicode(default=None)
description Unicode(default=None)
status Unicode(default=None)
cr_date Unicode(default=None)
created_by Integer(default=None)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
Resource
(*args, **kwargs)¶ - Superclass for anything which has a layout field:
nodes
links
network
scenario
project
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
ResourceAttr
(parent=None)¶ id Integer(min_occurs=0, default=None)
attr_id Integer(default=None)
ref_id Integer(min_occurs=0, default=None)
ref_key Unicode(min_occurs=0, default=None)
attr_is_var Unicode(min_occurs=0, default=’N’)
resourcescenario ResourceScenario
cr_date Unicode(default=None)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
ResourceAttrMap
(parent=None)¶ resource_attr_id_a Integer(default=None)
resource_attr_id_b Integer(default=None)
attr_a_name Unicode(default=None)
attr_b_name Unicode(default=None)
ref_key_a Unicode(default=None)
ref_key_b Unicode(default=None)
ref_id_a Integer(default=None)
ref_id_b Integer(default=None)
resource_a_name Unicode(default=None)
resource_b_name Unicode(default=None)
network_a_id Integer(default=None)
network_b_id Integer(default=None)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
ResourceData
(resourceattr=None, include_value='N')¶ An object which represents a resource attr, resource scenario and dataset all in one.
attr_id: The ID of the attribute to which this data belongs
scenario_id: The ID of the scenario in which this data has been assigned
resource_attr_id: The unique ID representing the attribute and resource combination
ref_key: Indentifies the type of resource to which this dataset is attached. Can be ‘NODE’, ‘LINK’, ‘GROUP’, ‘NETWORK’ or ‘PROJECT’
ref_id: The ID of the node, link, group, network, or project in question
attr_is_var: Flag to indicate whether this resource’s attribute is a variable and hence should be filled in by a model
dataset_id: The ID of the dataset which has been assigned to the resource attribute
dataset_type: The type of the dataset – can be scalar, descriptor, array or timeseries
dataset_dimension: The dimension of the dataset (This MUST match the dimension of the attribute)
dataset_unit: The unit of the dataset.
dataset_name: The name of the dataset. Most likely used for distinguishing similar datasets or searching for datasets
dataset_hidden: Indicates whether the dataset is hidden, in which case only authorised users can use the dataset.
dataset_metadata:: A dictionary of the metadata associated with the dataset. For example: {‘created_by’: “User 1”, “source”:”Import from CSV”}
- dataset_value:
Depending on what the dataset_type is, this can be a decimal value, a freeform string or a JSON string. For a timeseries for example, the datasset_value looks like:
'{ "H1" : { "2014/09/04 16:46:12:00":1, "2014/09/05 16:46:12:00":2, "2014/09/06 16:46:12:00":3, "2014/09/07 16:46:12:00":4}, "H2" : { "2014/09/04 16:46:12:00":10, "2014/09/05 16:46:12:00":20, "2014/09/06 16:46:12:00":30, "2014/09/07 16:46:12:00":40}, "H3" : { "2014/09/04 16:46:12:00":100, "2014/09/05 16:46:12:00":200, "2014/09/06 16:46:12:00":300, "2014/09/07 16:46:12:00":400} }'
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
ResourceGroup
(parent=None, summary=False)¶ id Integer(default=None)
network_id Integer(default=None)
name Unicode(default=None)
description Unicode(min_occurs=1, default=”“)
status Unicode(default=’A** pattern=”[AX]”)
attributes SpyneArray(ResourceAttr)
types SpyneArray(TypeSummary)
cr_date Unicode(default=None)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
ResourceGroupDiff
(parent=None)¶ scenario_1_items SpyneArray(ResourceGroupItem)
scenario_2_items SpyneArray(ResourceGroupItem))
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
ResourceGroupItem
(parent=None)¶ id Integer(default=None)
ref_id Integer(default=None)
ref_key Unicode(default=None)
group_id Integer(default=None)
cr_date Unicode(default=None)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
ResourceScenario
(parent=None, attr_id=None)¶ resource_attr_id Integer(default=None)
attr_id Integer(default=None)
dataset_id Integer(default=None)
value Dataset
source Unicode
cr_date Unicode(default=None)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
ResourceScenarioDiff
(parent=None)¶ resource_attr_id Integer(default=None)
scenario_1_dataset Dataset
scenario_2_dataset Dataset
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
ResourceSummary
(parent=None)¶ ref_key Unicode(default=None)
id Integer(default=None)
name Unicode(default=None)
description Unicode(min_occurs=1, default=”“)
attributes SpyneArray(ResourceAttr)),
types SpyneArray(TypeSummary)),
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
ResourceTypeDef
(*args, **kwargs)¶ ref_key Unicode(default=None)
ref_id Integer(default=None)
type_id Integer(default=None)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
Role
(parent=None)¶ id Integer
name Unicode
code Unicode
roleperms SpyneArray(RolePerm)
roleusers SpyneArray(RoleUser)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
Rule
(parent=None)¶ id Integer
name Unicode
description Unicode
scenario_id Integer
ref_key Unicode
ref_id Integer
value Unicode
cr_date Unicode(default=None)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
Scenario
(parent=None, summary=False)¶ id Integer(default=None)
name Unicode(default=None)
description Unicode(min_occurs=1, default=”“)
network_id Integer(default=None)
layout AnyDict(min_occurs=0, max_occurs=1, default=None)
status Unicode(default=’A** pattern=”[AX]”)
locked Unicode(default=’N** pattern=”[YN]”)
start_time Unicode(default=None)
end_time Unicode(default=None)
created_by Integer(default=None)
cr_date Unicode(default=None)
time_step Unicode(default=None)
resourcescenarios SpyneArray(ResourceScenario, default=None)
resourcegroupitems SpyneArray(ResourceGroupItem, default=None)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
ScenarioDiff
(parent=None)¶ resourcescenarios SpyneArray(ResourceScenarioDiff)
groups ResourceGroupDiff
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
Template
(parent=None)¶ id Integer(default=None)
name Unicode(default=None)
layout AnyDict(min_occurs=0, max_occurs=1, default=None)
types SpyneArray(TemplateType)
cr_date Unicode(default=None)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
TemplateType
(parent=None)¶ id Integer(default=None)
name Unicode(default=None)
resource_type Unicode(values=[‘GROUP’, ‘NODE’, ‘LINK’, ‘NETWORK’], default=None)
alias Unicode(default=None)
layout AnyDict(min_occurs=0, max_occurs=1, default=None)
template_id Integer(min_occurs=1, default=None)
typeattrs SpyneArray(TypeAttr)
cr_date Unicode(default=None)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
TypeAttr
(parent=None)¶ attr_id Integer(min_occurs=1, max_occurs=1)
attr_name Unicode(default=None)
type_id Integer(default=None)
data_type Unicode(default=None)
dimension Unicode(default=None)
unit Unicode(default=None)
default_dataset_id Integer(default=None)
data_restriction AnyDict(default=None)
is_var Unicode(default=None)
description Unicode(default=None)
properties AnyDict(default=None)
cr_date Unicode(default=None)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
TypeSummary
(parent=None)¶ name Unicode
id Integer
template_name Unicode
template_id Integer
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
Unit
(parent=None)¶ id Integer
name Unicode
abbr Unicode
abbreviation Unicode
cf Double
lf Double
info Unicode
description Unicode
dimension_id Integer
project_id Integer
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
User
(parent=None)¶ id Integer
username Unicode(default=None)
display_name Unicode(default=None)
password Unicode(default=None)
-
class
Attributes
¶
-
class
hydra_server.server.complexmodels.
ValidationError
(error_text, scenario_id=None, ref_key=None, ref_id=None, ref_name=None, attr_name=None, attr_id=None, template_id=None, type_id=None, resource_attr_id=None, dataset_id=None)¶ scenario_id Integer(default=None)
ref_key Unicode(default=None)
ref_id Integer(default=None)
ref_name Unicode(default=None)
attr_name Unicode(default=None)
attr_id Integer(default=None)
template_id Integer(default=None)
type_id Integer(default=None)
resource_attr_id Integer(default=None)
dataset_id Integer(default=None)
error_text Unicode(default=None)
-
class
Attributes
¶
API functions¶
Projects¶
-
class
hydra_server.server.project.
ProjectService
¶ The project SOAP service
-
static
add_project
(ctx, project)¶ Add a new project
- Args:
project (complexmodels.Project): The new project to be added. The project does not include networks.
- Returns:
complexmodels.Project: The project received, but with an ID this time.
Raises:
-
static
delete_project
(ctx, project_id)¶ Set the status of a project to ‘X’. This does NOT delete the project from the database (which also entails deleting all sub-networks, data etc). For that, use purge_project.
- Args:
project_id (int): The ID of the project to delete.
- Returns:
string: ‘OK’
- Raises:
ResourceNotFoundError: If the Project is not found.
-
static
get_network_project
(ctx, network_id)¶ Get the project of a specified network
- Args:
network_id (int): The ID of the network whose project details you want
- Returns:
complexmodels.Project: The parent project of the specified Network
- Raises:
ResourceNotFoundError: If the Network is not found.
-
static
get_networks
(ctx, project_id, include_data)¶ Get all networks in a project
- Args:
project_id (int): The ID of the project whose networks you want. include_data (string) (‘Y’ or ‘N’): Include data with the networks? Defaults as ‘Y’ but using ‘N’ gives a significant performance boost.
- Returns:
List(complexmodels.Network): All the project’s Networks.
- Raises:
ResourceNotFoundError: If the Project is not found.
-
static
get_project
(ctx, project_id)¶ Get an existing Project
- Args:
project_id (int): The ID of the project to retrieve
- Returns:
complexmodels.Project: The requested project
- Raises:
ResourceNotFoundError: If the project is not found.
-
static
get_project_by_name
(ctx, project_name)¶ If you don’t know the ID of the project in question, but do know the name, use this function to retrieve it.
- Args:
project_name (string): The name of the project to retrieve
- Returns:
complexmodels.Project: The requested project
- Raises:
ResourceNotFoundError: If the project is not found.
-
static
get_projects
(ctx, user_id)¶ Get all the projects belonging to a user.
- Args:
user_id (int): The user ID whose projects you want
- Returns:
List(complexmodels.Project): The requested projects
- Raises:
ResourceNotFoundError: If the User is not found.
-
static
purge_project
(ctx, project_id)¶ Delete a project from the DB completely. WARNING: THIS WILL DELETE ALL THE PROJECT’S NETWORKS AND CANNOT BE REVERSED!
- Args:
project_id (int): The ID of the project to purge.
- Returns:
string: ‘OK’
- Raises:
ResourceNotFoundError: If the Project is not found.
-
static
update_project
(ctx, project)¶ Update a project
- Args:
project (complexmodels.Project): The project to be updated. All the attributes of this project will be used to update the existing project
- Returns:
complexmodels.Project: The updated project
- Raises:
ResourceNotFoundError: If the project is not found.
-
static
Networks (Inc nodes & links)¶
General remarks¶
Generally speaking, a network consists of nodes and links. Each node can be connected to other one or several nodes through one or several links. Each link connects exactly two nodes.
-
class
hydra_server.server.network.
NetworkService
¶ The network SOAP service.
-
static
activate_group
(ctx, group_id)¶ Set the status of a group to ‘A’
- Args:
group_id (int): The resource group to reactivate
- Returns:
string: ‘OK’
- Raises:
ResourceNotFoundError: If the resource group is not found.
-
static
activate_link
(ctx, link_id)¶ Set the status of a link to ‘A’
- Args:
link_id (int): The link to reactivate
- Returns:
string: ‘OK’
- Raises:
ResourceNotFoundError: If the link is not found.
-
static
activate_network
(ctx, network_id)¶ Un-Deletes a network. (Set the status to ‘Y’ meaning it’ll be included when you request a project’s networks.
- Args:
network_id (int): The network to reactivate
- Returns:
string: ‘OK’
- Raises:
ResourceNotFoundError: If the network is not found.
-
static
activate_node
(ctx, node_id)¶ Set the status of a node to ‘A’
Un-Deletes a node. (Set the status to ‘Y’ meaning it’ll be included when you request a network.
- Args:
node_id (int): The node to reactivate
- Returns:
string: ‘OK’
- Raises:
ResourceNotFoundError: If the node is not found.
-
static
add_group
(ctx, network_id, group)¶ Add a resourcegroup to a network
- Args:
network_id (int): The id of the network to receive the new node group (complexmodels.ResourceGroup): The group to be added
- Returns:
complexmodels.ResourceGroup: The newly added group, complete with an ID
- Raises:
ResourceNotFoundError: If the network is not found
-
static
add_link
(ctx, network_id, link)¶ Add a link to a network
- Args:
network_id (int): The id of the network to receive the new link link (complexmodels.Link): The link to be added (see above for the format)
- Returns:
complexmodels.Link: The newly added link, complete with an ID
- Raises:
ResourceNotFoundError: If the network is not found
-
static
add_links
(ctx, network_id, links)¶ Add a lost of links to a network
- Args:
network_id (int): The id of the network to receive the new link link (List(complexmodels.Link)): A list of the links to be added
- Returns:
List(complexmodels.Link): The newly added links, each complete with an ID
- Raises:
ResourceNotFoundError: If the network is not found
-
static
add_network
(ctx, net)¶ Takes an entire network complex model and saves it to the DB. This complex model includes links & scenarios (with resource data). Returns the network’s complex model.
As links connect two nodes using the node_ids, if the nodes are new they will not yet have node_ids. In this case, use negative ids as temporary IDS until the node has been given an permanent ID.
All inter-object referencing of new objects should be done using negative IDs in the client.
The returned object will have positive IDS
- Args:
net (complexmodels.Network): The entire network complex model structure including nodes, links, scenarios and data
- Returns:
complexmodels.Network: The full network structure, with correct IDs for all resources
-
static
add_node
(ctx, network_id, node)¶ Add a node to a network:
(Node){ id = 1027 name = "Node 1" description = "Node Description" x = 0.0 y = 0.0 attributes = (ResourceAttrArray){ ResourceAttr[] = (ResourceAttr){ attr_id = 1234 }, (ResourceAttr){ attr_id = 4321 }, } }
- Args:
network_id (int): The id of the network to receive the new node node (complexmodels.Node): The node to be added (see above for the format)
- Returns:
complexmodels.Node: The newly added node, complete with an ID
- Raises:
ResourceNotFoundError: If the network is not found
-
static
add_nodes
(ctx, network_id, nodes)¶ Add a lost of nodes to a network
- Args:
network_id (int): The id of the network to receive the new node node (List(complexmodels.Node)): A list of the nodes to be added
- Returns:
List(complexmodels.Node): The newly added nodes, each complete with an ID
- Raises:
ResourceNotFoundError: If the network is not found
-
static
clean_up_network
(ctx, network_id)¶ Purge all nodes, links, groups and scenarios from a network which have previously been deleted.
- Args:
network_id (int): The network to clean up
- Returns:
string: ‘OK’
- Raises:
ResourceNotFoundError: If the network is not found
-
static
delete_group
(ctx, group_id)¶ Set the status of a group to ‘X’ Args:
group_id (int): The resource group to delete
- Returns:
string: ‘OK’
- Raises:
ResourceNotFoundError: If the resource group is not found
-
static
delete_link
(ctx, link_id)¶ Set the status of a link to ‘X’
- Args:
link_id (int): The link to delete
- Returns:
string: ‘OK’
- Raises:
ResourceNotFoundError: If the link is not found
-
static
delete_network
(ctx, network_id)¶ Set status of network to ‘X’ so it will no longer appear when you retrieve its project. This will not delete the network from the DB. For that use purge_network
- Args:
network_id (int): The network to delete
- Returns:
string: ‘OK’
- Raises:
ResourceNotFoundError: If the network is not found
-
static
delete_node
(ctx, node_id)¶ Set status of node to ‘X’ so it will no longer appear when you retrieve its network. This will not delete the node from the DB. For that use purge_node
- Args:
node_id (int): The node to delete
- Returns:
string: ‘OK’
- Raises:
ResourceNotFoundError: If the node is not found
-
static
get_all_group_data
(ctx, network_id, scenario_id, group_ids, include_metadata)¶ Return all the attributes for all the groups in a given network and a given scenario. Returns a list of ResourceAttr objects, each with a resourcescenario attribute, containing the actual value for the scenario specified.
- Args:
network_id (int): The network to search in scenario_id (int): The scenario to search group_ids (List(int)) (optional): The specific resource groups to search for data in. If not specified, all the groups in the network will be searched. include_metadata: (string) (‘Y’ or ‘N’): Default ‘N’. Set to ‘Y’ to return metadata. This may vause a performance hit as metadata is BIG!
- Returns:
List(ResourceAttr), each with a resourcescenario attribute, containing the actual value for the scenario specified.
-
static
get_all_link_data
(ctx, network_id, scenario_id, link_ids, include_metadata)¶ Return all the attributes for all the links in a given network and a given scenario. Returns a list of ResourceAttr objects, each with a resourcescenario attribute, containing the actual value for the scenario specified.
- Args:
network_id (int): The network to search in scenario_id (int): The scenario to search link_ids (List(int)) (optional): The specific links to search for data in. If not specified, all the links in the network will be searched. include_metadata: (string) (‘Y’ or ‘N’): Default ‘N’. Set to ‘Y’ to return metadata. This may vause a performance hit as metadata is BIG!
- Returns:
List(ResourceAttr), each with a resourcescenario attribute, containing the actual value for the scenario specified.
- Raises:
ResourceNotFoundError: If the network or scenario are not found
-
static
get_all_node_data
(ctx, network_id, scenario_id, node_ids, include_metadata)¶ Return all the attributes for all the nodes in a given network and a given scenario.
- Args:
network_id (int): The network to search in scenario_id (int): The scenario to search node_ids (List(int)) (optional): The specific nodes to search for data in. If not specified, all the nodes in the network will be searched. include_metadata: (string) (‘Y’ or ‘N’): Default ‘N’. Set to ‘Y’ to return metadata. This may vause a performance hit as metadata is BIG!
- Returns:
List(ResourceAttr), each with a resourcescenario attribute, containing the actual value for the scenario specified.
- Raises:
ResourceNotFoundError: If the network or scenario are not found
-
static
get_all_resource_data
(ctx, scenario_id, include_values, include_metadata, page_start, page_end)¶ Return all the attributes for all the nodes in a given network and a given scenario.
In this function array data and timeseries data are returned as JSON strings.
If your data structure looks like:
H1
H2
H3
1
10
100
2
20
200
3
30
300
4
40
400
Then hydra will provide the data in the following format:
- ‘{
“H1” : {“0”:1, “1”:2, “3”:3, “4”:4},
“H2” : {“0”:10, “1”:20, “3”:30, “4”:40},
“H3” : {“0”:100, “1”:200, “3”:300, “4”:400}
}’
For a timeseries:
Time
H1
H2
H3
2014/09/04 16:46:12:00
1
10
100
2014/09/05 16:46:12:00
2
20
200
2014/09/06 16:46:12:00
3
30
300
2014/09/07 16:46:12:00
4
40
400
Then hydra will provide the data in the following format:
- ‘{
“H1” : {
“2014/09/04 16:46:12:00”:1,
“2014/09/05 16:46:12:00”:2,
“2014/09/06 16:46:12:00”:3,
“2014/09/07 16:46:12:00”:4},
“H2” : {
“2014/09/04 16:46:12:00”:10,
“2014/09/05 16:46:12:00”:20,
“2014/09/06 16:46:12:00”:30,
“2014/09/07 16:46:12:00”:40},
“H3” : {
“2014/09/04 16:46:12:00”:100,
“2014/09/05 16:46:12:00”:200,
“2014/09/06 16:46:12:00”:300,
“2014/09/07 16:46:12:00”:400}
}’
- Args:
scenario_id (int): The scenario to search include_values (string) (‘Y’ or ‘N’): Default ‘N’. Set to ‘Y’ to return the values. This may vause a performance hit as values are BIG! include_metadata: (string) (‘Y’ or ‘N’): Default ‘N’. Set to ‘Y’ to return metadata. This may vause a performance hit as metadata is BIG! page_start (int): The start of the search results (allows you to contol the nuber of results) page_end (int): The end of the search results
- Returns:
List(ResourceData): A list of objects describing datasets specifically designed for efficiency
-
static
get_link
(ctx, link_id, scenario_id)¶ Get a link using the link_id. optionally, scenario_id can be included if data is to be included
- Args:
link_id (int): The link to retrieve scenario_id (int) (optional): Include this if you want to include data with the scenario
- Returns:
complexmodels.Link: A link complex model, with attributes and data if requested)
- Raises:
ResourceNotFoundError: If the link or scenario is not found
-
static
get_network
(ctx, network_id, include_data, template_id, scenario_ids, summary)¶ Return a whole network as a complex model.
- Args:
network_id (int) : The ID of the network to retrieve include_data (char) (‘Y’ or ‘N’): Optional flag to indicate whether to return datasets with the network. Defaults to ‘Y’, but using ‘N’ is much faster. template_id (int) : Optional parameter which will only return attributes on the resources that are in this template. scenario_ids (List(int)) : Optional parameter to indicate which scenarios to return with the network. If left unspecified, all scenarios are returned summary (char) (‘Y’ or ‘N’): Optional flag to indicate whether attributes are returned with the nodes & links. Seting to ‘Y’ has significant speed improvements at the cost of not retrieving attribute information.
- Returns:
complexmodels.Network: A network complex model
- Raises:
ResourceNotFoundError: If the network is not found.
-
static
get_network_as_json
(ctx, network_id)¶ Return a whole network as a json string. Used for testing.
- Args:
network_id (int): The ID of the network to retrieve
- Returns:
string: A json-encoded representation of the network
-
static
get_network_by_name
(ctx, project_id, network_name)¶ Search for a network by its name and return it.
- Args:
project_id (int): As network names are only unique within a project, search for the network within the specified project network_name (string): The name of the network
- Returns:
complexmodels.Network: The entire network structure, no filtering is performed, so all data and attributes are returned
- Raises:
ResourceNotFoundError: If the project or network is not found
-
static
get_network_extents
(ctx, network_id)¶ Given a network, return its maximum extents. This would be the minimum x value of all nodes, the minimum y value of all nodes, the maximum x value of all nodes and maximum y value of all nodes.
- Args:
network_id (int): The network to get the extents for
- Returns:
NetworkExtents: the min x, max x, min y, max y of all nodes in the network
- Raises:
ResourceNotFoundError: If the network is not found.
-
static
get_node
(ctx, node_id, scenario_id)¶ Get a node using the node_id. optionally, scenario_id can be included if data is to be included
- Args:
node_id (int): The node to retrieve scenario_id (int) (optional): Include this if you want to include data with the scenario
- Returns:
complexmodels.Node: A node complex model, with attributes and data if requested)
- Raises:
ResourceNotFoundError: If the node or scenario is not found
-
static
get_resourcegroup
(ctx, group_id, scenario_id)¶ Get a resourcegroup using the group_id. optionally, scenario_id can be included if data is to be included
- Args:
group_id (int): The resource group to retrieve scenario_id (int) (optional): Include this if you want to include data with the scenario
- Returns:
complexmodels.ResourceGroup: A resource group complex model, with attributes and data if requested)
- Raises:
ResourceNotFoundError: If the group or scenario is not found
-
static
get_resources_of_type
(ctx, network_id, type_id)¶ Return a list of Nodes, Links or ResourceGroups which have the specified type.
- Args:
network_id (int): Types of resources in this network type_id (int): Search for resources of this type.
- Returns:
List(ResourceSummary): These objects contain the attributes common to all resources, namely: type, id, name, description, attribues and types.
- Raises:
ResourceNotFoundError: If the network or type is not found
-
static
get_scenarios
(ctx, network_id)¶ Get all the scenarios in a given network.
- Args:
network_id (int): The network from which to retrieve the scenarios
- Returns:
List(complexmodels.Scenario): All the scenarios in the network
- Raises:
ResourceNotFoundError: If the network is not found
-
static
network_exists
(ctx, project_id, network_name)¶ Using a network’s name, check if a network exists or not within a project.
- Args:
project_id (int): The project in which you are searching network_name (string): The name of the network you are searching for
- Returns:
Unicode: ‘Y’ or ‘N’
- Raises:
ResourceNotFoundError: If the project is not defined
-
static
purge_group
(ctx, group_id, purge_data)¶ Remove a resource group from the DB completely. If purge data is set to ‘Y’, any data that is unconnected after the removal of the group will be removed also.
- Args:
group_id (int): The resource group to remove completely purge_data (string) (‘Y’ or ‘N’): Any data left unconnected can be left in the DB or deleted with this flag.
- Returns:
string: ‘OK’
- Raises:
ResourceNotFoundError: If the resource group is not found
-
static
purge_link
(ctx, link_id, purge_data)¶ Remove link from DB completely If there are attributes on the link, use purge_data to try to delete the data. If no other resources link to this data, it will be deleted.
- Args:
link_id (int): The link to reactivate
- Returns:
string: ‘OK’
- Raises:
ResourceNotFoundError: If the link is not found.
-
static
purge_network
(ctx, network_id, purge_data)¶ Remove a network from hydra platform completely.
- Args:
network_id (int): The network to remove completely purge_data (string) (‘Y’ or ‘N’): Any data left unconnected can be left in the DB or deleted with this flag.
- Returns:
string: ‘OK’
- Raises:
ResourceNotFoundError: If the network is not found
-
static
purge_node
(ctx, node_id, purge_data)¶ Remove node from DB completely If there are attributes on the node, use purge_data to try to delete the data. If no other resources link to this data, it will be deleted.
- Args:
node_id (int): The node to remove completely purge_data (string) (‘Y’ or ‘N’): Any data left unconnected can be left in the DB or deleted with this flag.
- Returns:
string: ‘OK’
- Raises:
ResourceNotFoundError: If the node is not found
-
static
update_link
(ctx, link)¶ Update a link.
- Args:
link (complexmodels.Link): The link to be updated
- Returns:
complexmodels.Link: The updated link.
- Raises:
ResourceNotFoundError: If the link is not found
-
static
update_network
(ctx, net, update_nodes, update_links, update_groups, update_scenarios)¶ Update an entire network. Send a network complex model with updated nodes, links, groups or scenarios. Using flags, tell the function which of these to update.
- Args:
net (complexmodels.Network): A network reflecting an already existing network (must have an ID), which is to be updated updated_nodes (char) (Y or N): Flag to indicated whether the incoming network’s nodes should be updated updated_links (char) (Y or N): Flag to indicated whether the incoming network’s links should be updated updated_groups (char) (Y or N): Flag to indicated whether the incoming network’s resource groups should be updated updated_scenarios (char) (Y or N): Flag to indicated whether the incoming network’s data should be updated
- Returns:
complexmodels.Network: The updated network, in summarised forms (without data or attributes)
- Raises:
ResourceNotFoundError: If the network does not exist.
-
static
update_node
(ctx, node)¶ Update a node. If new attributes are present, they will be added to the node. The non-presence of attributes does not remove them.
(Node){ id = 1039 name = "Node 1" description = "Node Description" x = 0.0 y = 0.0 status = "A" attributes = (ResourceAttrArray){ ResourceAttr[] = (ResourceAttr){ id = 850 attr_id = 1038 ref_id = 1039 ref_key = "NODE" attr_is_var = True }, (ResourceAttr){ id = 852 attr_id = 1040 ref_id = 1039 ref_key = "NODE" attr_is_var = True }, } }
- Args:
node (complexmodels.Node): The node to be updated
- Returns:
complexmodels.Node: The updated node.
- Raises:
ResourceNotFoundError: If the node is not found
-
static
validate_network_topology
(ctx, network_id)¶ Check for the presence of orphan nodes in a network. Args:
network_id (int): The network to check
- Returns:
List(int)): IDs of all the orphan nodes in the network
- Raises:
ResourceNotFoundError: If the network is not found
-
static
Attributes¶
-
class
hydra_server.server.attributes.
AttributeGroupService
¶ -
static
add_attribute_group
(ctx, attributegroup)¶ Add a new attribute group.
An attribute group is a container for attributes which need to be grouped in some logical way. For example, if the ‘attr_is_var’ flag isn’t expressive enough to delineate different groupings.
- an attribute group looks like:
- {
‘project_id’ : XXX, ‘name’ : ‘my group name’ ‘description : ‘my group description’ (optional) ‘layout’ : ‘my group layout’ (optional) ‘exclusive’ : ‘N’ (or ‘Y’ ) (optional, default to ‘N’)
}
-
static
add_attribute_group_items
(ctx, attributegroupitems)¶ Populate attribute groups with items. ** attributegroupitems : a list of items, of the form:
Note that this approach supports the possibility of populating groups within multiple networks at the same time.
When adding a group item, the function checks whether it can be added, based on the ‘exclusivity’ setup of the groups – if a group is specified as being ‘exclusive’, then any attributes within that group cannot appear in any other group (within a network).
-
static
delete_attribute_group
(ctx, group_id)¶ Delete an attribute group.
-
static
delete_attribute_group_items
(ctx, attributegroupitems)¶ remove attribute groups items . ** attributegroupitems : a list of items, of the form:
-
static
get_attribute_group
(ctx, group_id)¶
-
static
get_attribute_item_groups
(ctx, network_id, attr_id)¶ Get all the group items in a network with a given attribute_id
-
static
get_group_attributegroup_items
(ctx, network_id, group_id)¶ Get all the items in a specified group, within a network
-
static
get_network_attributegroup_items
(ctx, network_id)¶ Get all the group items in a network
-
static
update_attribute_group
(ctx, attributegroup)¶ Update an existing attribute group.
An attribute group is a container for attributes which need to be grouped in some logical way. For example, if the ‘attr_is_var’ flag isn’t expressive enough to delineate different groupings.
- an attribute group looks like:
- {
‘project_id’ : XXX, ‘name’ : ‘my group name’ ‘description : ‘my group description’ (optional) ‘layout’ : ‘my group layout’ (optional) ‘exclusive’ : ‘N’ (or ‘Y’ ) (optional, default to ‘N’)
}
-
static
-
class
hydra_server.server.attributes.
AttributeService
¶ The attribute SOAP service
-
static
add_attribute
(ctx, attr)¶ Add a generic attribute, which can then be used in creating a resource attribute, and put into a type.
(Attr){ name = "Test Attr" dimen = "very big" description = "I am a very big attribute" }
- Args:
attr (complexmodels.Attr): An attribute object, as described above.
- Returns:
complexmodels.Attr: An attribute object, similar to the one sent in but with an ID.
-
static
add_attributes
(ctx, attrs)¶ Add multiple generic attributes
- Args:
- attrs (List[Attr]): A list of attribute complex models,
as described above.
- Returns:
- List[Attr]: A list of attribute complex models,
reflecting the ones sent in.
-
static
add_group_attribute
(ctx, group_id, attr_id, is_var)¶ Add a resource attribute to a group.
- Args:
group_id (int): The ID of the Group attr_id (int): THe ID if the attribute being added. is_var (char): Y or N. Indicates whether the attribute is a variable or not.
- Returns:
complexmodels.ResourceAttr: The newly created group attribute
- Raises:
ResourceNotFoundError: If the group or attribute do not exist HydraError: If this addition causes a duplicate attribute on the group.
-
static
add_group_attrs_from_type
(ctx, type_id, group_id)¶ Adds all the attributes defined by a type to a group.
- Args:
type_id (int): ID of the type used to get the resource attributes from group_id (int): ID of the group
- Returns:
List(complexmodels.ResourceAttr): All the newly created group attributes
- Raises:
ResourceNotFoundError if the type_id or group_id are not in the DB
-
static
add_link_attribute
(ctx, link_id, attr_id, is_var)¶ Add a resource attribute to a link.
- Args:
link_id (int): The ID of the Link attr_id (int): THe ID if the attribute being added. is_var (char): Y or N. Indicates whether the attribute is a variable or not.
- Returns:
complexmodels.ResourceAttr: The newly created link attribute
- Raises:
ResourceNotFoundError: If the link or attribute do not exist HydraError: If this addition causes a duplicate attribute on the link.
-
static
add_link_attrs_from_type
(ctx, type_id, link_id)¶ Adds all the attributes defined by a type to a link.
- Args:
type_id (int): ID of the type used to get the resource attributes from link_id (int): ID of the link
- Returns:
List(complexmodels.ResourceAttr): All the newly created link attributes
- Raises:
ResourceNotFoundError if the type_id or link_id are not in the DB
-
static
add_network_attribute
(ctx, network_id, attr_id, is_var)¶ Add a resource attribute to a network.
- Args:
network_id (int): ID of the network attr_id (int): ID of the attribute to assign to the network is_var (string) ‘Y’ or ‘N’. Indicates whether this attribute is
a variable or not. (a variable is typically the result of a model run, so therefore doesn’t need data assigned to it initially)
- Returns:
complexmodels.ResourceAttr: A complex model of the newly created resource attribute.
- Raises:
ResourceNotFoundError: If the network or attribute are not in the DB. HydraError : If the attribute is already on the network.
-
static
add_network_attrs_from_type
(ctx, type_id, network_id)¶ Adds all the attributes defined by a type to a network.
- Args:
type_id (int): ID of the type used to get the resource attributes from network_id (int): ID of the network
- Returns:
List(complexmodels.ResourceAttr): All the newly created network attributes
- Raises:
ResourceNotFoundError if the type_id or network_id are not in the DB
-
static
add_node_attribute
(ctx, node_id, attr_id, is_var)¶ Add a resource attribute to a node.
- Args:
node_id (int): The ID of the Node attr_id (int): THe ID if the attribute being added. is_var (char): Y or N. Indicates whether the attribute is a variable or not.
- Returns:
complexmodels.ResourceAttr: The newly created node attribute
- Raises:
ResourceNotFoundError: If the node or attribute do not exist HydraError: If this addition causes a duplicate attribute on the node.
-
static
add_node_attrs_from_type
(ctx, type_id, node_id)¶ Adds all the attributes defined by a type to a node.
- Args:
type_id (int): ID of the type used to get the resource attributes from node_id (int): ID of the node
- Returns:
List(complexmodels.ResourceAttr): All the newly created node attributes
- Raises:
ResourceNotFoundError if the type_id or node_id are not in the DB
-
static
check_attr_dimension
(ctx, attr_id)¶ Check that the dimension of the resource attribute data is consistent with the definition of the attribute. If the attribute says ‘volume’, make sure every dataset connected with this attribute via a resource attribute also has a dimension of ‘volume’.
- Args:
attr_id (int): The ID of the attribute you want to check
- Returns:
string: ‘OK’ if all is well.
- Raises:
HydraError: If a dimension mismatch is found.
-
static
check_mapping_exists
(ctx, resource_attr_id_source, resource_attr_id_target)¶ Check whether a mapping exists between two resource attributes This does not check whether a reverse mapping exists, so order is important here.
- Args:
resource_attr_id_source (int): The source resource attribute resource_attr_id_target (int) (optional): The target resource attribute
- Returns:
string: ‘Y’ if a mapping between the source and target exists. ‘N’ in every other case.
-
static
delete_attribute_mapping
(ctx, resource_attr_a, resource_attr_b)¶ Delete a mapping which said one resource attribute from one network was the same as the resource attribute in another.
- Args:
resource_attr_a (int): The ID of the source resoure attribute resource_attr_b (int): The ID of the target resoure attribute
- Returns:
string: ‘OK’ if all is well. If the mapping isn’t there, it’ll still return ‘OK’, so make sure the IDs are correct!
-
static
delete_mappings_in_network
(ctx, network_id, network_2_id)¶ Delete all the resource attribute mappings in a network. If another network is specified, only delete the mappings between the two networks.
- Args:
network_id (int): The network you want to delete the mappings from (both from and to) network_2_id (int) (optional): The partner network
- Returns:
string: ‘OK’
-
static
delete_resource_attribute
(ctx, resource_attr_id)¶ Add a resource attribute attribute to a resource (Duplicate of delete_resourceattr)
- Args:
resource_attr_id (int): ID of the complex model to be deleted
- Returns:
unicode: ‘OK’
- Raises:
ResourceNotFoundError if the resource_attr_id is not in the DB
-
static
delete_resourceattr
(ctx, resource_attr_id)¶ Deletes a resource attribute and all associated data. *WILL BE DEPRECATED*
- Args:
resource_attr_id (int): ID of the complex model to be deleted
- Returns:
unicode: ‘OK’
- Raises:
ResourceNotFoundError if the resource_attr_id is not in the DB
-
static
get_all_attributes
(ctx)¶ Get all the attributes in the system
- Args:
None
- Returns:
List[Attr]: A list of attribute complex models
-
static
get_all_group_attributes
(ctx, network_id, template_id)¶ Get all the resource attributes for all the groups in the network.
- Args:
network_id (int): The ID of the network that you want the group attributes from template_id (int) (optional): If this is specified, then it will only return the attributes in this template.
- Returns:
List(complexmodels.ResourceAttr): The resource attributes of all the groups in the network.
-
static
get_all_link_attributes
(ctx, network_id, template_id)¶ Get all the resource attributes for all the links in the network.
- Args:
network_id (int): The ID of the network that you want the link attributes from template_id (int) (optional): If this is specified, then it will only return the attributes in this template.
- Returns:
List(complexmodels.ResourceAttr): The resource attributes of all the links in the network.
-
static
get_all_node_attributes
(ctx, network_id, template_id)¶ Get all the resource attributes for all the nodes in the network.
- Args:
network_id (int): The ID of the network that you want the node attributes from template_id (int) (optional): If this is specified, then it will only return the attributes in this template.
- Returns:
List(complexmodels.ResourceAttr): The resource attributes of all the nodes in the network.
-
static
get_attribute
(ctx, name, dimension)¶ Get a specific attribute by its name and dimension (this combination is unique for attributes in Hydra Platform).
- Args:
name (unicode): The name of the attribute dimension (unicode): The dimension of the attribute
- Returns:
- complexmodels.Attr: An attribute complex model.
Returns None if no attribute is found.
-
static
get_attribute_by_id
(ctx, ID)¶ Get a specific attribute by its ID.
- Args:
ID (int): The ID of the attribute
- Returns:
- complexmodels.Attr: An attribute complex model.
Returns None if no attribute is found.
-
static
get_attributes
(ctx, attrs)¶ - Get a list of attribute, by their names and dimension. Takes a list
of attribute objects, picks out their name & dimension, finds the appropriate attribute in the DB and updates the incoming attribute with an ID. The same attributes go out that came in, except this time with an ID. If one of the incoming attributes does not match, this attribute is not returned.
- Args:
attrs (List(Attr)): A list of attribute complex models
- Returns:
List(complexmodels.Attr): List of Attr complex models
-
static
get_group_attributes
(ctx, group_id, type_id)¶ Get all a group’s attributes.
- Args:
group_id (int): ID of the group type_id (int) (optional): ID of the type. If specified will only return the resource attributes relative to that type
- Returns:
List(complexmodels.ResourceAttr): All the group’s attributes
- Raises:
ResourceNotFoundError if the type_id or group_id do not exist.
-
static
get_link_attributes
(ctx, link_id, type_id)¶ Get all a link’s attributes.
- Args:
link_id (int): ID of the link type_id (int) (optional): ID of the type. If specified will only return the resource attributes relative to that type
- Returns:
List(complexmodels.ResourceAttr): All the link’s attributes
- Raises:
ResourceNotFoundError if the type_id or link_id do not exist.
-
static
get_mappings_in_network
(ctx, network_id, network_2_id)¶ Get all the resource attribute mappings in a network (both from and to). If another network is specified, only return the mappings between the two networks.
- Args:
network_id (int): The network you want to check the mappings of (both from and to) network_2_id (int) (optional): The partner network
- Returns:
List(complexmodels.ResourceAttrMap): All the mappings to and from the network(s) in question.
-
static
get_network_attributes
(ctx, network_id, type_id)¶ Get all a network’s attributes (not the attributes of the nodes and links. just the network itself).
- Args:
network_id (int): ID of the network type_id (int) (optional): ID of the type. If specified will only return the resource attributes relative to that type
- Returns:
List(complexmodels.ResourceAttr): All the network attributes
- Raises:
ResourceNotFoundError if the type_id or network_id are not in the DB
-
static
get_node_attributes
(ctx, node_id, type_id)¶ Get all a node’s attributes.
- Args:
node_id (int): ID of the node type_id (int) (optional): ID of the type. If specified will only return the resource attributes relative to that type
- Returns:
List(complexmodels.ResourceAttr): All the node’s attributes
- Raises:
ResourceNotFoundError if the type_id or node_id do not exist.
-
static
get_node_mappings
(ctx, node_id, node_2_id)¶ Get the mappings for all the attributes of a given node. If a second node is specified, return only the mappings between these nodes..
- Args:
node_id (int): The node you want to delete the mappings from (both from and to) node_2_id (int) (optional): The partner node
- Returns:
List(complexmodels.ResourceAttrMap): All the mappings to and from the node(s) in question.
-
static
get_template_attributes
(ctx, template_id)¶ Get all the attributes in a template. Args
param (int) template_id
Returns
List(Attr)
-
static
set_attribute_mapping
(ctx, resource_attr_a, resource_attr_b)¶ Define one resource attribute from one network as being the same as that from another network.
- Args:
resource_attr_a (int): The ID of the source resoure attribute resource_attr_b (int): The ID of the target resoure attribute
- Returns:
string: ‘OK’ if all is well.
- Raises:
ResourceNotFoundError: If either resource attribute is not found.
-
static
update_attribute
(ctx, attr)¶ Update a generic attribute, which can then be used in creating a resource attribute, and put into a type.
(Attr){ id = 1020 name = "Test Attr" dimen = "very big" description = "I am a very big attribute" }
- Args:
attr (complexmodels.Attr): An attribute complex model, as described above.
- Returns:
complexmodels.Attr: An attribute complex model, reflecting the one sent in.
-
static
update_resource_attribute
(ctx, resource_attr_id, is_var)¶ Update a resource attribute (which means update the is_var flag as this is the only thing you can update on a resource attr)
- Args:
resource_attr_id (int): ID of the complex model to be updated is_var (unicode): ‘Y’ or ‘N’
- Returns:
List(complexmodels.ResourceAttr): Updated ResourceAttr
- Raises:
ResourceNotFoundError if the resource_attr_id is not in the DB
-
static
Scenarios¶
-
class
hydra_server.server.scenario.
ScenarioService
¶ The scenario SOAP service as all resources already exist, there is no need to worry about negative IDS
-
static
activate_scenario
(ctx, scenario_id)¶ Set the status of a scenario to ‘X’.
-
static
add_data_to_attribute
(ctx, scenario_id, resource_attr_id, dataset)¶ Add data to a resource scenario outside of a network update
-
static
add_scenario
(ctx, network_id, scen, return_summary)¶ Add a scenario to a specified network.
-
static
bulk_update_resourcedata
(ctx, scenario_ids, resource_scenarios)¶ Update the data associated with a scenario. Data missing from the resource scenario will not be removed from the scenario. Use the remove_resourcedata for this task.
-
static
copy_data_from_scenario
(ctx, resource_attr_ids, source_scenario_id, target_scenario_id)¶ Copy the datasets from a source scenario into the equivalent resource scenarios in the target scenario. Parameters are a list of resource attribute IDS, the ID of the source scenario and the ID of the target scenario.
-
static
create_child_scenario
(ctx, scenario_id, child_name)¶ Create a new scenario which inherits from the specified scenario
-
static
delete_resourcedata
(ctx, scenario_id, resource_scenario)¶ Remove the data associated with a resource in a scenario.
-
static
delete_scenario
(ctx, scenario_id)¶ Set the status of a scenario to ‘X’.
-
static
get_attribute_datasets
(ctx, attr_id, scenario_id, get_parent_data)¶ Get all the datasets from resource attributes with the given attribute ID in the given scenario.
Return a list of resource attributes with their associated resource scenarios (and values).
-
static
get_dataset_scenarios
(ctx, dataset_id)¶ Get all the scenarios attached to a dataset @returns a list of scenario_ids
-
static
get_link_data
(ctx, link_id, scenario_id, type_id, get_parent_data)¶ Get all the resource scenarios for a given link in a given scenario. If type_id is specified, only return the resource scenarios for the attributes within the type.
-
static
get_network_data
(ctx, network_id, scenario_id, type_id, get_parent_data)¶ Get all the resource scenarios for a given network in a given scenario. If type_id is specified, only return the resource scenarios for the attributes within the type.
-
static
get_node_attribute_data
(ctx, node_ids, attr_ids)¶ Get the data for multiple attributes on multiple nodes across multiple scenarios. @returns a list of AttributeData objects, which consist of a list of ResourceAttribute objects and a list of corresponding ResourceScenario objects.
-
static
get_node_data
(ctx, node_id, scenario_id, type_id, get_parent_data)¶ Get all the resource scenarios for a given node in a given scenario. If type_id is specified, only return the resource scenarios for the attributes within the type.
-
static
get_resource_scenario
(ctx, resource_attr_id, scenario_id, get_parent_data)¶ Get the resource scenario object for a given resource atttribute and scenario. This is done when you know the attribute, resource and scenario and want to get the value associated with it.
The get_parent_data flag indicates whether we should look only at this scenario, or if the resource scenario does not exist on this scenario to look in its parent.
-
static
get_resourcegroup_data
(ctx, resourcegroup_id, scenario_id, type_id, get_parent_data)¶ Get all the resource scenarios for a given resourcegroup in a given scenario. If type_id is specified, only return the resource scenarios for the attributes within the type.
-
static
get_scenario
(ctx, scenario_id, return_summary, get_parent_data)¶ Get the specified scenario
-
static
purge_scenario
(ctx, scenario_id)¶ Set the status of a scenario to ‘X’.
-
static
set_resourcescenario_dataset
(ctx, resource_attr_id, scenario_id, dataset_id)¶ A short-hand way of creating a resource scenario. This function says: assign this datset ID to this resource attribute in this scenario. All the IDs must already exist.
-
static
update_resourcedata
(ctx, scenario_id, resource_scenarios)¶ Update the data associated with a scenario. Data missing from the resource scenario will not be removed from the scenario. Use the remove_resourcedata for this task.
-
static
update_scenario
(ctx, scen, update_data, update_groups, return_summary)¶ Update a single scenario as all resources already exist, there is no need to worry about negative IDS
-
static
User Management¶
-
class
hydra_server.server.users.
UserService
¶ The user soap service
-
static
add_perm
(ctx, perm)¶ Add a new permission. A permission defines a particular action that a user can perform. A permission is independent of roles and are added to roles later.
- Args:
perm (complexmodels.Perm): The new permission.
- Returns:
complexmodels.Perm: The new permission
-
static
add_role
(ctx, role)¶ Add a new role. A role is the highest level in the permission tree and is container for permissions. Users are then assigned a role, which gives them the specified permissions
- Args:
role (complexmodels.Role): The role to be added
- Returns:
complexmodels.Role: The newly created role, complete with ID
-
static
add_user
(ctx, user)¶ Add a new user.
- Args:
user (complexmodels.User): The user to be added, including username, display name and password
- Returns:
complexmodels.User: The newly added user, without password
- Raises:
ResourceNotFoundError: If the uid is not found
-
static
delete_perm
(ctx, perm_id)¶ Permenantly delete a permission
- Args:
perm_id (int): The permission to be deleted
- Returns:
string: ‘OK’
- Raises:
ResourceNotFoundError: If the perm_id is not found
-
static
delete_role
(ctx, role_id)¶ Permenantly delete a role (and all its sub-permissions and users)
- Args:
role_id (int): The role to be deleted
- Returns:
string: ‘OK’
- Raises:
ResourceNotFoundError: If the role_id is not found
-
static
delete_role_perm
(ctx, role_id, perm_id)¶ Remove a permission from a role
- Args:
role_id (int): The role to lose the permission perm_id (int): The permission being removed from the role
- Returns:
string: ‘OK’
- Raises:
ResourceNotFoundError: If the role does not contain the permission or if the userermission or role do not exist.
-
static
delete_user
(ctx, user_id)¶ Delete a user permenantly from the DB.
- Args:
user_id (int): The ID user to be deleted.
- Returns:
string: ‘OK’
- Raises:
ResourceNotFoundError: If the user_id is not found
-
static
delete_user_role
(ctx, user_id, role_id)¶ Remove a user from a role
- Args:
user_id (int): The user to be removed from the role role_id (int): The role to lose the user
- Returns:
string: ‘OK’
- Raises:
ResourceNotFoundError: If the role does not contain the user or if the user or role do not exist.
-
static
get_all_perms
(ctx)¶ Get all permissions
Args:
- Returns:
List(complexmodels.Perm): All the permissions in the system
Raises:
-
static
get_all_roles
(ctx)¶ Get all roles
Args:
- Returns:
List(complexmodels.Role): All the roles in the system
Raises:
-
static
get_all_users
(ctx)¶ Get the username & ID of all users.
Args:
- Returns:
List(complexmodels.User): All the users in the system
Raises:
-
static
get_perm
(ctx, perm_id)¶ Get a permission, by ID
- Args:
perm_id (int): The ID of the permission
- Returns:
complexmodels.Perm: The permission
- Raises:
ResourceNotFoundError: If the permission does not exist
-
static
get_perm_by_code
(ctx, perm_code)¶ Get a permission by its code. Permission IDS change between hydra instances. Codes are more stable.
- Args:
perm_id (int): The code of the permission.
- Returns:
complexmodels.Perm: The permission
- Raises:
ResourceNotFoundError: If the permission does not exist
-
static
get_role
(ctx, role_id)¶ Get a role by its ID.
- Args:
role_id (int): The ID of the role to retrieve
- Returns:
complexmodels.Role: The role
- Raises:
ResourceNotFoundError: If the role does not exist
-
static
get_role_by_code
(ctx, role_code)¶ Get a role by its code instead of ID (IDS can change between databases. codes are more stable)
- Args:
role_code (string): The code of the role to retrieve
- Returns:
complexmodels.Role: The role
- Raises:
ResourceNotFoundError: If the role does not exist
-
static
get_user_by_name
(ctx, username)¶ Get a user by username
- Args:
username (string): The username being searched for
- Returns:
complexmodels.User: The requested user, or None
-
static
get_user_permissions
(ctx, user_id)¶ Get all the permissions granted to the user, based on all the roles that the user is in. Args:
user_id (int): The user whose permissions you want
- Returns:
List(complexmodels.Perm): The user’s permissions
- Raises:
ResourceNotFoundError: If the user does not exist
-
static
get_user_roles
(ctx, user_id)¶ Get the roles assigned to a user. (A user can have multiple roles)
- Args:
user_id (int): The ID of the user whose roles you want
- Returns:
List(complexmodels.Role): The roles of the user
- Raises:
ResourceNotFoundError: If the user does not exist
-
static
get_username
(ctx, uid)¶ Get a user’s username.
- Args:
uid (int): The ID of the user
- Returns:
string: the user’s username
- Raises:
ResourceNotFoundError: If the uid is not found
-
static
set_role_perm
(ctx, role_id, perm_id)¶ Assign a permission to a role
- Args:
role_id (int): The role to receive the permission perm_id (int): The permission being added to the role
- Returns:
complexmodels.Role: The newly updated role, complete with new permission
- Raises:
ResourceNotFoundError: If the role or permission do not exist
-
static
set_user_role
(ctx, user_id, role_id)¶ Assign a user to a role
- Args:
user_id (int): The user to be given the new role role_id (int): The role to receive the new user
- Returns:
complexmodels.Role: Returns the role to which the user has been added. (contains all the user roles).
- Raises:
ResourceNotFoundError: If the user_id or role_id do not exist
-
static
update_role
(ctx, role)¶ Update a role. Used to add multiple permissions and users to a role in one go.
- Args:
role (complexmodels.Role): The role with new users & permissions
- Returns:
complexmodels.Role: The newly updated role
- Raises:
ResourceNotFoundError: If the role or any users or permissions do not exist
-
static
update_user_display_name
(ctx, user)¶ Update a user’s display name
- Args:
user (complexmodels.User): The user to be updated. Only the display name is updated
- Returns:
complexmodels.User: The updated user, without password
- Raises:
ResourceNotFoundError: If the uid is not found
-
static
update_user_password
(ctx, user_id, new_password)¶ Update a user’s password
- Args:
user_id (int): The ID user to be updated. new_password (string): The new password.
- Returns:
complexmodels.User: The updated user, without password
- Raises:
ResourceNotFoundError: If the user_id is not found
-
static
whoami
(ctx)¶ Get the user object of the requesting user.
Args:
- Returns:
User: the user object
- Raises:
ResourceNotFoundError: If the uid is not found
-
static
Plugins¶
-
class
hydra_server.server.plugins.
PluginService
¶ Plugin SOAP service
-
static
check_plugin_status
(ctx, plugin_name, pid)¶ Check the status of a plugin by looking into the log file for the PID
- Args:
plugin_name (string): The name of the plugin being checked (used to identify the log file to look in) pid (int): The ID of the plugin to check
- Returns:
string: The logs produced by the plugin. If the PID is not correct, return “No log found for PID %s in %s”
- Raises:
IOError: If the log file does not exist for the plugin name
-
static
get_plugins
(ctx)¶ Get all available plugins
Args:
- Returns:
List(string): A list of all the available plugins (the contents of plugin.xml)
-
static
run_plugin
(ctx, plugin)¶ Run a plugin
- Args:
plugin (Plugin): A plugin object containing the location of the plugin and its parameters.
- Returns:
string: The process ID of the plugin
-
static
Resource Templates¶
-
class
hydra_server.server.template.
TemplateService
¶ The template SOAP service
-
static
add_template
(ctx, tmpl)¶ Add template and a type and typeattrs.
-
static
add_templatetype
(ctx, templatetype)¶ Add a template type with typeattrs.
-
static
add_typeattr
(ctx, typeattr)¶ Add an typeattr to an existing type.
-
static
apply_template_to_network
(ctx, template_id, network_id)¶ Given a template and a network, try to match up and assign all the nodes & links in the network to the types in the template
-
static
assign_type_to_resource
(ctx, type_id, resource_type, resource_id)¶ Assign new type to a resource. This function checks if the necessary attributes are present and adds them if needed. Non existing attributes are also added when the type is already assigned. This means that this function can also be used to update resources, when a resource type has changed.
-
static
assign_types_to_resources
(ctx, resource_types)¶ Assign new types to list of resources. This function checks if the necessary attributes are present and adds them if needed. Non existing attributes are also added when the type is already assigned. This means that this function can also be used to update resources, when a resource type has changed.
-
static
delete_template
(ctx, template_id)¶ Update template and a type and typeattrs.
-
static
delete_templatetype
(ctx, type_id)¶ Update template and a type and typeattrs.
-
static
delete_typeattr
(ctx, typeattr)¶ Remove an typeattr from an existing type
-
static
get_matching_resource_types
(ctx, resource_type, resource_id)¶ Get the possible types of a resource by checking its attributes against all available types.
@returns A list of TypeSummary objects.
-
static
get_network_as_xml_template
(ctx, network_id)¶ Turn an existing network into an xml template using its attributes. If an optional scenario ID is passed in, default values will be populated from that scenario.
-
static
get_template
(ctx, template_id)¶ Get a specific resource template template, either by ID or name.
-
static
get_template_by_name
(ctx, template_name)¶ Get a specific resource template, either by ID or name.
-
static
get_templates
(ctx)¶ Get all resource template templates.
-
static
get_templatetype
(ctx, type_id)¶ Get a specific resource type by ID.
-
static
get_templatetype_by_name
(ctx, template_id, type_name)¶ Get a specific resource type by name.
-
static
remove_attr_from_type
(ctx, type_id, attr_id)¶ Remove an attribute from a type
-
static
remove_template_from_network
(ctx, network_id, template_id, remove_attrs)¶ Given a template and a network, try to match up and assign all the nodes & links in the network to the types in the template
-
static
remove_type_from_resource
(ctx, type_id, resource_type, resource_id)¶ Remove a resource type trom a resource
-
static
update_template
(ctx, tmpl)¶ Update template and a type and typeattrs.
-
static
update_templatetype
(ctx, templatetype)¶ Update a resource type and its typeattrs. New typeattrs will be added. typeattrs not sent will be ignored. To delete typeattrs, call delete_typeattr
-
static
upload_template_xml
(ctx, template_xml)¶ Add the template, type and typeattrs described in an XML file.
Delete type, typeattr entries in the DB that are not in the XML file The assumption is that they have been deleted and are no longer required.
-
static
validate_attr
(ctx, resource_attr_id, scenario_id, template_id)¶ Validate that the value of a specified resource attribute is valid relative to the data restrictions specified on the template. If no template is specified, (set as null), then validation will be made against every template on the network.
-
static
Units and Dimensions¶
-
class
hydra_server.server.units.
UnitService
¶ DIMENSION FUNCTIONS - GET
-
static
add_dimension
(ctx, dimension)¶ Add a physical dimensions (such as
Volume
orSpeed
) to the servers list of dimensions. If the dimension already exists, nothing is done.
-
static
add_unit
(ctx, unit)¶ Add a physical unit to the servers list of units. The Hydra server provides a complex model
Unit
which should be used to add a unit.A minimal example:
from HydraLib import PluginLib cli = PluginLib.connect() new_unit = cli.factory.create('hyd:Unit') new_unit.name = 'Teaspoons per second' new_unit.abbr = 'tsp s^-1' new_unit.cf = 0 # Constant conversion factor new_unit.lf = 1.47867648e-05 # Linear conversion factor new_unit.dimension = 'Volumetric flow rate' new_unit.info = 'A flow of one teaspoon per second.' cli.service.add_unit(new_unit)
-
static
check_consistency
(ctx, unit, dimension)¶ Check if a given units corresponds to a physical dimension.
-
static
convert_dataset
(ctx, dataset_id, to_unit)¶ Convert a whole dataset (specified by ‘dataset_id’ to new unit (‘to_unit’).
-
static
convert_unit
(ctx, value, unit1, unit2)¶ Convert a SINGLE value from one unit to another one.
Example:
>>> cli = PluginLib.connect() >>> cli.service.convert_units(20.0, 'm', 'km') 0.02
-
static
convert_units
(ctx, values, unit1, unit2)¶ Convert a list of values from one unit to another one.
Example:
>>> cli = PluginLib.connect() >>> cli.service.convert_units(20.0, 'm', 'km') 0.02
-
static
delete_dimension
(ctx, dimension_id)¶ Delete a physical dimension from the list of dimensions. Please note that deleting works only for dimensions listed in the custom file.
-
static
delete_unit
(ctx, unit_id)¶ Delete a unit from the custom unit collection.
-
static
get_dimension
(ctx, dimension_id)¶ Gets the dimension details and the list of all units assigned to the dimension.
-
static
get_dimensions
(ctx)¶ Gets a list of all physical dimensions available on the server.
-
static
get_unit
(ctx, unit_id)¶ Gets the Unit details
-
static
get_unit_dimension
(ctx, unit1)¶ Get the corresponding physical dimension for a given unit.
Example:
>>> cli = PluginLib.connect() >>> cli.service.get_dimension('m') Length
-
static
get_units
(ctx)¶ Get a list of all units corresponding to a physical dimension.
-
static
is_global_dimension
(ctx, dimension_id)¶ Returns True if the dimension is global, False otherwise
-
static
is_global_unit
(ctx, unit_id)¶ Returns True if the dimension is global, False otherwise
-
static
update_dimension
(ctx, dimension)¶ update a physical dimensions (such as
Volume
orSpeed
) to the servers list of dimensions.
-
static
update_unit
(ctx, unit)¶ Update an existing unit added to the custom unit collection. Please not that units built in to the library can not be updated.
-
static