Skip to content

Commit 3ff6bfd

Browse files
committed
ADD: ability to compare uml data
1 parent d1f311a commit 3ff6bfd

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ markdownify = "^0.13"
1818
lxml = "^5.3.0"
1919
opendssdirect-py = {extras = ["extras"], version = "^0.9.4"}
2020
jschon= {extras = ["requests"], version = "^0.11.1"}
21+
openpyxl = "^3.1.5"
2122

2223
[tool.poetry.group.dev.dependencies]
2324
pytest = "^8.3.3"

ravens/uml/data.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def __init__(self):
204204
setattr(self, _attr_names[table_name], df)
205205

206206
@classmethod
207-
def loadf(cls, file: pathlib.PosixPath = _UML_XML_PATH, set_index: bool = True) -> object:
207+
def loadf(cls, file: str | pathlib.Path = _UML_XML_PATH, set_index: bool = True) -> object:
208208
dataframes: dict = cls._create_dataframes(file, set_index=set_index)
209209
obj = cls()
210210
for table_name, df in dataframes.items():
@@ -213,7 +213,7 @@ def loadf(cls, file: pathlib.PosixPath = _UML_XML_PATH, set_index: bool = True)
213213
return obj
214214

215215
@staticmethod
216-
def _create_dataframes(file: pathlib.PosixPath = _UML_XML_PATH, set_index: bool = True) -> dict:
216+
def _create_dataframes(file: str | pathlib.Path = _UML_XML_PATH, set_index: bool = True) -> dict:
217217
tree = ET.parse(file)
218218
root = tree.getroot()
219219

@@ -256,6 +256,23 @@ def _create_dataframes(file: pathlib.PosixPath = _UML_XML_PATH, set_index: bool
256256

257257
return dataframes
258258

259+
def compare(self, data, compare_attributes: list[str] | None = None):
260+
if compare_attributes is None:
261+
compare_attributes = ["objects", "connectors", "attributes"]
262+
263+
results = {}
264+
for attr in compare_attributes:
265+
a = getattr(self, attr)
266+
b = getattr(data, attr)
267+
results[attr] = b[~b.isin(a.to_dict(orient="list")).all(axis=1)]
268+
269+
return results
270+
271+
def export_comparison(self, path: str | pathlib.Path, results: dict[str, pd.DataFrame]):
272+
with pd.ExcelWriter(path, engine="openpyxl") as writer:
273+
for t, df in results.items():
274+
df.to_excel(writer, sheet_name=t, index=False)
275+
259276

260277
if __name__ == "__main__":
261278
uml = UMLData()

0 commit comments

Comments
 (0)