Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REF: UI redesign #5

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 24 additions & 53 deletions docs/source/scripts/schema.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,13 @@
import glob
import json
import os
import pathlib

import json_schema_for_humans.generate as Gen
from ravens.schema import RavensSchema, generate_schema_docs
from ravens.uml import UMLExclusions

from ravens.io import parse_uml_data
from ravens.cim_tools.common import build_package_exclusions, build_object_exclusions
from ravens.cim_tools.graph import build_generalization_graph, build_attribute_graph
from ravens.cim_tools.template import CIMTemplate
from ravens.schema.build_definitions import build_definitions
from ravens.schema.build_map import add_attributes_to_template
from ravens.schema.build_schema import build_schema_from_map
from ravens.schema.add_copyright_notice import add_cim_copyright_notice_to_decomposed_schemas
from ravens.schema.decompose_schema import Schemas


def build_schema_docs():
current_dir = os.path.dirname(os.path.abspath(__file__))
template_path = os.path.join(current_dir, "../../../ravens/cim_tools/cim_conversion_template.json")
xmi_path = os.path.join(current_dir, "../../../cim/iec61970cim17v40_iec61968cim13v13b_iec62325cim03v17b_CIM100.1.1.1_mgravens24v1.xmi")
tmp_dir = os.path.join(current_dir, "../tmp")
static_schema_dir = os.path.join(current_dir, "../_static/schema")
schema_md_dir = os.path.join(current_dir, "../schema")

uml_data = parse_uml_data(xmi_path)

exclude_packages = build_package_exclusions(uml_data.packages, lambda x: any(str(x.Name).startswith(k) for k in ["Inf", "Mkt"]))
exclude_objects = build_object_exclusions(
uml_data.objects,
lambda x: any(str(x.Name).startswith(k) for k in ["Inf", "Mkt"]),
exclude_packages=exclude_packages,
)

schema = build_schema_from_map(
add_attributes_to_template(
CIMTemplate(template_path).template,
CIMTemplate(template_path).template,
uml_data,
build_generalization_graph(uml_data, exclude_packages, exclude_objects),
build_attribute_graph(uml_data, exclude_packages, exclude_objects),
)
)

schema["$defs"] = build_definitions(uml_data)

a = Schemas(schema, base_id_uri=f"file://{tmp_dir}")

add_cim_copyright_notice_to_decomposed_schemas(a.schemas, uml_data)

for k, v in a.schemas.items():
filename = k.split("/")[-1].replace(".json", "")
with open(os.path.join(tmp_dir, f"{filename}.json"), "w") as f:
json.dump(v, f, indent=2)

config = Gen.GenerationConfiguration(template_name="js")
Gen.generate_from_filename(tmp_dir, static_schema_dir, config=config)

def modify_schema_docs_resource_paths(static_schema_dir: pathlib.PosixPath):
for file in glob.glob(os.path.join(static_schema_dir, "*.html")):
with open(file, "r") as f:
f_str = f.read()
Expand All @@ -66,6 +18,8 @@ def build_schema_docs():
with open(file, "w") as f:
f.write(f_str)


def build_markdown_file(schema_md_dir: pathlib.PosixPath, static_schema_dir: pathlib.PosixPath):
md_file = """# Schema Documentation

## Root Schema
Expand All @@ -77,8 +31,25 @@ def build_schema_docs():
"""

for file in sorted(glob.glob("*.html", root_dir=static_schema_dir)):
if file != "__main__.html":
if file != "Root.html":
md_file = md_file + f"[{file.split(".html")[0]}](../_static/schema/{file})" + "{.external}" + "\n\n"

with open(os.path.join(schema_md_dir, "index.md"), "w") as f:
f.write(md_file)


def build_schema_docs():
current_dir = os.path.dirname(os.path.abspath(__file__))
tmp_dir = os.path.join(current_dir, "../tmp")
static_schema_dir = os.path.join(current_dir, "../_static/schema")
schema_md_dir = os.path.join(current_dir, "../schema")

a = RavensSchema(uml_exclusions=UMLExclusions().exclude_by_name_startswith(["Inf", "Mkt"]))

a.export_schemas(tmp_dir)

generate_schema_docs(tmp_dir, static_schema_dir)

modify_schema_docs_resource_paths(static_schema_dir)

build_markdown_file(schema_md_dir, static_schema_dir)
9 changes: 3 additions & 6 deletions docs/source/scripts/uml.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import os

from ravens.io import parse_uml_data
from ravens.uml.d3 import save_uml_diagrams_from_package_name
from ravens.uml import UMLVisualizer


def build_uml_docs():
xmi_file = "../../cim/iec61970cim17v40_iec61968cim13v13b_iec62325cim03v17b_CIM100.1.1.1_mgravens24v1.xmi"
uml_data = parse_uml_data(xmi_file)

current_dir = os.path.dirname(os.path.abspath(__file__))
static_uml_path = os.path.join(current_dir, "../_static/uml")
uml_vis = UMLVisualizer()

md_str = "# UML Diagrams for MG-RAVENS Schema\n"
for package_name in ["EconomicDesign", "SimplifiedDiagrams", "EquipmentExtensions", "Software"]:

paths = save_uml_diagrams_from_package_name(uml_data, package_name, static_uml_path)
paths = uml_vis.save_uml_diagrams_from_package_name(package_name, static_uml_path)
md_str = (
md_str
+ f"\n## {package_name}\n"
Expand Down
1 change: 1 addition & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

!case3_balanced.dss
!case3_balanced.xml
!case3_balanced.json
!IEEE13_Assets.xml
!IEEE13.xml
!/schema
Loading
Loading