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
def load_external_ref(): rset = ResourceSet() rset.resource_factory['esdl'] = XMLResource rset.resource_factory['*'] = XMLResource #car_rs = rset.get_resource(HttpURI('https://edr.hesi.energy/store/esdl/80e3ac6a-94b1-4a85-a0d1-a68de4251243?format=xml')) #units_rs = rset.get_resource(HttpURI('http://localhost:9080/store/resource/public/QuantityAndUnits.esdl')) #es_rs = rset.get_resource(URI('ES with external ref.esdl')) es_rs = rset.get_resource( ESDLDriveHttpURI( 'http://localhost:9080/store/resource/public/ES%20with%20external%20ref.esdl' )) print('initial rset', rset.resources) es = es_rs.contents[0] # uri = StringURI('http://test.esdl') # es_rs.save(uri) # string_esdl = uri.getvalue() # rset2 = ResourceSet() # rset2.resource_factory['esdl'] = XMLResource # rset2.resource_factory['*'] = XMLResource # # uri2 = StringURI('string://test2.esdl', text=string_esdl) # es_rs2 = rset2.create_resource(uri2) # es_rs2.load() # #es_rs2 = rset2.get_resource(uri=uri2) # es2 = es_rs2.contents[0] #uri = StringURI('to_string_' + 'es_ref' + '.esdl') #es_rs.save(uri) #print(uri.getvalue()) print('before access, new rset:', rset.resources) ref = es.energySystemInformation.carriers.carrier[ 0].energyContentUnit.reference print(qau_to_string(ref)) print(EnergySystemHandler.attr_to_dict(ref)) print(list(rset.resources.values())[1].contents[0].id) print(rset.resources)
from esdl import esdl from esdl.processing.ESDLQuantityAndUnits import * from esdl.esdl_handler import EnergySystemHandler esdl.QuantityAndUnitType.__repr__ = \ lambda x: '{}'.format(EnergySystemHandler.attr_to_dict(x)) def test_qau(descr, qau): print("{}:".format(descr)) 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()))
# # 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')