Skip to content

Commit

Permalink
fix variable names, python deps
Browse files Browse the repository at this point in the history
  • Loading branch information
gtfierro committed Nov 11, 2024
1 parent e870439 commit 1cfd72a
Show file tree
Hide file tree
Showing 6 changed files with 626 additions and 133 deletions.
8 changes: 6 additions & 2 deletions buildingmotif/dataclasses/model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dataclasses import dataclass
from functools import cached_property
from typing import TYPE_CHECKING, Dict, List, Optional

import pandas as pd
Expand Down Expand Up @@ -322,9 +323,12 @@ class CompiledModel:
shape_collections: List[ShapeCollection]
_compiled_graph: rdflib.Graph

@property
@cached_property
def graph(self) -> rdflib.Graph:
return self._compiled_graph
g = copy_graph(self._compiled_graph)
for shape_collection in self.shape_collections:
g += shape_collection.graph
return g

def get_manifest(self) -> ShapeCollection:
"""Get the manifest ShapeCollection for this model.
Expand Down
4 changes: 2 additions & 2 deletions buildingmotif/dataclasses/shape_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,10 @@ def gensym():

for pshape in graph.objects(shape, SH.property):
# get the varname if we've already assigned one for this pshape above,
# or generate a new one. When generating a name, use the SH.name field
# or generate a new one. When generating a name, use the SH.name|RDFS.label field
# in the PropertyShape or generate a unique one
name = pshape_vars.get(
pshape, f"?{graph.value(pshape, SH.name) or gensym()}".replace(" ", "_")
pshape, f"?{graph.value(pshape, SH.name|RDFS.label) or gensym()}".replace(" ", "_")
)
path = _sh_path_to_path(graph, graph.value(pshape, SH.path))
qMinCount = graph.value(pshape, SH.qualifiedMinCount) or 0
Expand Down
168 changes: 103 additions & 65 deletions notebooks/Compile-model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,28 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"PREFIX sh: <http://www.w3.org/ns/shacl#>\n",
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n",
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n",
" SELECT ?OAT_AVG ?RAT_AVG ?MAT_AVG ?target WHERE {\n",
"?target rdf:type/rdfs:subClassOf* <https://brickschema.org/schema/Brick#Air_Handling_Unit> .\n",
"?target <https://brickschema.org/schema/Brick#hasPoint> ?MAT_AVG .\n",
" ?MAT_AVG rdf:type/rdfs:subClassOf* <https://brickschema.org/schema/Brick#Mixed_Air_Temperature_Sensor> .\n",
"?target <https://brickschema.org/schema/Brick#hasPoint> ?RAT_AVG .\n",
" ?RAT_AVG rdf:type/rdfs:subClassOf* <https://brickschema.org/schema/Brick#Return_Air_Temperature_Sensor> .\n",
"?target <https://brickschema.org/schema/Brick#hasPoint> ?OAT_AVG .\n",
" ?OAT_AVG rdf:type/rdfs:subClassOf* <https://brickschema.org/schema/Brick#Outside_Air_Temperature_Sensor> .\n",
"\n",
"}\n"
]
},
{
"data": {
"text/html": [
Expand All @@ -180,83 +199,83 @@
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>MAT_AVG</th>\n",
" <th>OAT_AVG</th>\n",
" <th>RAT_AVG</th>\n",
" <th>target</th>\n",
" <th>wc0</th>\n",
" <th>wc1</th>\n",
" <th>wc2</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>http://example.org/building/Perimeter_ZN_1-ZN-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_1-ZN-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_1-ZN-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_1-ZN-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_3-ZN-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_3-ZN-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_3-ZN-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_3-ZN-...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>http://example.org/building/Core_ZN-ZN-PSZ-AC-...</td>\n",
" <td>http://example.org/building/Core_ZN-ZN-PSZ-AC-...</td>\n",
" <td>http://example.org/building/Core_ZN-ZN-PSZ-AC-...</td>\n",
" <td>http://example.org/building/Core_ZN-ZN-PSZ-AC-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_2-ZN-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_2-ZN-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_2-ZN-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_2-ZN-...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>http://example.org/building/Perimeter_ZN_1-ZN-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_1-ZN-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_1-ZN-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_1-ZN-...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>http://example.org/building/Perimeter_ZN_4-ZN-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_4-ZN-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_4-ZN-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_4-ZN-...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>http://example.org/building/Perimeter_ZN_3-ZN-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_3-ZN-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_3-ZN-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_3-ZN-...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>http://example.org/building/Perimeter_ZN_2-ZN-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_2-ZN-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_2-ZN-...</td>\n",
" <td>http://example.org/building/Perimeter_ZN_2-ZN-...</td>\n",
" <td>http://example.org/building/Core_ZN-ZN-PSZ-AC-...</td>\n",
" <td>http://example.org/building/Core_ZN-ZN-PSZ-AC-...</td>\n",
" <td>http://example.org/building/Core_ZN-ZN-PSZ-AC-...</td>\n",
" <td>http://example.org/building/Core_ZN-ZN-PSZ-AC-...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" target \\\n",
"0 http://example.org/building/Perimeter_ZN_1-ZN-... \n",
"1 http://example.org/building/Core_ZN-ZN-PSZ-AC-... \n",
"2 http://example.org/building/Perimeter_ZN_4-ZN-... \n",
"3 http://example.org/building/Perimeter_ZN_3-ZN-... \n",
"4 http://example.org/building/Perimeter_ZN_2-ZN-... \n",
" MAT_AVG \\\n",
"0 http://example.org/building/Perimeter_ZN_3-ZN-... \n",
"1 http://example.org/building/Perimeter_ZN_2-ZN-... \n",
"2 http://example.org/building/Perimeter_ZN_1-ZN-... \n",
"3 http://example.org/building/Perimeter_ZN_4-ZN-... \n",
"4 http://example.org/building/Core_ZN-ZN-PSZ-AC-... \n",
"\n",
" wc0 \\\n",
"0 http://example.org/building/Perimeter_ZN_1-ZN-... \n",
"1 http://example.org/building/Core_ZN-ZN-PSZ-AC-... \n",
"2 http://example.org/building/Perimeter_ZN_4-ZN-... \n",
"3 http://example.org/building/Perimeter_ZN_3-ZN-... \n",
"4 http://example.org/building/Perimeter_ZN_2-ZN-... \n",
" OAT_AVG \\\n",
"0 http://example.org/building/Perimeter_ZN_3-ZN-... \n",
"1 http://example.org/building/Perimeter_ZN_2-ZN-... \n",
"2 http://example.org/building/Perimeter_ZN_1-ZN-... \n",
"3 http://example.org/building/Perimeter_ZN_4-ZN-... \n",
"4 http://example.org/building/Core_ZN-ZN-PSZ-AC-... \n",
"\n",
" wc1 \\\n",
"0 http://example.org/building/Perimeter_ZN_1-ZN-... \n",
"1 http://example.org/building/Core_ZN-ZN-PSZ-AC-... \n",
"2 http://example.org/building/Perimeter_ZN_4-ZN-... \n",
"3 http://example.org/building/Perimeter_ZN_3-ZN-... \n",
"4 http://example.org/building/Perimeter_ZN_2-ZN-... \n",
" RAT_AVG \\\n",
"0 http://example.org/building/Perimeter_ZN_3-ZN-... \n",
"1 http://example.org/building/Perimeter_ZN_2-ZN-... \n",
"2 http://example.org/building/Perimeter_ZN_1-ZN-... \n",
"3 http://example.org/building/Perimeter_ZN_4-ZN-... \n",
"4 http://example.org/building/Core_ZN-ZN-PSZ-AC-... \n",
"\n",
" wc2 \n",
"0 http://example.org/building/Perimeter_ZN_1-ZN-... \n",
"1 http://example.org/building/Core_ZN-ZN-PSZ-AC-... \n",
"2 http://example.org/building/Perimeter_ZN_4-ZN-... \n",
"3 http://example.org/building/Perimeter_ZN_3-ZN-... \n",
"4 http://example.org/building/Perimeter_ZN_2-ZN-... "
" target \n",
"0 http://example.org/building/Perimeter_ZN_3-ZN-... \n",
"1 http://example.org/building/Perimeter_ZN_2-ZN-... \n",
"2 http://example.org/building/Perimeter_ZN_1-ZN-... \n",
"3 http://example.org/building/Perimeter_ZN_4-ZN-... \n",
"4 http://example.org/building/Core_ZN-ZN-PSZ-AC-... "
]
},
"execution_count": 9,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -267,35 +286,54 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"PREFIX sh: <http://www.w3.org/ns/shacl#>\n",
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n",
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n",
" SELECT ?OAT_AVG ?RAT_AVG ?MAT_AVG ?target WHERE {\n",
"?target rdf:type/rdfs:subClassOf* <https://brickschema.org/schema/Brick#Air_Handling_Unit> .\n",
"?target <https://brickschema.org/schema/Brick#hasPoint> ?MAT_AVG .\n",
" ?MAT_AVG rdf:type/rdfs:subClassOf* <https://brickschema.org/schema/Brick#Mixed_Air_Temperature_Sensor> .\n",
"?target <https://brickschema.org/schema/Brick#hasPoint> ?RAT_AVG .\n",
" ?RAT_AVG rdf:type/rdfs:subClassOf* <https://brickschema.org/schema/Brick#Return_Air_Temperature_Sensor> .\n",
"?target <https://brickschema.org/schema/Brick#hasPoint> ?OAT_AVG .\n",
" ?OAT_AVG rdf:type/rdfs:subClassOf* <https://brickschema.org/schema/Brick#Outside_Air_Temperature_Sensor> .\n",
"\n",
"}\n"
]
},
{
"data": {
"text/plain": [
"[('http://example.org/building/Perimeter_ZN_1-ZN-PSZ-AC-2-Mixed-Air-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Perimeter_ZN_1-ZN-PSZ-AC-2-Supply-Inlet-Node_System_Node_Temperature',\n",
"[('http://example.org/building/Perimeter_ZN_3-ZN-PSZ-AC-4-Mixed-Air-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Perimeter_ZN_3-ZN-PSZ-AC-4-Outdoor-Air-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Perimeter_ZN_3-ZN-PSZ-AC-4-Supply-Inlet-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Perimeter_ZN_3-ZN-PSZ-AC-4-Unitary-HP'),\n",
" ('http://example.org/building/Perimeter_ZN_2-ZN-PSZ-AC-3-Mixed-Air-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Perimeter_ZN_2-ZN-PSZ-AC-3-Outdoor-Air-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Perimeter_ZN_2-ZN-PSZ-AC-3-Supply-Inlet-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Perimeter_ZN_2-ZN-PSZ-AC-3-Unitary-HP'),\n",
" ('http://example.org/building/Perimeter_ZN_1-ZN-PSZ-AC-2-Mixed-Air-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Perimeter_ZN_1-ZN-PSZ-AC-2-Outdoor-Air-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Perimeter_ZN_1-ZN-PSZ-AC-2-Supply-Inlet-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Perimeter_ZN_1-ZN-PSZ-AC-2-Unitary-HP'),\n",
" ('http://example.org/building/Core_ZN-ZN-PSZ-AC-1-Mixed-Air-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Core_ZN-ZN-PSZ-AC-1-Supply-Inlet-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Core_ZN-ZN-PSZ-AC-1-Outdoor-Air-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Core_ZN-ZN-PSZ-AC-1-Unitary-HP'),\n",
" ('http://example.org/building/Perimeter_ZN_4-ZN-PSZ-AC-5-Mixed-Air-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Perimeter_ZN_4-ZN-PSZ-AC-5-Supply-Inlet-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Perimeter_ZN_4-ZN-PSZ-AC-5-Outdoor-Air-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Perimeter_ZN_4-ZN-PSZ-AC-5-Supply-Inlet-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Perimeter_ZN_4-ZN-PSZ-AC-5-Unitary-HP'),\n",
" ('http://example.org/building/Perimeter_ZN_3-ZN-PSZ-AC-4-Mixed-Air-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Perimeter_ZN_3-ZN-PSZ-AC-4-Supply-Inlet-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Perimeter_ZN_3-ZN-PSZ-AC-4-Outdoor-Air-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Perimeter_ZN_3-ZN-PSZ-AC-4-Unitary-HP'),\n",
" ('http://example.org/building/Perimeter_ZN_2-ZN-PSZ-AC-3-Mixed-Air-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Perimeter_ZN_2-ZN-PSZ-AC-3-Supply-Inlet-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Perimeter_ZN_2-ZN-PSZ-AC-3-Outdoor-Air-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Perimeter_ZN_2-ZN-PSZ-AC-3-Unitary-HP')]"
" ('http://example.org/building/Core_ZN-ZN-PSZ-AC-1-Mixed-Air-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Core_ZN-ZN-PSZ-AC-1-Outdoor-Air-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Core_ZN-ZN-PSZ-AC-1-Supply-Inlet-Node_System_Node_Temperature',\n",
" 'http://example.org/building/Core_ZN-ZN-PSZ-AC-1-Unitary-HP')]"
]
},
"execution_count": 10,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
Expand Down
Loading

0 comments on commit 1cfd72a

Please sign in to comment.