Skip to content

Commit

Permalink
More work
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuestengecko committed Jan 26, 2024
1 parent 70f9d5f commit ab9239c
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 67 deletions.
161 changes: 95 additions & 66 deletions capella_model_explorer/demo.py
Original file line number Diff line number Diff line change
@@ -1,76 +1,105 @@
import streamlit as st
import capellambse
import pandas as pd
import streamlit as st
from jinja2.environment import Environment

import capellambse

env = Environment()

model = capellambse.MelodyModel(
path="automated-train",
entrypoint="/automated-train.aird",
)

viewpoint = "capabilities"
@st.cache_resource
def load_model() -> capellambse.MelodyModel:
return capellambse.MelodyModel(
path="automated-train",
entrypoint="/automated-train.aird",
)


model = load_model()

with st.sidebar:
st.write("# Sidebar!")
viewpoint = st.selectbox("Viewpoint:", ["Capabilities", "Functions", "Interfaces"])


sys_caps = model.sa.all_capabilities

st.write("""
# Caps
""")
sys_caps_idx = {cap.name: cap for cap in sys_caps}
selected_name = st.selectbox("Select System Capability", options=sys_caps_idx.keys())

cap = sys_caps_idx[selected_name]

st.image(cap.context_diagram.as_svg)

cap_real_entities = set([entity.owner for entity in cap.involved_functions if entity.owner])
table = pd.DataFrame([
{
"name": obj.name,
"functions": "; ".join(["" + fnc.name for fnc in cap.involved_functions if fnc.owner == obj])
} for obj in cap_real_entities
])

st.dataframe(table.style.set_properties(**{"white-space": "pre-wrap"}))

table_template = """
To realize this capability the System and involved actors are required to perform the following functions:</p>
<table>
<tr>
<th>Involved Entity</th><th>Required function</th>
</tr>
<tbody>
{% for owner, fncs in cap.involved_functions | rejectattr("owner","none") | groupby("owner.name") %}
<tr>
<td>{{owner}}</td>
<td>
{% for fnc in fncs %}
- {{fnc.name}}
viewpoint = st.radio(
"Viewpoint:", ["Capabilities", "Functions", "Interfaces"]
)


if viewpoint == "Capabilities":
with st.sidebar:
sys_caps = model.sa.all_capabilities
sys_caps_idx = {cap.name: cap for cap in sys_caps}
selected_name = st.selectbox(
"Select System Capability", options=sys_caps_idx.keys()
)
cap = sys_caps_idx[selected_name]
st.write(f"# {cap.name}")

st.write("## Description")
st.write(cap.description, unsafe_allow_html=True)

st.write("## Context Diagram")
st.write(
"""\
The image below provides an overview over the actors immediately
involved in the Capability.
"""
)
st.image(cap.context_diagram.as_svg)

st.write("## Required Functions")
cap_real_entities = {
entity.owner for entity in cap.involved_functions if entity.owner
}
table = pd.DataFrame(
[
{
"name": obj.name,
"functions": "; ".join(
fnc.name
for fnc in cap.involved_functions
if fnc.owner == obj
),
}
for obj in cap_real_entities
]
)

st.dataframe(
table.style.set_properties(**{"white-space": "pre-wrap"}),
hide_index=True,
)

elif viewpoint == "Functions":
table_template = """
To realize this capability the System and involved actors are required to perform the following functions:</p>
<table>
<tr>
<th>Involved Entity</th><th>Required function</th>
</tr>
<tbody>
{% for owner, fncs in cap.involved_functions | rejectattr("owner","none") | groupby("owner.name") %}
<tr>
<td>{{owner}}</td>
<td>
{% for fnc in fncs %}
- {{fnc.name}}
{% endfor %}
</td>
</tr>
{% endfor %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
"""
template = env.from_string(table_template)
st.markdown(template.render(cap=obj), unsafe_allow_html=True)

fncs = model.sa.all_functions

st.write("""
# Functions
""")
sys_fncs = {fnc.name: fnc for fnc in fncs}
selected_fnc_name = st.selectbox("Select Function", options=sys_fncs.keys())
fnc_obj = sys_fncs[selected_fnc_name]

card = f"""{fnc_obj.context_diagram.as_svg}"""
st.markdown(card, unsafe_allow_html=True)
</tbody>
</table>
"""
template = env.from_string(table_template)
st.markdown(template.render(cap=obj), unsafe_allow_html=True)

fncs = model.sa.all_functions

st.write("# Functions")
sys_fncs = {fnc.name: fnc for fnc in fncs}
selected_fnc_name = st.selectbox(
"Select Function", options=sys_fncs.keys()
)
fnc_obj = sys_fncs[selected_fnc_name]

card = f"""{fnc_obj.context_diagram.as_svg}"""
st.markdown(card, unsafe_allow_html=True)
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ classifiers = [
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dependencies = []
dependencies = [
"capellambse",
"capellambse-context-diagrams",
"jinja2",
"pandas",
"streamlit",
]

[project.urls]
Homepage = "https://github.com/DSD-DBS/capella-model-explorer"
Expand Down

0 comments on commit ab9239c

Please sign in to comment.