Beispiel #1
0
    def 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.

        """

        group_resourcescenarios = network.get_attributes_for_resource(
            network_id, scenario_id, 'GROUP', group_ids, include_metadata)
        return_ras = []
        for grouprs in group_resourcescenarios:
            ra = ResourceAttr(grouprs.resourceattr)
            ra.resourcescenario = ResourceScenario(grouprs, ra.attr_id)
            return_ras.append(ra)

        return return_ras
Beispiel #2
0
    def get_attribute_datasets(ctx, attr_id, scenario_id):
        """
            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).
        """
        resource_attrs = scenario.get_attribute_datasests(attr_id, scenario_id, **ctx.in_header.__dict__)

        ra_cms = []
        for ra in resource_attrs:
            res_attr_cm = ResourceAttr(ra)
            for rs in ra.resourcescenarios:
                if rs.scenario_id==scenario_id:
                    res_attr_cm.resourcescenario = ResourceScenario(rs)
            ra_cms.append(res_attr_cm)

        return ra_cms
Beispiel #3
0
    def get_attribute_datasets(ctx, attr_id, scenario_id):
        """
            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).
        """
        resource_attrs = scenario.get_attribute_datasests(
            attr_id, scenario_id, **ctx.in_header.__dict__)

        ra_cms = []
        for ra in resource_attrs:
            res_attr_cm = ResourceAttr(ra)
            for rs in ra.resourcescenarios:
                if rs.scenario_id == scenario_id:
                    res_attr_cm.resourcescenario = ResourceScenario(rs)
            ra_cms.append(res_attr_cm)

        return ra_cms
Beispiel #4
0
    def 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


        """
        start = datetime.datetime.now()

        link_resourcescenarios = network.get_attributes_for_resource(
            network_id, scenario_id, 'LINK', link_ids, include_metadata)

        log.info("Qry done in %s", (datetime.datetime.now() - start))
        start = datetime.datetime.now()

        return_ras = []
        for linkrs in link_resourcescenarios:
            ra = ResourceAttr(linkrs.resourceattr)
            ra.resourcescenario = ResourceScenario(linkrs, ra.attr_id)
            return_ras.append(ra)

        log.info("Return vals built in %s", (datetime.datetime.now() - start))

        return return_ras
Beispiel #5
0
    def get_resource_attribute_datasets(ctx, resource_attr_id, scenario_id):
        """
            Get all the datasets from resource attributes with the given resource attribute
            IDs in the given scenarios.
        """

        if not isinstance(resource_attr_id, list):
            resource_attr_id = [resource_attr_id]

        if not isinstance(scenario_id, list):
            scenario_id = [scenario_id]

        ra_cms = []
        resource_attrs = scenario.get_resource_attribute_datasets(
            resource_attr_id, scenario_id, **ctx.in_header.__dict__)

        for ra in resource_attrs:
            res_attr_cm = ResourceAttr(ra)
            for rs in ra.resourcescenarios:
                if rs.scenario_id in scenario_id:
                    res_attr_cm.resourcescenario = ResourceScenario(rs)
            ra_cms.append(res_attr_cm)

        return ra_cms