def build_qau_from_dict(qau_dict) -> esdl.QuantityAndUnitType:
    qau = esdl.QuantityAndUnitType()

    if 'id' in qau_dict:
        qau.id = qau_dict['id']
    else:
        qau.id = str(uuid.uuid4())

    if 'description' in qau_dict:
        qau.description = qau_dict['description']
    else:
        qau.description = ''

    if 'physicalQuantity' in qau_dict:
        qau.physicalQuantity = esdl.PhysicalQuantityEnum.from_string(
            qau_dict['physicalQuantity'])
    if 'multiplier' in qau_dict:
        qau.multiplier = esdl.MultiplierEnum.from_string(
            qau_dict['multiplier'])
    if 'unit' in qau_dict:
        qau.unit = esdl.UnitEnum.from_string(qau_dict['unit'])
    if 'perMultiplier' in qau_dict:
        qau.perMultiplier = esdl.MultiplierEnum.from_string(
            qau_dict['perMultiplier'])
    if 'perUnit' in qau_dict:
        qau.perUnit = esdl.UnitEnum.from_string(qau_dict['perUnit'])
    if 'perTimeUnit' in qau_dict:
        qau.perTimeUnit = esdl.TimeUnitEnum.from_string(
            qau_dict['perTimeUnit'])

    return qau
Ejemplo n.º 2
0
def _create_cost_qau(cost_unit_string):
    qau = esdl.QuantityAndUnitType(
        id=str(uuid4()),
        physicalQuantity=esdl.PhysicalQuantityEnum.COST,
        description='Cost in ' + cost_unit_string)
    _change_cost_unit(qau, cost_unit_string)
    print('new qau', EnergySystemHandler.attr_to_dict(qau))
    return qau
Ejemplo n.º 3
0
 def get_or_create_qau(self, qau_id):
     esh = get_handler()
     active_es_id = get_session('active_es_id')
     try:
         qau = esh.get_by_id(active_es_id, qau_id)
         return qau
     except KeyError:
         # qua does not exist, create it
         global_qua = get_or_create_esi_qau(esh, active_es_id)
         if qau_id == 'flow':
             qau = esdl.QuantityAndUnitType(id=qau_id)
             qau.physicalQuantity = esdl.PhysicalQuantityEnum.FLOW
             qau.unit = esdl.UnitEnum.CUBIC_METRE
             qau.perTimeUnit = esdl.TimeUnitEnum.HOUR
             qau.description = "Flow in m³/h"
         if qau_id == 'head':
             qau = esdl.QuantityAndUnitType(id=qau_id)
             qau.physicalQuantity = esdl.PhysicalQuantityEnum.HEAD
             qau.unit = esdl.UnitEnum.METRE
             qau.description = "Head in m"
         if qau_id == 'efficiency':
             qau = esdl.QuantityAndUnitType(id=qau_id)
             qau.physicalQuantity = esdl.PhysicalQuantityEnum.COEFFICIENT
             qau.unit = esdl.UnitEnum.PERCENT
             qau.description = "Efficiency in %"
         if qau_id == 'position':
             qau = esdl.QuantityAndUnitType(id=qau_id)
             qau.physicalQuantity = esdl.PhysicalQuantityEnum.POSITION
             qau.unit = esdl.UnitEnum.NONE
             qau.description = "Position [-]"
         if qau_id == 'kv_coefficient':
             qau = esdl.QuantityAndUnitType(id=qau_id)
             qau.physicalQuantity = esdl.PhysicalQuantityEnum.COEFFICIENT
             qau.unit = esdl.UnitEnum.CUBIC_METRE
             qau.perTimeUnit = esdl.TimeUnitEnum.HOUR
             qau.perUnit = esdl.UnitEnum.BAR
             qau.description = "Coefficient in m³/h/bar"
         global_qua.quantityAndUnit.append(qau)
         esh.add_object_to_dict(active_es_id, qau)
         return qau
    def convert_potential(esh, active_es_id, pot, add_to_building, percentage, asset_list):
        pot_container = pot.eContainer()

        # Determine orientation from potential information
        orientation_name = ""
        if pot.orientation in PICO_ROOF_ORIENTATIONS:
            orientation_name = " (" + PICO_ROOF_ORIENTATIONS[pot.orientation] + ")"

        # Create a PVInstallation instance and attach a profile with the percentage of the potential that
        # will be 'installed'
        pv_installation = esdl.PVInstallation(id=str(uuid.uuid4()), name="PV Installation" + orientation_name)
        pv_outport = esdl.OutPort(id=str(uuid.uuid4()), name="Out")
        pv_profile = esdl.SingleValue(id=str(uuid.uuid4()), name="PV production", value=pot.value * percentage / 100)
        # Assume kWh for now, Geodan should communicate this in the ESDL in the end
        pv_profile.profileQuantityAndUnit = esdl.QuantityAndUnitType(
            physicalQuantity=esdl.PhysicalQuantityEnum.ENERGY,
            unit=esdl.UnitEnum.WATTHOUR,
            multiplier=esdl.MultiplierEnum.KILO)
        pv_outport.profile.append(pv_profile)
        pv_installation.port.append(pv_outport)

        # Generate a location on the map for the PV Installation
        if isinstance(pot_container, esdl.AbstractBuilding):
            # Place the Asset in the top left corner of the BuildingEditor
            pv_geometry = esdl.Point(lon=10.0, lat=490.0, CRS="Simple")
            pv_installation.geometry = pv_geometry
            add_to_building[0] = True
        else:
            pot_geometry = pot.geometry
            if isinstance(pot_geometry, esdl.Point):
                # Place the Asset with a small offset from the SolarPotential marker
                pv_geometry = esdl.Point(lon=pot_geometry.lon + 0.001, lat=pot_geometry.lat - 0.001)
                pv_installation.geometry = pv_geometry
            else:
                logger.warning('Using potentials with geometry other than esdl.Point not supported yet')

        # Add the PVInstallation to the same container as the SolarPotential (Area or Building)
        pot_container.asset.append(pv_installation)
        esh.add_object_to_dict(active_es_id, pv_installation, recursive=True)
        if isinstance(pot_container, esdl.AbstractBuilding):
            calc_building_assets_location(pot_container, True)

        # Adapt the potential (substract the installed value)
        pot.value = pot.value * (100-percentage) / 100

        port_list = [{'name': pv_outport.name, 'id': pv_outport.id, 'type': type(pv_outport).__name__, 'conn_to': []}]
        capability_type = ESDLAsset.get_asset_capability_type(pv_installation)
        tooltip_asset_attrs = get_tooltip_asset_attrs(pv_installation, 'marker')
        asset_list.append(['point', 'asset', pv_installation.name, pv_installation.id,
                           type(pv_installation).__name__, [pv_geometry.lat, pv_geometry.lon],
                           tooltip_asset_attrs, 'e', port_list, capability_type])
        return pv_installation
def build_qau_from_unit_string(unit_string):
    qau = esdl.QuantityAndUnitType(id=str(uuid.uuid4()))

    unit_parts = unit_string.split('/')
    if unit_parts:
        # Parse the unit
        for u in unitdict:
            if unitdict[u] == unit_parts[0]:
                qau.unit = esdl.UnitEnum.from_string(u)

        # if the first try failed, try to see if there is a multiplier in front of the unit
        if qau.unit == esdl.UnitEnum.NONE:
            unit = unit_parts[0][1:]
            for u in unitdict:
                if unitdict[u] == unit:
                    for m in multiplierdict:
                        if multiplierdict[m] == unit_parts[0][0]:
                            qau.unit = esdl.UnitEnum.from_string(u)
                            qau.multiplier = esdl.MultiplierEnum.from_string(m)

        # Zero, one or two 'perUnits' are possible
        if len(unit_parts) > 1:
            for up in range(1, len(unit_parts)):
                # Parse the perUnit
                for u in unitdict:
                    if unitdict[u] == unit_parts[up]:
                        qau.perUnit = esdl.UnitEnum.from_string(u)

                # if the first try failed, try to see if there is a multiplier in front of the perUnit
                if qau.perUnit == esdl.UnitEnum.NONE:
                    unit = unit_parts[up][1:]
                    for u in unitdict:
                        if unitdict[u] == unit:
                            for m in multiplierdict:
                                if multiplierdict[m] == unit_parts[up][0]:
                                    qau.perUnit = esdl.UnitEnum.from_string(u)
                                    qau.perMultiplier = esdl.MultiplierEnum.from_string(
                                        m)

                # Parse the perTimeUnit
                for tu in timeunitdict:
                    if timeunitdict[tu] == unit_parts[up]:
                        qau.perTimeUnit = esdl.TimeUnitEnum.from_string(tu)

    return qau
    def collect_info(self, area, include_all_areas):
        esh = get_handler()
        active_es_id = get_session('active_es_id')
        es = esh.get_energy_system(active_es_id)

        heat_qau = esdl.QuantityAndUnitType(
                    physicalQuantity=esdl.PhysicalQuantityEnum.ENERGY,
                    multiplier=esdl.MultiplierEnum.MEGA,
                    unit=esdl.UnitEnum.JOULE)

        esi = es.energySystemInformation
        if not esi:
            esi = esdl.EnergySystemInformation(id=str(uuid.uuid4()))
            es.energySystemInformation = esi

        qaus = esi.quantityAndUnits
        if not qaus:
            qaus = esdl.QuantityAndUnits(id=str(uuid.uuid4()))
            esi.quantityAndUnits = qaus

        qaus.quantityAndUnit.append(heat_qau)

        for ar in area.area:
            asset_list, qau_list = self.call_residentail_EG_service(ar.id, ar.scope)
            for qau in qau_list:
                try:
                    q = esh.get_by_id(active_es_id, qau.id)
                except:
                    # Only add qau if not already exists
                    qaus.quantityAndUnit.append(qau)
                    esh.add_object_to_dict(active_es_id, qau)

            for asset in list(asset_list):
                if isinstance(asset, esdl.GasDemand):
                    gv = asset.port[0].profile[0].value   # in m3
                    hv = gv * 35.17      # in MJ

                    hd = esdl.HeatingDemand(id=str(uuid.uuid4()), name="HD_"+ar.id)
                    hd.port.append(esdl.InPort(id=str(uuid.uuid4()),name="InPort"))
                    hd.port[0].profile.append(esdl.SingleValue(id=str(uuid.uuid4()), value=hv))
                    hd.port[0].profile[0].profileQuantityAndUnit = esdl.QuantityAndUnitReference(reference=heat_qau)

                    ar.asset.append(hd)
                    esh.add_object_to_dict(active_es_id, hd, True)
Ejemplo n.º 7
0
    def add_quantity_and_units(self):
        """
        Energy System information can be used to globally define the quantity and
        units of this system, instead of defining them manually per KPI in each
        area: this fosters reuse (but is not necessary)
        """
        q_and_u = self.energy_system.get_quantity_and_units()

        for quantity, prop in quantities.items():
            if self.energy_system.has_object_with_id(quantity): continue

            q_and_u.quantityAndUnit.append(
                esdl.QuantityAndUnitType(
                    id=quantity,
                    physicalQuantity=prop['physicalQuantity'],
                    multiplier=prop['multiplier'],
                    unit=prop['unit'],
                    description=prop['description']
                )
            )
def get_qau_information(esdl_doc=None):
    qaut = esdl.QuantityAndUnitType()

    attributes = dict()
    for x in qaut.eClass.eAllStructuralFeatures():
        # print('{} is of type {}'.format(x.name, x.eClass.name))
        if isinstance(x, EAttribute):
            attr = dict()
            attr['name'] = x.name
            attr['type'] = x.eType.name
            # if isinstance(x., EEnum):
            #    attr['value'] = list(es.eGet(x))
            attr['value'] = qaut.eGet(x)
            if attr['value'] is not None:
                if x.many:
                    if isinstance(attr['value'], EOrderedSet):
                        attr['value'] = [x.name for x in attr['value']]
                        attr['many'] = True
                    else:
                        attr['value'] = list(x.eType.to_string(attr['value']))
                else:
                    attr['value'] = x.eType.to_string(attr['value'])
            if isinstance(x.eType, EEnum):
                attr['type'] = 'EEnum'
                attr['enum_type'] = x.eType.name
                attr['options'] = list(lit.name for lit in x.eType.eLiterals)
                attr['default'] = x.eType.default_value.name
            else:
                attr['default'] = x.eType.default_value
                if x.eType.default_value is not None:
                    attr['default'] = x.eType.to_string(x.eType.default_value)
            if x.eType.name == 'EBoolean':
                attr['options'] = ['true', 'false']
            attr['doc'] = x.__doc__
            if x.__doc__ is None and esdl_doc is not None:
                attr['doc'] = esdl_doc.get_doc(qaut.eClass.name, x.name)

            attributes[x.name] = attr

    return attributes
Ejemplo n.º 9
0
    qau.description = descr
    qau_str = qau_to_string(qau)
    print("- {}".format(qau_str))

    print("- Building unit from the QaU sting:")
    unit_str = unit_to_string(qau)
    unit_qau = build_qau_from_unit_string(unit_str)
    qau_dict = esh.attr_to_dict(unit_qau)
    print("  Unit: {}".format(unit_to_string(unit_qau)))
    print("  {}".format(qau_dict))


if __name__ == "__main__":
    esh = EnergySystemHandler()

    qau = esdl.QuantityAndUnitType(id=str(uuid4()))
    qau.physicalQuantity = esdl.PhysicalQuantityEnum.DIRECTION
    qau.unit = esdl.UnitEnum.DEGREES
    test_qau("Wind direction in degrees", qau)

    qau = esdl.QuantityAndUnitType(id=str(uuid4()))
    qau.physicalQuantity = esdl.PhysicalQuantityEnum.POWER
    qau.multiplier = esdl.MultiplierEnum.KILO
    qau.unit = esdl.UnitEnum.WATT
    test_qau("Power in kiloWatt", qau)

    qau = esdl.QuantityAndUnitType(id=str(uuid4()))
    qau.physicalQuantity = esdl.PhysicalQuantityEnum.ENERGY
    qau.multiplier = esdl.MultiplierEnum.TERA
    qau.unit = esdl.UnitEnum.JOULE
    test_qau("Energy in TeraJoule", qau)
        def use_part_of_potential(pot_id, percentage):
            """
            Use part of a SolarPotential to install a PVInstallation

            :param pot_id: id of the SolarPotential
            :param percentage: percentage (0-100) of the SolarPotential that should be installed as a PVInstallation
            :return: None
            """
            with self.flask_app.app_context():
                esh = get_handler()
                active_es_id = get_session('active_es_id')

                pot = esh.get_by_id(active_es_id, pot_id)
                pot_container = pot.eContainer()

                # Create a PVInstallation instance and attach a profile with the percentage of the potential that
                # will be 'installed'
                pv_installation = esdl.PVInstallation(id=str(uuid.uuid4()),
                                                      name="PV Installation")
                pv_outport = esdl.OutPort(id=str(uuid.uuid4()), name="Out")
                pv_profile = esdl.SingleValue(id=str(uuid.uuid4()),
                                              name="PV production",
                                              value=pot.value * percentage /
                                              100)
                # Assume kWh for now, Geodan should communicate this in the ESDL in the end
                pv_profile.profileQuantityAndUnit = esdl.QuantityAndUnitType(
                    physicalQuantity=esdl.PhysicalQuantityEnum.ENERGY,
                    unit=esdl.UnitEnum.WATTHOUR,
                    multiplier=esdl.MultiplierEnum.KILO)
                pv_outport.profile.append(pv_profile)
                pv_installation.port.append(pv_outport)

                add_to_building = False
                # Generate a location on the map for the PV Installation
                if isinstance(pot_container, esdl.AbstractBuilding):
                    # Place the Asset in the top left corner of the BuildingEditor
                    pv_geometry = esdl.Point(lon=10, lat=490, CRS="Simple")
                    pv_installation.geometry = pv_geometry
                    add_to_building = True
                else:
                    pot_geometry = pot.geometry
                    if isinstance(pot_geometry, esdl.Point):
                        # Place the Asset with a small offset from the SolarPotential marker
                        pv_geometry = esdl.Point(lon=pot_geometry.lon + 0.001,
                                                 lat=pot_geometry.lat - 0.001)
                        pv_installation.geometry = pv_geometry
                    else:
                        logger.warning(
                            'Using potentials with geometry other than esdl.Point not supported yet'
                        )

                # Add the PVInstallation to the same container as the SolarPotential (Area or Building)
                pot_container.asset.append(pv_installation)
                esh.add_object_to_dict(active_es_id,
                                       pv_installation,
                                       recursive=True)

                # Adapt the potential (substract the installed value)
                pot.value = pot.value * (100 - percentage) / 100

                # Emit the information to the front-end
                asset_list = []
                port_list = [{
                    'name': pv_outport.name,
                    'id': pv_outport.id,
                    'type': type(pv_outport).__name__,
                    'conn_to': []
                }]
                capability_type = ESDLAsset.get_asset_capability_type(
                    pv_installation)
                asset_list.append([
                    'point', 'asset', pv_installation.name, pv_installation.id,
                    type(pv_installation).__name__,
                    [pv_geometry.lat, pv_geometry.lon], port_list,
                    capability_type
                ])
                emit(
                    'add_esdl_objects', {
                        'es_id': active_es_id,
                        'add_to_building': add_to_building,
                        'asset_pot_list': asset_list,
                        'zoom': False
                    })
Ejemplo n.º 11
0
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Contributors:
#      TNO         - Initial implementation
#  Manager:
#      TNO

from extensions.vue_backend.cost_information import _change_cost_unit
from esdl.esdl_handler import EnergySystemHandler
from uuid import uuid4
from esdl import esdl
import re

cost_unit_string = "EUR/kWh/yr"
qau = esdl.QuantityAndUnitType(id=str(uuid4()), physicalQuantity=esdl.PhysicalQuantityEnum.COST, description='Cost in '+cost_unit_string)
_change_cost_unit(qau, cost_unit_string)
print(EnergySystemHandler.attr_to_dict(qau))

if re.match(r"\w+/kWh", cost_unit_string):
    print('yes')
else:
    print('no')

if re.match(r".+/yr$", cost_unit_string):
    print("\yr")
    qau.perTimeUnit = esdl.TimeUnitEnum.YEAR
else:
    print('no /yr')