From b5c08049205f09e7c07d9139f368d085eb0a7c1d Mon Sep 17 00:00:00 2001 From: vik378 Date: Mon, 18 Nov 2024 15:06:41 +0100 Subject: [PATCH] feat: better handling of corner cases in sysdef template --- .../system-analysis/system-definition.html.j2 | 241 +++++++++--------- 1 file changed, 125 insertions(+), 116 deletions(-) diff --git a/templates/system-analysis/system-definition.html.j2 b/templates/system-analysis/system-definition.html.j2 index a895dbc..e90cec9 100644 --- a/templates/system-analysis/system-definition.html.j2 +++ b/templates/system-analysis/system-definition.html.j2 @@ -132,142 +132,151 @@ {% endmacro %} +{% 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 %} + +{% 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 object.allocated_functions %} {% for function in object.allocated_functions %}

5.{{ loop.index }} {{ linked_name_with_icon(function) | safe }}

{{ description(function) | safe }} - {% if function.inputs %} -

5.{{ loop.index }}.1 Inputs

-

The function {{ function.name }} may need the following inputs:

- {% 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 %} - + {# Classify Functional IO #} + {%- set internal_inputs = [] -%} + {%- set external_inputs = [] -%} + {%- set undefined_owner_inputs = [] -%} + {%- set input_ports_with_no_exchanges = [] -%} + {%- set internal_outputs = [] -%} + {%- set external_outputs = [] -%} + {%- set undefined_owner_outputs = [] -%} + {%- set output_ports_with_no_exchanges = [] -%} + + {%- if function.inputs -%} + {%- 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 none_ = external_inputs.append(exchange) -%} + {%- elif partner == object -%} + {%- set none_ = internal_inputs.append(exchange) -%} + {%- else -%} + {%- set none_ = undefined_owner_inputs.append(exchange) -%} + {%- endif -%} + {%- endfor -%} + {%- else -%} + {%- set none_ = input_ports_with_no_exchanges.append(input) -%} + {%- endif -%} + {%- endfor -%} + {%- endif -%} + + {%- if function.outputs -%} + {%- 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 none_ = external_outputs.append(exchange) -%} + {%- elif partner == object -%} + {%- set none_ = internal_outputs.append(exchange) -%} + {%- else -%} + {%- set none_ = undefined_owner_outputs.append(exchange) -%} + {%- endif -%} + {%- endfor -%} + {%- else -%} + {%- set none_ = output_ports_with_no_exchanges.append(output) -%} + {%- endif -%} + {%- endfor -%} + {%- endif -%} - {% 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 %} + {# Visualize Functional IO #} - {% if external_inputs %} -

Inputs from activities of external actors:

- {{ functional_exchanges_table("Input", "Source", external_inputs, decorate_actor_source) | safe }} - {% endif %} - - {% if internal_inputs %} -

Inputs from internal activities of {{ object.name }}

-

To {{ function.name }} {{object.name}} may need:

- {{ functional_exchanges_table("Input", "Source", internal_inputs, decorate_own_source) | safe }} - {% endif %} + {% if function.inputs %} +

5.{{ loop.index }}.1 Inputs

+

The function {{ function.name }} may need the following inputs:

+ + {% if external_inputs %} +

Inputs from activities of external actors:

+ {{ functional_exchanges_table("Input", "Source", external_inputs, decorate_actor_source) | safe }} + {% endif %} - {% if undefined_owner_inputs %} -

The following exchanges come from functions that are not allocated to any entity:

- - {% endif %} + {% if internal_inputs %} +

Inputs from internal activities of {{ object.name }}

+

To {{ function.name }} {{object.name}} may need:

+ {{ functional_exchanges_table("Input", "Source", internal_inputs, decorate_own_source) | safe }} + {% endif %} - {% if ports_with_no_exchanges %} -

The following input ports have no incoming exchanges defined:

- - {% endif %} + {% if undefined_owner_inputs %} +

The following exchanges come from functions that are not allocated to any entity:

+ + {% endif %} + {% if input_ports_with_no_exchanges %} +

The following input ports have no incoming exchanges defined:

+ + {% endif %} {% else %} -

{{object.name}} seems to require no inputs to {{function.name}}.

+

{{object.name}} seems to require no inputs to {{function.name}}.

{% endif %} {% if function.outputs %} -

5.{{ loop.index }}.2 Outputs

-

The function {{ function.name }} may produce the following outputs:

- {% 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) %} +

5.{{ loop.index }}.2 Outputs

+

The function {{ function.name }} may produce the following outputs:

+ + {% if external_outputs %} +

Outputs to activities of external actors:

+ {{ functional_exchanges_table("Output", "Target", external_outputs, decorate_actor_target) | safe }} {% 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 %} -

Outputs to activities of external actors:

- {{ functional_exchanges_table("Output", "Target", external_outputs, decorate_actor_target) | safe }} - {% endif %} + {% if internal_outputs %} +

Outputs to internal activities of {{ object.name }}

+

From {{ function.name }} {{object.name}} may produce:

+ {{ functional_exchanges_table("Output", "Target", internal_outputs, decorate_own_target) | safe }} + {% endif %} - {% if internal_outputs %} -

Outputs to internal activities of {{ object.name }}

-

From {{ function.name }} {{object.name}} may produce:

- {{ functional_exchanges_table("Output", "Target", internal_outputs, decorate_own_target) | safe }} - {% endif %} + {% if undefined_owner_outputs %} +

The following exchanges go to functions that are not allocated to any entity:

+ + {% endif %} - {% if undefined_owner_outputs %} -

The following exchanges go to functions that are not allocated to any entity:

- + {% if output_ports_with_no_exchanges %} +

The following output ports have no outgoing exchanges defined:

+ + {% endif %} + {% else %} +

{{object.name}} seems to produce no outputs from {{function.name}}.

{% endif %} - {% if ports_with_no_exchanges %} -

The following output ports have no outgoing exchanges defined:

- - - {% endif %} - {% else %} -

{{object.name}} seems to produce no outputs from {{function.name}}.

+ {% if not function.inputs and not function.outputs %} +

{{ object.name }} seem to require no inputs and provide no outputs while performing "{{ function.name }}" which doesn't seem correct. A function should consume inputs and produce observable outputs unless it is a source or sink function.

{% endif %}