From c3e570b87f5c34fc75681629de9ecfd81146df41 Mon Sep 17 00:00:00 2001 From: "tobias.beckhoelter" Date: Wed, 25 Jul 2018 17:25:11 +0200 Subject: [PATCH 1/7] add networktype bidirectional, node type supply_bidirectional and attr is_supply_bidirectional #10 --- uesgraphs/uesgraph.py | 62 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/uesgraphs/uesgraph.py b/uesgraphs/uesgraph.py index bc6bf1e..b66d642 100644 --- a/uesgraphs/uesgraph.py +++ b/uesgraphs/uesgraph.py @@ -51,6 +51,10 @@ class UESGraph(nx.Graph): Dictionary contains nodelists for all cooling networks. Keys are names of the networks in str format, values are lists of all node ids that belong to the network + nodelists_bidirectional : dict + Dictionary contains nodelists for all bidirectional networks. Keys are + names of the networks in str format, values are lists of all node ids + that belong to the network nodelists_electricity : dict Dictionary contains nodelists for all electricity networks. Keys are names of the networks in str format, values are lists of all node @@ -102,12 +106,14 @@ def __init__(self): self.nodelist_building = [] self.nodelists_heating = {'default': []} self.nodelists_cooling = {'default': []} + self.nodelists_bidirectional = {'default': []} self.nodelists_electricity = {'default': []} self.nodelists_gas = {'default': []} self.nodelists_others = {'default': []} self.network_types = ['heating', 'cooling', + 'bidirectional', 'electricity', 'gas', 'others'] @@ -212,6 +218,7 @@ def _update_min_max_positions(self, position): def add_building(self, name=None, position=None, is_supply_heating=False, is_supply_cooling=False, + is_supply_bidirectional=False, is_supply_electricity=False, is_supply_gas=False, is_supply_other=False, @@ -230,6 +237,9 @@ def add_building(self, name=None, position=None, True if the building contains a heat supply unit, False if not is_supply_cooling : boolean True if the building contains a cooling supply unit, False if not + is_supply_bidirectional : boolean + True if the building contains a bidirectional supply unit, False + if not is_supply_electricity : boolean True if the building contains an electricity supply unit, False if not @@ -260,6 +270,7 @@ def add_building(self, name=None, position=None, 'position': position, 'is_supply_heating': is_supply_heating, 'is_supply_cooling': is_supply_cooling, + 'is_supply_bidirectional': is_supply_bidirectional, 'is_supply_electricity': is_supply_electricity, 'is_supply_gas': is_supply_gas, 'is_supply_other': is_supply_other} @@ -445,6 +456,8 @@ def add_network_node(self, nodelist = self.nodelists_heating[network_id] elif network_type == 'cooling': nodelist = self.nodelists_cooling[network_id] + elif network_type == 'bidirectional': + nodelist = self.nodelists_bidirectional[network_id] elif network_type == 'electricity': nodelist = self.nodelists_electricity[network_id] elif network_type == 'gas': @@ -475,6 +488,8 @@ def add_network_node(self, nodelist.append(node_number) elif network_type == 'cooling': nodelist.append(node_number) + elif network_type == 'bidirectional': + nodelist.append(node_number) elif network_type == 'electricity': nodelist.append(node_number) elif network_type == 'gas': @@ -489,6 +504,8 @@ def add_network_node(self, nodelist.append(node_number) elif network_type == 'cooling': nodelist.append(node_number) + elif network_type == 'bidirectional': + nodelist.append(node_number) elif network_type == 'electricity': nodelist.append(node_number) elif network_type == 'gas': @@ -510,6 +527,7 @@ def remove_network_node(self, node_number): """ # Search for occurrence of node number within different network dicts network_list = [self.nodelists_heating, self.nodelists_cooling, + self.nodelists_bidirectional, self.nodelists_electricity, self.nodelists_gas, self.nodelists_others] @@ -608,6 +626,8 @@ def create_subgraphs(self, network_type, all_buildings=True, streets=False): nodelists = self.nodelists_heating elif network_type == 'cooling': nodelists = self.nodelists_cooling + elif network_type == 'bidirectional': + nodelists = self.nodelists_bidirectional elif network_type == 'electricity': nodelists = self.nodelists_electricity elif network_type == 'gas': @@ -652,6 +672,10 @@ def create_subgraphs(self, network_type, all_buildings=True, streets=False): elif network_type == 'cooling': H.nodelists_cooling[ network_id] = self.nodelists_cooling[network_id] + elif network_type == 'bidirectional': + H.nodelists_bidirectional[ + network_id] = self.nodelists_bidirectional[ + network_id] elif network_type == 'electricity': H.nodelists_electricity[ network_id] = self.nodelists_electricity[ @@ -689,6 +713,8 @@ def create_subgraphs(self, network_type, all_buildings=True, streets=False): if (self.nodes[building]['is_supply_heating'] is False and self.nodes[building][ 'is_supply_cooling'] is False and + self.nodes[building][ + 'is_supply_bidirectional'] is False and self.nodes[building][ 'is_supply_electricity'] is False and self.nodes[building][ @@ -794,6 +820,29 @@ def from_json(self, path, network_type, check_overlap=False): # TODO: This currently only supports heating and cooling supplies if 'supply' in node['node_type']: supply_id = node['name'] + if 'bidirectional' in node['node_type']: + if (node['is_supply_heating'] & node['is_supply_cooling']): + new_node = self.add_building( + name=supply_id, + position=this_position, + is_supply_heating=True, + is_supply_cooling=True, + is_supply_bidirectional=True) + elif node['is_supply_heating']: + new_node = self.add_building( + name=supply_id, + position=this_position, + is_supply_heating=True) + elif node['is_supply_cooling']: + new_node = self.add_building( + name=supply_id, + position=this_position, + is_supply_cooling=True) + else: + new_node = self.add_building( + name=supply_id, + position=this_position, + is_supply_bidirecitonal=True) if 'heating' in node['node_type']: new_node = self.add_building(name=supply_id, position=this_position, @@ -822,6 +871,7 @@ def from_json(self, path, network_type, check_overlap=False): 'name', 'is_supply_heating', 'is_supply_cooling', + 'is_supply_bidirectional', 'node_type', ] for attrib in node.keys(): @@ -941,6 +991,8 @@ def to_json(self, path, name, description='json export from uesgraph', if 'is_supply_cooling' in self.nodes[node]: if self.nodes[node]['is_supply_cooling'] is True: node_type = 'supply_cooling' + if 'bidirectional' in node_type: + node_type = 'supply_bidirectional' nodes[-1]['node_type'] = node_type if all_data is True: for key in self.nodes[node]: @@ -1389,6 +1441,8 @@ def number_of_nodes(self, node_type): nodelists = list(self.nodelists_heating.values()) elif node_type == 'cooling': nodelists = list(self.nodelists_cooling.values()) + elif node_type == 'bidirectional': + nodelists = list(self.nodelists_bidirectional.values()) elif node_type == 'electricity': nodelists = list(self.nodelists_electricity.values()) elif node_type == 'gas': @@ -1530,6 +1584,8 @@ def group_nodes(node, group): nodelists = self.nodelists_heating elif network_type == 'cooling': nodelists = self.nodelists_cooling + elif network_type == 'bidirectional': + nodelists = self.nodelists_bidirectional elif network_type == 'electricity': nodelists = self.nodelists_electricity elif network_type == 'gas': @@ -1648,6 +1704,10 @@ def remove_unconnected_nodes(self, network_type, elif network_type == 'cooling': is_supply = 'is_supply_cooling' nodelist = self.nodelists_cooling[network_id] + # TODO: not all supply types in bidir. networks(missing just heat/cool) + elif network_type == 'bidirectional': + is_supply = 'is_supply_bidirectional' + nodelist = self.nodelists_bidirectional[network_id] supplies = [] for node in self.nodelist_building: @@ -1734,6 +1794,8 @@ def remove_dead_ends(self, network_type, network_id='default'): nodelist = self.nodelists_heating[network_id] elif network_type == 'cooling': nodelist = self.nodelists_cooling[network_id] + elif network_type == 'bidirectional': + nodelist = self.nodelists_bidirectional[network_id] def remove_end(end): """Deletes a dead end and follows up on its neighbor for recursion From b7eaceb40adf7276baa2be4eef457ef3650ad734 Mon Sep 17 00:00:00 2001 From: "tobias.beckhoelter" Date: Wed, 25 Jul 2018 17:37:30 +0200 Subject: [PATCH 2/7] add bidirectional in add_network() #10 --- uesgraphs/uesgraph.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/uesgraphs/uesgraph.py b/uesgraphs/uesgraph.py index b66d642..2e24971 100644 --- a/uesgraphs/uesgraph.py +++ b/uesgraphs/uesgraph.py @@ -180,6 +180,8 @@ def add_network(self, network_type, network_id): self.nodelists_heating[network_id] = [] elif network_type == 'cooling': self.nodelists_cooling[network_id] = [] + elif network_type == 'bidirectional': + self.nodelists_bidirectional[network_id] = [] elif network_type == 'electricity': self.nodelists_electricity[network_id] = [] elif network_type == 'gas': From 052e589b29230d9e7fde2dcf59cd6d7b05677400 Mon Sep 17 00:00:00 2001 From: jsc-tbe Date: Tue, 14 Aug 2018 15:51:19 +0200 Subject: [PATCH 3/7] back to the start #10 --- uesgraphs/uesgraph.py | 64 ------------------------------------------- 1 file changed, 64 deletions(-) diff --git a/uesgraphs/uesgraph.py b/uesgraphs/uesgraph.py index 2e24971..bc6bf1e 100644 --- a/uesgraphs/uesgraph.py +++ b/uesgraphs/uesgraph.py @@ -51,10 +51,6 @@ class UESGraph(nx.Graph): Dictionary contains nodelists for all cooling networks. Keys are names of the networks in str format, values are lists of all node ids that belong to the network - nodelists_bidirectional : dict - Dictionary contains nodelists for all bidirectional networks. Keys are - names of the networks in str format, values are lists of all node ids - that belong to the network nodelists_electricity : dict Dictionary contains nodelists for all electricity networks. Keys are names of the networks in str format, values are lists of all node @@ -106,14 +102,12 @@ def __init__(self): self.nodelist_building = [] self.nodelists_heating = {'default': []} self.nodelists_cooling = {'default': []} - self.nodelists_bidirectional = {'default': []} self.nodelists_electricity = {'default': []} self.nodelists_gas = {'default': []} self.nodelists_others = {'default': []} self.network_types = ['heating', 'cooling', - 'bidirectional', 'electricity', 'gas', 'others'] @@ -180,8 +174,6 @@ def add_network(self, network_type, network_id): self.nodelists_heating[network_id] = [] elif network_type == 'cooling': self.nodelists_cooling[network_id] = [] - elif network_type == 'bidirectional': - self.nodelists_bidirectional[network_id] = [] elif network_type == 'electricity': self.nodelists_electricity[network_id] = [] elif network_type == 'gas': @@ -220,7 +212,6 @@ def _update_min_max_positions(self, position): def add_building(self, name=None, position=None, is_supply_heating=False, is_supply_cooling=False, - is_supply_bidirectional=False, is_supply_electricity=False, is_supply_gas=False, is_supply_other=False, @@ -239,9 +230,6 @@ def add_building(self, name=None, position=None, True if the building contains a heat supply unit, False if not is_supply_cooling : boolean True if the building contains a cooling supply unit, False if not - is_supply_bidirectional : boolean - True if the building contains a bidirectional supply unit, False - if not is_supply_electricity : boolean True if the building contains an electricity supply unit, False if not @@ -272,7 +260,6 @@ def add_building(self, name=None, position=None, 'position': position, 'is_supply_heating': is_supply_heating, 'is_supply_cooling': is_supply_cooling, - 'is_supply_bidirectional': is_supply_bidirectional, 'is_supply_electricity': is_supply_electricity, 'is_supply_gas': is_supply_gas, 'is_supply_other': is_supply_other} @@ -458,8 +445,6 @@ def add_network_node(self, nodelist = self.nodelists_heating[network_id] elif network_type == 'cooling': nodelist = self.nodelists_cooling[network_id] - elif network_type == 'bidirectional': - nodelist = self.nodelists_bidirectional[network_id] elif network_type == 'electricity': nodelist = self.nodelists_electricity[network_id] elif network_type == 'gas': @@ -490,8 +475,6 @@ def add_network_node(self, nodelist.append(node_number) elif network_type == 'cooling': nodelist.append(node_number) - elif network_type == 'bidirectional': - nodelist.append(node_number) elif network_type == 'electricity': nodelist.append(node_number) elif network_type == 'gas': @@ -506,8 +489,6 @@ def add_network_node(self, nodelist.append(node_number) elif network_type == 'cooling': nodelist.append(node_number) - elif network_type == 'bidirectional': - nodelist.append(node_number) elif network_type == 'electricity': nodelist.append(node_number) elif network_type == 'gas': @@ -529,7 +510,6 @@ def remove_network_node(self, node_number): """ # Search for occurrence of node number within different network dicts network_list = [self.nodelists_heating, self.nodelists_cooling, - self.nodelists_bidirectional, self.nodelists_electricity, self.nodelists_gas, self.nodelists_others] @@ -628,8 +608,6 @@ def create_subgraphs(self, network_type, all_buildings=True, streets=False): nodelists = self.nodelists_heating elif network_type == 'cooling': nodelists = self.nodelists_cooling - elif network_type == 'bidirectional': - nodelists = self.nodelists_bidirectional elif network_type == 'electricity': nodelists = self.nodelists_electricity elif network_type == 'gas': @@ -674,10 +652,6 @@ def create_subgraphs(self, network_type, all_buildings=True, streets=False): elif network_type == 'cooling': H.nodelists_cooling[ network_id] = self.nodelists_cooling[network_id] - elif network_type == 'bidirectional': - H.nodelists_bidirectional[ - network_id] = self.nodelists_bidirectional[ - network_id] elif network_type == 'electricity': H.nodelists_electricity[ network_id] = self.nodelists_electricity[ @@ -715,8 +689,6 @@ def create_subgraphs(self, network_type, all_buildings=True, streets=False): if (self.nodes[building]['is_supply_heating'] is False and self.nodes[building][ 'is_supply_cooling'] is False and - self.nodes[building][ - 'is_supply_bidirectional'] is False and self.nodes[building][ 'is_supply_electricity'] is False and self.nodes[building][ @@ -822,29 +794,6 @@ def from_json(self, path, network_type, check_overlap=False): # TODO: This currently only supports heating and cooling supplies if 'supply' in node['node_type']: supply_id = node['name'] - if 'bidirectional' in node['node_type']: - if (node['is_supply_heating'] & node['is_supply_cooling']): - new_node = self.add_building( - name=supply_id, - position=this_position, - is_supply_heating=True, - is_supply_cooling=True, - is_supply_bidirectional=True) - elif node['is_supply_heating']: - new_node = self.add_building( - name=supply_id, - position=this_position, - is_supply_heating=True) - elif node['is_supply_cooling']: - new_node = self.add_building( - name=supply_id, - position=this_position, - is_supply_cooling=True) - else: - new_node = self.add_building( - name=supply_id, - position=this_position, - is_supply_bidirecitonal=True) if 'heating' in node['node_type']: new_node = self.add_building(name=supply_id, position=this_position, @@ -873,7 +822,6 @@ def from_json(self, path, network_type, check_overlap=False): 'name', 'is_supply_heating', 'is_supply_cooling', - 'is_supply_bidirectional', 'node_type', ] for attrib in node.keys(): @@ -993,8 +941,6 @@ def to_json(self, path, name, description='json export from uesgraph', if 'is_supply_cooling' in self.nodes[node]: if self.nodes[node]['is_supply_cooling'] is True: node_type = 'supply_cooling' - if 'bidirectional' in node_type: - node_type = 'supply_bidirectional' nodes[-1]['node_type'] = node_type if all_data is True: for key in self.nodes[node]: @@ -1443,8 +1389,6 @@ def number_of_nodes(self, node_type): nodelists = list(self.nodelists_heating.values()) elif node_type == 'cooling': nodelists = list(self.nodelists_cooling.values()) - elif node_type == 'bidirectional': - nodelists = list(self.nodelists_bidirectional.values()) elif node_type == 'electricity': nodelists = list(self.nodelists_electricity.values()) elif node_type == 'gas': @@ -1586,8 +1530,6 @@ def group_nodes(node, group): nodelists = self.nodelists_heating elif network_type == 'cooling': nodelists = self.nodelists_cooling - elif network_type == 'bidirectional': - nodelists = self.nodelists_bidirectional elif network_type == 'electricity': nodelists = self.nodelists_electricity elif network_type == 'gas': @@ -1706,10 +1648,6 @@ def remove_unconnected_nodes(self, network_type, elif network_type == 'cooling': is_supply = 'is_supply_cooling' nodelist = self.nodelists_cooling[network_id] - # TODO: not all supply types in bidir. networks(missing just heat/cool) - elif network_type == 'bidirectional': - is_supply = 'is_supply_bidirectional' - nodelist = self.nodelists_bidirectional[network_id] supplies = [] for node in self.nodelist_building: @@ -1796,8 +1734,6 @@ def remove_dead_ends(self, network_type, network_id='default'): nodelist = self.nodelists_heating[network_id] elif network_type == 'cooling': nodelist = self.nodelists_cooling[network_id] - elif network_type == 'bidirectional': - nodelist = self.nodelists_bidirectional[network_id] def remove_end(end): """Deletes a dead end and follows up on its neighbor for recursion From 4b8704ae6d77157dc9ab4c081ef9419c50667f8b Mon Sep 17 00:00:00 2001 From: jsc-tbe Date: Wed, 15 Aug 2018 12:32:45 +0200 Subject: [PATCH 4/7] add node_type supply_heating_cooling in import/export json methods #10 --- uesgraphs/uesgraph.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/uesgraphs/uesgraph.py b/uesgraphs/uesgraph.py index bc6bf1e..7278657 100644 --- a/uesgraphs/uesgraph.py +++ b/uesgraphs/uesgraph.py @@ -794,11 +794,17 @@ def from_json(self, path, network_type, check_overlap=False): # TODO: This currently only supports heating and cooling supplies if 'supply' in node['node_type']: supply_id = node['name'] - if 'heating' in node['node_type']: + if ('heating' in node['node_type'] and + 'cooling' in node['node_type']): + new_node = self.add_building(name=supply_id, + position=this_position, + is_supply_heating=True, + is_supply_cooling=True) + elif 'heating' in node['node_type']: new_node = self.add_building(name=supply_id, position=this_position, is_supply_heating=True) - if 'cooling' in node['node_type']: + elif 'cooling' in node['node_type']: new_node = self.add_building(name=supply_id, position=this_position, is_supply_cooling=True) @@ -935,10 +941,15 @@ def to_json(self, path, name, description='json export from uesgraph', if 'node_type' in self.nodes[node]: node_type = self.nodes[node]['node_type'] if 'building' in node_type: - if 'is_supply_heating' in self.nodes[node]: + if ('is_supply_heating' in self.nodes[node] and + 'is_supply_cooling' in self.nodes[node]): + if (self.nodes[node]['is_supply_heating'] is True and + self.nodes[node]['is_supply_cooling'] is True): + node_type = 'supply_heating_cooling' + elif 'is_supply_heating' in self.nodes[node]: if self.nodes[node]['is_supply_heating'] is True: node_type = 'supply_heating' - if 'is_supply_cooling' in self.nodes[node]: + elif 'is_supply_cooling' in self.nodes[node]: if self.nodes[node]['is_supply_cooling'] is True: node_type = 'supply_cooling' nodes[-1]['node_type'] = node_type From 1b6819b7711a8f3648bea8ae3ab2d42ae351e6d2 Mon Sep 17 00:00:00 2001 From: jsc-tbe Date: Wed, 29 Aug 2018 10:46:58 +0200 Subject: [PATCH 5/7] delete new node type, instead use node type building #10 --- uesgraphs/uesgraph.py | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/uesgraphs/uesgraph.py b/uesgraphs/uesgraph.py index 7278657..ee04989 100644 --- a/uesgraphs/uesgraph.py +++ b/uesgraphs/uesgraph.py @@ -786,25 +786,38 @@ def from_json(self, path, network_type, check_overlap=False): # Add buildings if 'building' in node['node_type']: building_id = node['name'] - new_node = self.add_building(name=building_id, - position=this_position) + if ('is_supply_heating' in node and + 'is_supply_cooling' in node and + node['is_supply_heating'] is True and + node['is_supply_cooling'] is True): + new_node = self.add_building(name=building_id, + position=this_position, + is_supply_heating=True, + is_supply_cooling=True) + elif ('is_supply_heating' in node and + node['is_supply_heating'] is True): + new_node = self.add_building(name=building_id, + position=this_position, + is_supply_heating=True) + elif ('is_supply_cooling' in node and + node['is_supply_cooling'] is True): + new_node = self.add_building(name=building_id, + position=this_position, + is_supply_cooling=True) + else: + new_node = self.add_building(name=building_id, + position=this_position) # Add supplies # TODO: This currently only supports heating and cooling supplies if 'supply' in node['node_type']: supply_id = node['name'] - if ('heating' in node['node_type'] and - 'cooling' in node['node_type']): - new_node = self.add_building(name=supply_id, - position=this_position, - is_supply_heating=True, - is_supply_cooling=True) - elif 'heating' in node['node_type']: + if 'heating' in node['node_type']: new_node = self.add_building(name=supply_id, position=this_position, is_supply_heating=True) - elif 'cooling' in node['node_type']: + if 'cooling' in node['node_type']: new_node = self.add_building(name=supply_id, position=this_position, is_supply_cooling=True) @@ -945,7 +958,7 @@ def to_json(self, path, name, description='json export from uesgraph', 'is_supply_cooling' in self.nodes[node]): if (self.nodes[node]['is_supply_heating'] is True and self.nodes[node]['is_supply_cooling'] is True): - node_type = 'supply_heating_cooling' + node_type = 'building' elif 'is_supply_heating' in self.nodes[node]: if self.nodes[node]['is_supply_heating'] is True: node_type = 'supply_heating' From fe329b61ac1935d767ae2b7157495bbe9505da21 Mon Sep 17 00:00:00 2001 From: jsc-tbe Date: Thu, 27 Sep 2018 17:39:47 +0200 Subject: [PATCH 6/7] add test for json export and import, with KeyError #10 --- tests/test_uesgraphs.py | 26 ++++++++++++++ uesgraphs/examples/example_uesgraph.py | 50 ++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/tests/test_uesgraphs.py b/tests/test_uesgraphs.py index dfd7f20..ea240bb 100644 --- a/tests/test_uesgraphs.py +++ b/tests/test_uesgraphs.py @@ -199,3 +199,29 @@ def test_remove_dead_ends(self): assert len(example_district.edges()) == 12, msg assert removed == [1015], msg + + def test_to_from_json(self): + """Tests the output and input of an uesgraph to JSON + """ + workspace = ug.make_workspace('json_output') + + example_district = ug.simple_bidirectional_network_model() + example_district.to_json(path=workspace, + name='demo', + all_data=True) + example_district_import = ug.UESGraph() + example_district_import.from_json(path=workspace, + network_type='heating') + + assert (len(example_district_import.nodelist_building) == 5) + + mapping = {} + for b in example_district.nodelist_building: + name = example_district.nodes[b]['name'] + for n in example_district_import.nodelist_building: + if name==example_district_import.nodes[n]['name']: + mapping[b] = n + for b in example_district.nodelist_building: + for k in example_district.nodes[b].keys(): + assert example_district.nodes[b][k] ==\ + example_district_import[mapping[b]][k] \ No newline at end of file diff --git a/uesgraphs/examples/example_uesgraph.py b/uesgraphs/examples/example_uesgraph.py index 882fc70..a9c8611 100644 --- a/uesgraphs/examples/example_uesgraph.py +++ b/uesgraphs/examples/example_uesgraph.py @@ -126,6 +126,56 @@ def simple_dhc_model(): return example_district +def simple_bidirectional_network_model(): + """Initializes an UESGraph object, adds 1 bidirectional network + + Returns + ------- + example_district : uesgraphs.uesgraph.UESGraph object + An UESGraph containing 4 buildings connected to 1 ideal plant. + """ + example_district = ug.UESGraph() + ideal_plant_1 = example_district.add_building(name='idealPlant', + position=Point(1, 2), + is_supply_heating=True, + is_supply_cooling=True) + + building_1 = example_district.add_building(name='building_1', + position=Point(2, 3), + is_supply_heating=True, + is_supply_cooling=True, + input_heat=[1500, 1000, 500], + input_cool=[0, 500, 1000]) + building_2 = example_district.add_building(name='building_2', + position=Point(3, 3), + is_supply_heating=True, + is_supply_cooling=True, + input_heat=[1500, 1000, 500], + input_cool=[0, 500, 1000]) + building_3 = example_district.add_building(name='building_3', + position=Point(4, 3), + is_supply_heating=True, + input_cool=[0, 500, 1000]) + building_4 = example_district.add_building(name='building_4', + position=Point(5, 3), + is_supply_cooling=True, + input_heat=[1500, 1000, 500]) + + n_1 = example_district.add_network_node(network_type='heating', + position=Point(2, 2)) + n_2 = example_district.add_network_node(network_type='heating', + position=Point(3, 2)) + n_3 = example_district.add_network_node(network_type='heating', + position=Point(3, 1)) + example_district.add_edge(ideal_plant_1, n_1) + example_district.add_edge(n_1, building_1) + example_district.add_edge(n_1, n_2) + example_district.add_edge(n_2, building_2) + example_district.add_edge(ideal_plant_1, n_3) + example_district.add_edge(n_3, building_3) + example_district.add_edge(n_3, building_4) + + return example_district def add_more_networks(example_district): """Adds an electric grid to the simple_dhc_model example From 269b9b9c565983e1dc41b86214719ff312f20b04 Mon Sep 17 00:00:00 2001 From: jsc-tbe Date: Thu, 27 Sep 2018 18:06:01 +0200 Subject: [PATCH 7/7] debug unit test #10 --- tests/test_uesgraphs.py | 48 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/tests/test_uesgraphs.py b/tests/test_uesgraphs.py index ea240bb..43ff736 100644 --- a/tests/test_uesgraphs.py +++ b/tests/test_uesgraphs.py @@ -222,6 +222,48 @@ def test_to_from_json(self): if name==example_district_import.nodes[n]['name']: mapping[b] = n for b in example_district.nodelist_building: - for k in example_district.nodes[b].keys(): - assert example_district.nodes[b][k] ==\ - example_district_import[mapping[b]][k] \ No newline at end of file + if example_district.nodes[b]['name'] == 'building_1': + assert example_district_import.nodes[mapping[b]][ + 'is_supply_heating'] is True + assert example_district_import.nodes[mapping[b]][ + 'is_supply_cooling'] is True + assert 'input_heat' in example_district_import.nodes[ + mapping[b]] + assert 'input_cool' in example_district_import.nodes[ + mapping[b]] + elif example_district.nodes[b]['name'] == 'building_2': + assert example_district_import.nodes[mapping[b]][ + 'is_supply_heating'] is True + assert example_district_import.nodes[mapping[b]][ + 'is_supply_cooling'] is True + assert 'input_heat' in example_district_import.nodes[ + mapping[b]] + assert 'input_cool' in example_district_import.nodes[ + mapping[b]] + elif example_district.nodes[b]['name'] == 'building_3': + assert example_district_import.nodes[mapping[b]][ + 'is_supply_heating'] is True + if 'is_supply_cooling' in example_district_import.nodes[ + mapping[b]]: + assert example_district_import.nodes[mapping[b]][ + 'is_supply_cooling'] is False + assert 'input_cool' in example_district_import.nodes[ + mapping[b]] + elif example_district.nodes[b]['name'] == 'building_4': + if 'is_supply_heating' in example_district_import.nodes[ + mapping[b]]: + assert example_district_import.nodes[mapping[b]][ + 'is_supply_heating'] is False + assert example_district_import.nodes[mapping[b]][ + 'is_supply_cooling'] is True + assert 'input_heat' in example_district_import.nodes[ + mapping[b]] + elif example_district.nodes[b]['name'] == 'idealPlant': + assert example_district_import.nodes[mapping[b]][ + 'is_supply_heating'] is True + assert example_district_import.nodes[mapping[b]][ + 'is_supply_cooling'] is True + assert 'input_heat' not in example_district_import.nodes[ + mapping[b]] + assert 'input_cool' not in example_district_import.nodes[ + mapping[b]] \ No newline at end of file