def add_asset_to_asset_list(asset_list, asset): port_list = [] ports = asset.port for p in ports: conn_to_ids = [cp.id for cp in p.connectedTo] profile = p.profile profile_info_list = [] p_carr_id = None if p.carrier: p_carr_id = p.carrier.id if profile: profile_info_list = [] # generate_profile_info(profile) port_list.append({ 'name': p.name, 'id': p.id, 'type': type(p).__name__, 'conn_to': conn_to_ids, 'profile': profile_info_list, 'carrier': p_carr_id }) state = asset_state_to_ui(asset) geom = asset.geometry if geom: if isinstance(geom, esdl.Point): lat = geom.lat lon = geom.lon capability_type = ESDLAsset.get_asset_capability_type(asset) attrs = get_tooltip_asset_attrs(asset, 'marker') add_spatial_attributes(asset, attrs) asset_list.append([ 'point', 'asset', asset.name, asset.id, type(asset).__name__, [lat, lon], attrs, state, port_list, capability_type ]) if isinstance(geom, esdl.Line): coords = [] for point in geom.point: coords.append([point.lat, point.lon]) attrs = get_tooltip_asset_attrs(asset, 'line') add_spatial_attributes(asset, attrs) asset_list.append([ 'line', 'asset', asset.name, asset.id, type(asset).__name__, coords, attrs, state, port_list ]) if isinstance(geom, esdl.Polygon): coords = ESDLGeometry.parse_esdl_subpolygon(geom.exterior, False) # [lon, lat] coords = ESDLGeometry.exchange_coordinates( coords) # --> [lat, lon] capability_type = ESDLAsset.get_asset_capability_type(asset) attrs = get_tooltip_asset_attrs(asset, 'polygon') add_spatial_attributes(asset, attrs) asset_list.append([ 'polygon', 'asset', asset.name, asset.id, type(asset).__name__, coords, attrs, state, port_list, capability_type ])
def energy_asset_to_ui(esh, es_id, asset): # , port_asset_mapping): port_list = [] conn_list = [] ports = asset.port for p in ports: # p_asset = port_asset_mapping[p.id] p_asset = get_asset_and_coord_from_port_id(esh, es_id, p.id) p_asset_coord = p_asset['coord'] # get proper coordinate if asset is line conn_to = [cp.id for cp in p.connectedTo] profile = p.profile profile_info_list = [] if profile: profile_info_list = generate_profile_info(profile) port_list.append \ ({'name': p.name, 'id': p.id, 'type': type(p).__name__, 'conn_to': conn_to, 'profile': profile_info_list}) if conn_to: # conn_to_list = conn_to.split(' ') # connectedTo attribute is list of port ID's separated by a space for id in conn_to: # pc_asset = port_asset_mapping[id] pc_asset = get_asset_and_coord_from_port_id(esh, es_id, id) pc_asset_coord = pc_asset['coord'] conn_list.append \ ({'from-port-id': p.id, 'from-asset-id': p_asset['asset'].id, 'from-asset-coord': p_asset_coord, 'to-port-id': id, 'to-asset-id': pc_asset['asset'].id, 'to-asset-coord': pc_asset_coord}) geom = asset.geometry if geom: if isinstance(geom, esdl.Point): lat = geom.lat lon = geom.lon capability_type = ESDLAsset.get_asset_capability_type(asset) return ['point', 'asset', asset.name, asset.id, type(asset).__name__, [lat, lon], port_list, capability_type], conn_list elif isinstance(geom, esdl.Line): coords = [] for point in geom.point: coords.append([point.lat, point.lon]) return ['line', 'asset', asset.name, asset.id, type(asset).__name__, coords, port_list], conn_list elif isinstance(geom, esdl.Polygon): if isinstance(asset, esdl.WindParc) or isinstance(asset, esdl.PVParc) or isinstance(asset, esdl.WindPark) \ or isinstance(asset, esdl.PVPark): coords = ESDLGeometry.parse_esdl_subpolygon(geom.exterior, False) # [lon, lat] coords = ESDLGeometry.exchange_coordinates(coords) # --> [lat, lon] capability_type = ESDLAsset.get_asset_capability_type(asset) # print(coords) return ['polygon', 'asset', asset.name, asset.id, type(asset).__name__, coords, port_list, capability_type], conn_list else: return [], []
def process_area(esh, es_id, asset_list, building_list, area_bld_list, conn_list, area, level): area_bld_list.append(['Area', area.id, area.name, level]) # process subareas for ar in area.area: process_area(esh, es_id, asset_list, building_list, area_bld_list, conn_list, ar, level+1) # process assets in area for asset in area.asset: if isinstance(asset, esdl.AbstractBuilding): process_building(esh, es_id, asset_list, building_list, area_bld_list, conn_list, asset, False, level+1) if isinstance(asset, esdl.EnergyAsset): port_list = [] ports = asset.port for p in ports: p_asset = get_asset_and_coord_from_port_id(esh, es_id, p.id) p_asset_coord = p_asset['coord'] # get proper coordinate if asset is line conn_to_ids = [cp.id for cp in p.connectedTo] profile = p.profile profile_info_list = [] p_carr_id = None if p.carrier: p_carr_id = p.carrier.id if profile: profile_info_list = generate_profile_info(profile) port_list.append({'name': p.name, 'id': p.id, 'type': type(p).__name__, 'conn_to': conn_to_ids, 'profile': profile_info_list, 'carrier': p_carr_id}) if conn_to_ids: for pc in p.connectedTo: pc_asset = get_asset_and_coord_from_port_id(esh, es_id, pc.id) if pc_asset['asset'].containingBuilding: bld_pc_asset = pc_asset['asset'].containingBuilding if bld_pc_asset.geometry: if isinstance(bld_pc_asset.geometry, esdl.Point): pc_asset_coord = (bld_pc_asset.geometry.lat, bld_pc_asset.geometry.lon) elif isinstance(bld_pc_asset.geometry, esdl.Polygon): pc_asset_coord = ESDLGeometry.calculate_polygon_center(bld_pc_asset.geometry) else: pc_asset_coord = pc_asset['coord'] pc_carr_id = None if pc.carrier: pc_carr_id = pc.carrier.id conn_list.append({'from-port-id': p.id, 'from-port-carrier': p_carr_id, 'from-asset-id': p_asset['asset'].id, 'from-asset-coord': p_asset_coord, 'to-port-id': pc.id, 'to-port-carrier': pc_carr_id, 'to-asset-id': pc_asset['asset'].id, 'to-asset-coord': pc_asset_coord}) geom = asset.geometry if geom: if isinstance(geom, esdl.Point): lat = geom.lat lon = geom.lon capability_type = ESDLAsset.get_asset_capability_type(asset) asset_list.append(['point', 'asset', asset.name, asset.id, type(asset).__name__, [lat, lon], port_list, capability_type]) if isinstance(geom, esdl.Line): coords = [] for point in geom.point: coords.append([point.lat, point.lon]) asset_list.append(['line', 'asset', asset.name, asset.id, type(asset).__name__, coords, port_list]) if isinstance(geom, esdl.Polygon): # if isinstance(asset, esdl.WindParc) or isinstance(asset, esdl.PVParc) or isinstance(asset, esdl.WindPark) or isinstance(asset, esdl.PVPark): coords = ESDLGeometry.parse_esdl_subpolygon(geom.exterior, False) # [lon, lat] coords = ESDLGeometry.exchange_coordinates(coords) # --> [lat, lon] capability_type = ESDLAsset.get_asset_capability_type(asset) # print(coords) asset_list.append(['polygon', 'asset', asset.name, asset.id, type(asset).__name__, coords, port_list, capability_type]) for potential in area.potential: geom = potential.geometry if geom: if isinstance(geom, esdl.Point): lat = geom.lat lon = geom.lon asset_list.append( ['point', 'potential', potential.name, potential.id, type(potential).__name__, [lat, lon]]) if isinstance(geom, esdl.Polygon): coords = [] for point in geom.exterior.point: coords.append([point.lat, point.lon]) asset_list.append(['polygon', 'potential', potential.name, potential.id, type(potential).__name__, coords])
def process_building(esh, es_id, asset_list, building_list, area_bld_list, conn_list, building, bld_editor, level): # Add building to list that is shown in a dropdown at the top area_bld_list.append(['Building', building.id, building.name, level]) # Determine if building has assets building_has_assets = False if building.asset: for basset in building.asset: if isinstance(basset, esdl.EnergyAsset): building_has_assets = True break # Generate information for drawing building (as a point or a polygon) if isinstance(building, esdl.Building) or isinstance(building, esdl.AggregatedBuilding): geometry = building.geometry bld_KPIs = create_building_KPIs(building) if geometry: if isinstance(geometry, esdl.Point): building_list.append( ['point', building.name, building.id, type(building).__name__, [geometry.lat, geometry.lon], building_has_assets, bld_KPIs]) bld_coord = (geometry.lat, geometry.lon) elif isinstance(geometry, esdl.Polygon): coords = ESDLGeometry.parse_esdl_subpolygon(building.geometry.exterior, False) # [lon, lat] coords = ESDLGeometry.exchange_coordinates(coords) # --> [lat, lon] # building_list.append(['polygon', building.name, building.id, type(building).__name__, coords, building_has_assets]) boundary = ESDLGeometry.create_boundary_from_geometry(geometry) building_list.append(['polygon', building.name, building.id, type(building).__name__, boundary['coordinates'], building_has_assets, bld_KPIs]) # bld_coord = coords bld_coord = ESDLGeometry.calculate_polygon_center(geometry) elif building.containingBuilding: # BuildingUnit bld_geom = building.containingBuilding.geometry if bld_geom: if isinstance(bld_geom, esdl.Point): bld_coord = (bld_geom.lat, bld_geom.lon) elif isinstance(bld_geom, esdl.Polygon): bld_coord = ESDLGeometry.calculate_polygon_center(bld_geom) # Iterate over all assets in building to gather all required information for basset in building.asset: if isinstance(basset, esdl.AbstractBuilding): process_building(esh, es_id, asset_list, building_list, area_bld_list, conn_list, basset, bld_editor, level + 1) else: # Create a list of ports for this asset port_list = [] ports = basset.port for p in ports: conn_to = p.connectedTo conn_to_id_list = [ct.id for ct in conn_to] # TODO: add profile_info and carrier port_list.append({'name': p.name, 'id': p.id, 'type': type(p).__name__, 'conn_to': conn_to_id_list}) geom = basset.geometry coord = () if geom: # Individual asset in Building has its own geometry information if isinstance(geom, esdl.Point): lat = geom.lat lon = geom.lon coord = (lat, lon) capability_type = ESDLAsset.get_asset_capability_type(basset) if bld_editor: asset_list.append(['point', 'asset', basset.name, basset.id, type(basset).__name__, [lat, lon], port_list, capability_type]) else: send_alert("Assets within buildings with geometry other than esdl.Point are not supported") # Inherit geometry from containing building # if level > 0: # coord = bld_coord ports = basset.port for p in ports: p_carr_id = None if p.carrier: p_carr_id = p.carrier.id conn_to = p.connectedTo if conn_to: for pc in conn_to: in_different_buildings = False pc_asset = get_asset_and_coord_from_port_id(esh, es_id, pc.id) # If the asset the current asset connects to, is in a building... if pc_asset['asset'].containingBuilding: bld_pc_asset = pc_asset['asset'].containingBuilding bld_basset = basset.containingBuilding # If the asset is in a different building ... if not bld_pc_asset == bld_basset: in_different_buildings = True if bld_pc_asset.geometry: if bld_editor: # ... connect to the left border pc_asset_coord = (coord[0], 0) else: # ... use the building coordinate instead of the asset coordinate if isinstance(bld_pc_asset.geometry, esdl.Point): pc_asset_coord = (bld_pc_asset.geometry.lat, bld_pc_asset.geometry.lon) elif isinstance(bld_pc_asset.geometry, esdl.Polygon): pc_asset_coord = ESDLGeometry.calculate_polygon_center(bld_pc_asset.geometry) # If connecting to a building outside of the current, replace current asset # coordinates with building coordinates too if not bld_editor: coord = bld_coord else: # asset is in the same building, use asset's own coordinates pc_asset_coord = pc_asset['coord'] else: # other asset is not in a building if bld_editor: # ... connect to the left border pc_asset_coord = (coord[0], 0) else: # ... just use asset's location pc_asset_coord = pc_asset['coord'] pc_carr_id = None if pc.carrier: pc_carr_id = pc.carrier.id # Add connections if we're editing a building or if the connection is between two different buildings # ( The case of an asset in an area that is connected with an asset in a building is handled # in process_area (now all connections are added twice, from both sides) ) if bld_editor or in_different_buildings: conn_list.append({'from-port-id': p.id, 'from-port-carrier': p_carr_id, 'from-asset-id': basset.id, 'from-asset-coord': coord, 'to-port-id': pc.id, 'to-port-carrier': pc_carr_id, 'to-asset-id': pc_asset['asset'].id, 'to-asset-coord': pc_asset_coord}) if bld_editor: for potential in building.potential: geom = potential.geometry if geom: if isinstance(geom, esdl.Point): lat = geom.lat lon = geom.lon asset_list.append( ['point', 'potential', potential.name, potential.id, type(potential).__name__, [lat, lon]])