Пример #1
0
    def get_network(ctx, network_id, include_resources, summary, include_data,
                    template_id, scenario_ids):
        """
        Return a whole network as a complex model.

        Args:
            network_id   (int)              : The ID of the network to retrieve
            include_resources      (char) ('Y' or 'N'): Optional flag to indicate whether resources are included with the network.
            summary      (char) ('Y' or 'N'): Optional flag to indicate whether attributes are returned with the nodes & links. Setting to 'Y' has significant speed improvements at the cost of not retrieving attribute information.
            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

        Returns:
            hydra_complexmodels.Network: A network complex model

        Raises:
            ResourceNotFoundError: If the network is not found.
        """
        include_resources = True if include_resources == 'Y' else False
        summary = True if summary == 'Y' else False
        net = network.get_network(network_id, include_resources, summary,
                                  include_data, scenario_ids, template_id,
                                  **ctx.in_header.__dict__)
        ret_net = Network(net, summary)
        return ret_net
Пример #2
0
    def add_network(ctx, net, return_summary):
        """
        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 (hydra_complexmodels.Network): The entire network complex model structure including nodes, links, scenarios and data

        Returns:
            hydra_complexmodels.Network: The full network structure, with correct IDs for all resources

        """
        net = network.add_network(net, **ctx.in_header.__dict__)
        ret_net = Network(net, summary=return_summary == 'Y')
        return ret_net
Пример #3
0
    def 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 (hydra_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:
            hydra_complexmodels.Network: The updated network, in summarised forms (without data or attributes)

        Raises:
            ResourceNotFoundError: If the network does not exist.


        """
        upd_nodes = True if update_nodes == 'Y' else False
        upd_links = True if update_links == 'Y' else False
        upd_groups = True if update_groups == 'Y' else False
        upd_scenarios = True if update_scenarios == 'Y' else False

        net = network.update_network(net, upd_nodes, upd_links, upd_groups,
                                     upd_scenarios, **ctx.in_header.__dict__)
        return Network(net, summary=True)
Пример #4
0
    def get_networks(ctx, project_id, include_resources, summary,
                     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(hydra_complexmodels.Network): All the project's Networks.

        Raises:
            ResourceNotFoundError: If the Project is not found.

        """
        include_resources = True if include_resources == 'Y' else False
        summary = True if summary == 'Y' else False
        net_dicts = project_lib.get_networks(
            project_id,
            include_resources=include_resources,
            summary=summary,
            include_data=include_data,
            **ctx.in_header.__dict__)
        networks = [Network(n, summary=summary) for n in net_dicts]
        return networks
Пример #5
0
    def 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:
            hydra_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
        """

        net = network.get_network_by_name(project_id, network_name,
                                          **ctx.in_header.__dict__)

        return Network(net)