Skip to content

Commit

Permalink
feat: sys def template upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
vik378 committed Nov 13, 2024
1 parent c899ced commit 4dfb0f9
Show file tree
Hide file tree
Showing 2 changed files with 265 additions and 49 deletions.
54 changes: 48 additions & 6 deletions templates/physical-architecture/phy-component.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,71 @@
Copyright DB InfraGO AG and contributors
SPDX-License-Identifier: Apache-2.0
#}
{% from 'common_macros.html.j2' import show_other_attributes, description, display_property_values %}
{% from 'common_macros.html.j2' import show_other_attributes, description, display_property_values, linked_name_with_icon %}

<h1>{{ object.name }}</h1>
<small style="color: #aaa">UUID: {{ object.uuid }}</small>

{{ description(object) | safe }}
{# what could be interesting to cover:
- component nature: hardware or software
- if it is hardware, list what software runs on it
- if it is software, list what hardware it runs on
show interfaces of the component
describe interfaces
#}
<h2>Context</h2>
<p>The context of {{ object.name }} is summarized by the diagram below:</p>
{{ object.context_diagram.render("svg", display_derived_interfaces=True, display_port_labels=True) | safe }}

<h2>Interfaces of {{ object.name }}</h2>
<h2>Deployed software</h2>
<p>No software deployment specified</p>

{# <h2>Network interfaces</h2> #}
{# <p>tbd</p> #}

<h2>Electrical interfaces of {{ object.name }}</h2>

<table>
<thead>
<tr>
<th>Port</th>
<th>Wire ID</th>
{# <th>Port Type</th> #}
<th>Cable ID</th>
<th>Target</th>
<th>Target Port</th>
</tr>
</thead>
<tbody>
{% for port in object.physical_ports %}
{% set cables = port.links %}
{% if cables %}
{% for cable in cables %}
<tr>
{% set other_port = cable.ends | reject("equalto", port) | first %}
{% if loop.first %}
<td rowspan="{{ cables | length }}">{{ linked_name_with_icon(port) | safe }}</td>
{# <td rowspan="{{ cables | length }}">{{ port.property_value_groups["design_for_integration.PortDetails"].type.name | safe }}</td> #}
{% endif %}
<td>{{ linked_name_with_icon(cable) | safe }}</td>
<td>{{ linked_name_with_icon(other_port.owner) | safe }}</td>
<td>{{ linked_name_with_icon(other_port) | safe }}</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td>{{ linked_name_with_icon(port) | safe }}</td>
{# <td>{{ port.property_value_groups["design_for_integration.PortDetails"].type.name | safe }}</td> #}
<td colspan="3">No cable connections planned</td>
</tr>
{% endif %}
{% endfor %}
</table>

{{ display_property_values(object) }}

{{ display_property_values(object) | safe }}

<h2>Other properties of "{{ object.name }}"</h2>
{% set excluded = ["context_diagram", "description"] %}
{{ show_other_attributes(object, excluded) | safe}}
{% set excluded = ["context_diagram", "description", "physical_ports", "applied_property_value_groups", "property_value_groups", "name", "uuid"] %}
{{ show_other_attributes(object, excluded=excluded) | safe}}
260 changes: 217 additions & 43 deletions templates/system-analysis/system-definition.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@
{%- endfor -%}
</p>
{% endif %}

{% set related_src_exchanges = actor.related_exchanges | selectattr("source.owner", "equalto", object) | list %}
{% set related_tgt_exchanges = actor.related_exchanges | selectattr("target.owner", "equalto", object) | list %}
{% set related_exchanges = related_src_exchanges + related_tgt_exchanges %}

{% if related_exchanges %}
<p>The <i>{{ object.name }}</i> interacts with the <i>{{ actor.name }}</i> via the following interfaces:</p>
<ul>
{%- for exchange in related_exchanges -%}
<li>{{ linked_name_with_icon(exchange) | safe }}</li>
{%- endfor -%}
</ul>
{% else %}
<p style="color:red">No interfaces defined between the system and the actor.</p>
{% endif %}
{% endfor %}
{% else %}
<p style="color:red">No actors defined for the system.</p>
Expand All @@ -96,10 +111,165 @@
<h2>5 System Functions</h2>
<p>This chapter defines the functions of the system</p>

{% macro functional_exchanges_table(exchange_col_label, owner_col_lable, exchanges, owner_decorator) %}
<table>
<thead>
<tr>
<th>ID</th>
<th>{{exchange_col_label}}</th>
<th>{{owner_col_lable}}</th>
</tr>
</thead>
<tbody>
{%- for exchange in exchanges -%}
<tr>
<td><a href="{{ exchange | make_href }}">{{ exchange.uuid[:5] | upper }}</a></td>
<td>{{ linked_name_with_icon(exchange) | safe }}</td>
<td>{{ owner_decorator(exchange) | safe }}</td>
</tr>
{%- endfor -%}
</tbody>
</table>
{% endmacro %}

{% if object.allocated_functions %}
{% for function in object.allocated_functions %}
<h3>5.{{ loop.index }} {{ linked_name_with_icon(function) | safe }}</h3>
{{ description(function) | safe }}
{% if function.inputs %}
<h4>5.{{ loop.index }}.1 Inputs</h4>
<p>The function <i>{{ function.name }}</i> may need the following inputs:</p>
{% set internal_inputs = [] %}
{% set external_inputs = [] %}
{% set undefined_owner_inputs = [] %}
{% set ports_with_no_exchanges = [] %}

{% for input in function.inputs %}
{% if input.exchanges %}
{% for exchange in input.exchanges %}
{% set partner = exchange.source.owner.owner %}
{% if partner and partner != object %}
{% set external_inputs = external_inputs.append(exchange) %}
{% elif partner == object %}
{% set internal_inputs = internal_inputs.append(exchange) %}
{% else %}
{% set undefined_owner_inputs = undefined_owner_inputs.append(exchange) %}
{% endif %}
{% endfor %}
{% else %}
{% set ports_with_no_exchanges = ports_with_no_exchanges.append(input) %}
{% endif %}
{% endfor %}



{% macro decorate_own_source(exchange) %}
{{ linked_name_with_icon(exchange.source.owner) | safe }} (own function)
{% endmacro %}

{% macro decorate_actor_source(exchange) %}
{{ linked_name_with_icon(exchange.source.owner) | safe }}, a function of {{ linked_name_with_icon(exchange.source.owner.owner) | safe }}
{% endmacro %}

{% if external_inputs %}
<p><b>Inputs from activities of external actors:</b></p>
{{ functional_exchanges_table("Input", "Source", external_inputs, decorate_actor_source) | safe }}
{% endif %}

{% if internal_inputs %}
<p><b>Inputs from internal activities of {{ object.name }}</b></p>
<p>To <i>{{ function.name }}</i> {{object.name}} may need:</p>
{{ functional_exchanges_table("Input", "Source", internal_inputs, decorate_own_source) | safe }}
{% endif %}

{% if undefined_owner_inputs %}
<p style="color:red">The following exchanges come from functions that are not allocated to any entity:</p>
<ul>
{%- for exchange in undefined_owner_inputs -%}
<li>{{ linked_name_with_icon(exchange) | safe }}, an output of {{linked_name_with_icon(exchange.source.owner) | safe }}</li>
{%- endfor -%}
</ul>
{% endif %}

{% if ports_with_no_exchanges %}
<p style="color:red">The following input ports have no incoming exchanges defined:</p>
<ul>
{%- for port in ports_with_no_exchanges -%}
<li>{{ linked_name_with_icon(port) | safe }}</li>
{%- endfor -%}
</ul>
{% endif %}

{% else %}
<p style="color:red">{{object.name}} seems to require no inputs to {{function.name}}.</p>
{% endif %}

{% if function.outputs %}
<h4>5.{{ loop.index }}.2 Outputs</h4>
<p>The function <i>{{ function.name }}</i> may produce the following outputs:</p>
{% set internal_outputs = [] %}
{% set external_outputs = [] %}
{% set undefined_owner_outputs = [] %}
{% set ports_with_no_exchanges = [] %}

{% for output in function.outputs %}
{% if output.exchanges %}
{% for exchange in output.exchanges %}
{% set partner = exchange.target.owner.owner %}
{% if partner and partner != object %}
{% set external_outputs = external_outputs.append(exchange) %}
{% elif partner == object %}
{% set internal_outputs = internal_outputs.append(exchange) %}
{% else %}
{% set undefined_owner_outputs = undefined_owner_outputs.append(exchange) %}
{% endif %}
{% endfor %}
{% else %}
{% set ports_with_no_exchanges = ports_with_no_exchanges.append(output) %}
{% endif %}
{% endfor %}

{% macro decorate_actor_target(exchange) %}
{{ linked_name_with_icon(exchange.target.owner) | safe }}, a function of {{ linked_name_with_icon(exchange.target.owner.owner) | safe }}
{% endmacro %}

{% macro decorate_own_target(exchange) %}
{{ linked_name_with_icon(exchange.target.owner) | safe }} (own function)
{% endmacro %}

{% if external_outputs %}
<p><b>Outputs to activities of external actors:</b></p>
{{ functional_exchanges_table("Output", "Target", external_outputs, decorate_actor_target) | safe }}
{% endif %}

{% if internal_outputs %}
<p><b>Outputs to internal activities of {{ object.name }}</b></p>
<p>From <i>{{ function.name }}</i> {{object.name}} may produce:</p>
{{ functional_exchanges_table("Output", "Target", internal_outputs, decorate_own_target) | safe }}
{% endif %}

{% if undefined_owner_outputs %}
<p style="color:red">The following exchanges go to functions that are not allocated to any entity:</p>
<ul>
{%- for exchange in undefined_owner_outputs -%}
<li>{{ linked_name_with_icon(exchange) | safe }}, an input of {{linked_name_with_icon(exchange.target.owner) | safe }}</li>
{%- endfor -%}
</ul>
{% endif %}

{% if ports_with_no_exchanges %}
<p style="color:red">The following output ports have no outgoing exchanges defined:</p>
<ul>
{%- for port in ports_with_no_exchanges -%}
<li>{{ linked_name_with_icon(port) | safe }}</li>
{%- endfor -%}
</ul>

{% endif %}
{% else %}
<p style="color:red">{{object.name}} seems to produce no outputs from {{function.name}}.</p>
{% endif %}


{# TODO: describe inputs, outputs and capability involvements; distinguish internal vs external #}

Expand Down Expand Up @@ -128,53 +298,57 @@
The {{ linked_name_with_icon(source) | safe }} shall provide {{ linked_name_with_icon(object) | safe }} to {{ linked_name_with_icon(target) | safe }} so that the {{ linked_name_with_icon(target) | safe }} could {{ linked_name_with_icon(target_function)|safe }}.
{% endmacro %}

{% macro describe_interface(interface) %}
{% if interface.description %}
{{ interface.description | safe }}
{% endif %}

{% if interface.allocated_functional_exchanges %}
<p>The figure below provides an overviow of the functional interactions enabled by this interface.</p>
{{ interface.context_diagram.as_svg | safe }}

<p>The interface may be used for the following functional interactions:</p>
<table>
<thead>
<tr>
<th>ID</th>
<th>Interaction description</th>
</thead>
<tbody>
{% for exchange in interface.allocated_functional_exchanges %}
<tr>
<td><a href="{{ exchange | make_href }}">{{ "LEXC-" + exchange.uuid[:5] | upper }}</a></td>
<td>
{{ describe_exchange(exchange) | safe }}
{% if exchange.exchange_items %}
{% if exchange.exchange_itemslength > 1 %}
<p>{{ exchange.name }} is further specified via the following Exchange Items:</p>
<ul>
{% for item in exchange.exchange_items %}
<li>{{ linked_name_with_icon(item) | safe }}</li>
{%- if item not in exchange_items_catalog -%}
{%- set _none = exchange_items_catalog.append(item) -%}
{%- endif -%}
{% endfor %}
</ul>
{% else %}
<p>This interaction is further specified via {{ linked_name_with_icon(exchange.exchange_items[0]) | safe}} Exchange Item</p>
{% endif %}
{% endif %}
</td>
</tr>
{% endfor %}
</table>
{% else %}
<p style="color:red">No exchanges defined for the interface.</p>
{% endif %}
{% endmacro %}

{% set interfaces = object.related_exchanges %}
{% if interfaces %}
{% for interface in interfaces %}
<h3>6.{{ loop.index }} {{ linked_name_with_icon(interface) | safe }}</h3>
{% if interface.description %}
{{ interface.description | safe }}
{% endif %}

{% if interface.allocated_functional_exchanges %}
<p>The figure below provides an overviow of the functional interactions enabled by this interface.</p>
{{ interface.context_diagram.as_svg | safe }}

<p>The interface may be used for the following functional interactions:</p>
<table>
<thead>
<tr>
<th>ID</th>
<th>Interaction description</th>
</thead>
<tbody>
{% for exchange in interface.allocated_functional_exchanges %}
<tr>
<td><a href="{{ exchange | make_href }}">{{ "LEXC-" + exchange.uuid[:5] | upper }}</a></td>
<td>
{{ describe_exchange(exchange) | safe }}
{% if exchange.exchange_items %}
{% if exchange.exchange_itemslength > 1 %}
<p>{{ exchange.name }} is further specified via the following Exchange Items:</p>
<ul>
{% for item in exchange.exchange_items %}
<li>{{ linked_name_with_icon(item) | safe }}</li>
{%- if item not in exchange_items_catalog -%}
{%- set _none = exchange_items_catalog.append(item) -%}
{%- endif -%}
{% endfor %}
</ul>
{% else %}
<p>This interaction is further specified via {{ linked_name_with_icon(exchange.exchange_items[0]) | safe}} Exchange Item</p>
{% endif %}
{% endif %}
</td>
</tr>
{% endfor %}
</table>
{% else %}
<p style="color:red">No exchanges defined for the interface.</p>
{% endif %}
{{ describe_interface(interface) | safe }}
{% endfor %}
{% else %}
<p style="color:red">No interfaces defined for the system.</p>
Expand Down

0 comments on commit 4dfb0f9

Please sign in to comment.