Skip to content

Commit

Permalink
Merge branch 'develop' into add_verif_docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
leijerry888 committed Sep 5, 2024
2 parents ac50809 + a43c892 commit 1b47c7d
Show file tree
Hide file tree
Showing 26 changed files with 653 additions and 101 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ temp
test_cases/verif_mtd_pp/idfs/
*.sbatch
dist/
*.html
*.js
.buildinfo
.nojekyll
*.inv
docs/_modules
docs/_sources
docs/_static
docs/.doctrees
2 changes: 1 addition & 1 deletion constrain/api/brick_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __init__(
}

# load brick schema and instance files
self.g = brickschema.Graph(load_brick=True)
self.g = brickschema.Graph(load_brick=False)
self.g.load_file(self.brick_schema_path)
if perform_reasoning:
self.g.expand(
Expand Down
7 changes: 3 additions & 4 deletions constrain/api/data_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def __init__(
data_source (str): Data source name. Use `EnergyPlus` or `Other`.
timestamp_column_name (str): Name of the column header that contains the time series timestamps.
"""

self.data = None

if data_path is None:
Expand All @@ -44,13 +43,13 @@ def __init__(
# check if data file exists
if os.path.isfile(data_path):
try:
if data_source == "EnergyPlus":
if data_source.lower() == "energyplus":
# Use CSVReader to parse EnergyPlus timestamps
data = CSVReader(csv_file=data_path).getseries()
data = DateTimeEP(data, 2000).transform()
data.drop("Date/Time", inplace=True, axis=1)

elif data_source == "Other":
elif data_source.lower() == "bms":
if timestamp_column_name is None:
logging.error(
"timestamp_column_name is required when data_source = 'Other'"
Expand All @@ -65,7 +64,7 @@ def __init__(
return None
data.set_index(timestamp_column_name, inplace=True)
try:
data = pd.to_datetime(data.index)
data.index = pd.to_datetime(data.index)
except:
logging.error(
f"The data in {timestamp_column_name} could not be converted to Python datetime object. Make sure that the data is consistent defined as a set of date strings."
Expand Down
8 changes: 4 additions & 4 deletions constrain/api/verification_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
library_schema = {
"library_item_id": (int, str, float),
"description_brief": str,
"description_detail": str,
"description_detailed": str,
"description_index": list,
"description_datapoints": dict,
"description_assertions": list,
Expand Down Expand Up @@ -144,8 +144,8 @@ def validate_library(self, items: List[str] = None) -> Dict:

# verify the library.json file
for lib_key in library_schema.keys():
# check if lib keys exist. "description_detail" key is optional
if lib_key not in ["description_detail"] and not self.lib_items[
# check if lib keys exist. "description_detailed" key is optional
if lib_key not in ["description_detailed"] and not self.lib_items[
item
].get(lib_key):
logging.error(
Expand All @@ -169,7 +169,7 @@ def validate_library(self, items: List[str] = None) -> Dict:
)

except KeyError:
# if `description_detail` key doesn't exist, output a warning.
# if `description_detailed` key doesn't exist, output a warning.
validity_info[item][lib_key] = None
logging.warning(f"{lib_key} doesn't exist.")

Expand Down
6 changes: 1 addition & 5 deletions constrain/api/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,7 @@ def import_package(self) -> None:
"""Import third party packages based on the "imports" element values of the workflow json.
E.g.: {
...
"imports": [
"numpy as np",
"pandas as pd",
"datetime"
],
"imports": ["numpy as np","pandas as pd","datetime"],
...
}
"""
Expand Down
45 changes: 24 additions & 21 deletions constrain/app/rect_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,28 +435,31 @@ def contextMenuEvent(self, event):
action = menu.exec(event.screenPos())

if action == delete_action:
self.delete()
# find payloads that self.state has created
objects_created = self.get_objects_created()

# find what objects are currently being used by other states
all_objects_in_use = self.scene().getObjectsinUse()

# make sure that payloads from self.state are not being used by another state
for created_object in objects_created:
if created_object in all_objects_in_use:
self.sendError("Object created in use")
return

# remove lines
for c in self.controls:
for p in c.paths:
p1 = p.start
p2 = p.end
if p1 in self.controls:
p2.removeLine(p)
else:
p1.removeLine(p)
self.scene().removeItem(self)

def delete(self):
objects_created = self.get_objects_created()

# find what objects are currently being used by other states
all_objects_in_use = self.scene().getObjectsinUse()

# make sure that payloads from self.state are not being used by another state
for created_object in objects_created:
if created_object in all_objects_in_use:
self.sendError("Object created in use")
return

# remove lines
for c in self.controls:
for p in c.paths:
p1 = p.start
p2 = p.end
if p1 in self.controls:
p2.removeLine(p)
else:
p1.removeLine(p)
self.scene().removeItem(self)

def sendError(self, text):
"""Displays an error message given text
Expand Down
55 changes: 54 additions & 1 deletion constrain/app/workflow_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
QGraphicsView,
QGraphicsTextItem,
QGraphicsRectItem,
QMenu,
)
from PyQt6.QtCore import Qt, pyqtSignal, QRectF
from PyQt6.QtGui import (
Expand All @@ -16,11 +17,14 @@
QColor,
QPen,
QBrush,
QAction,
)
from constrain.app.popup_window import PopupWindow
from constrain.app.advanced_popup import AdvancedPopup
from constrain.app.rect_connect import Scene, CustomItem, ControlPoint, Path
from constrain.app.utils import send_error
import json
from collections import Counter


class Zoom(QGraphicsView):
Expand Down Expand Up @@ -72,6 +76,55 @@ def keyPressEvent(self, event: QKeyEvent):
else:
super().keyPressEvent(event)

def contextMenuEvent(self, event):
menu = QMenu(self)

# Check if there's an item under the mouse cursor
selected_states = [
item
for item in self.scene.items()
if item.isSelected() and isinstance(item, CustomItem)
]
if selected_states:
delete_action = QAction("Delete", self)
delete_action.triggered.connect(lambda: self.delete_items(selected_states))
menu.addAction(delete_action)
else:
item = self.itemAt(event.pos())

if isinstance(item, CustomItem):
delete_action = QAction("Delete", self)
delete_action.triggered.connect(item.delete)
menu.addAction(delete_action)

menu.exec(event.globalPos())

def delete_items(self, item_list):
all_objects_in_use = Counter(self.scene.getObjectsinUse())
objects_used_in_items = Counter(
[
item_object
for item in item_list
for item_object in item.get_objects_used()
]
)
objects_not_used_in_items = set(all_objects_in_use - objects_used_in_items)
objects_created_in_items = set()
for item in item_list:
objects_created_in_items |= set(item.get_objects_created())

intersection = objects_created_in_items & objects_not_used_in_items
if intersection:
error_msg_object = ", ".join(intersection)
error_msg = f"{error_msg_object} being used by other state"
if len(intersection) > 1:
error_msg += "s"
send_error("Error deleting state", error_msg)
return

for item in item_list:
item.delete()

def mouseDoubleClickEvent(self, event):
super().mouseDoubleClickEvent(event)
item = self.itemAt(event.pos())
Expand Down Expand Up @@ -142,7 +195,6 @@ def mouseReleaseEvent(self, event):
if isinstance(item, CustomItem) and rect.intersects(
item.mapRectToScene(item.rect)
):
print(item.state["Title"])
selected_items.append(item)
item.setSelected(True)

Expand Down Expand Up @@ -443,3 +495,4 @@ def clear(self):
self.scene.clear()
self.view.resetTransform()
self.update()
self.popup = None
Loading

0 comments on commit 1b47c7d

Please sign in to comment.