Skip to content

Commit

Permalink
git commit -m 'connections from list to Dict'
Browse files Browse the repository at this point in the history
  • Loading branch information
vargastat committed Apr 3, 2024
1 parent caee341 commit 6d84cf1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
11 changes: 4 additions & 7 deletions src/andromede/study/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,18 @@
from dataclasses import dataclass
from typing import Dict, Iterable, List

from andromede.model import Model, PortType
from andromede.study import Component, PortRef, PortsConnection
from andromede.study import Component, PortRef


@dataclass(frozen=True)
class Components:
components: Dict[str, Component]
connections: List[PortRef]
connections: Dict[str, List[PortRef]]


def components(
components_list: Iterable[Component],
connections: Iterable[PortRef],
components_list: Iterable[Component], connections: Dict[str, List[PortRef]]
) -> Components:
return Components(
components=dict((m.id, m) for m in components_list),
connections=list(p for p in connections),
components=dict((m.id, m) for m in components_list), connections=connections
)
10 changes: 5 additions & 5 deletions src/andromede/study/resolve_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.
from typing import List, Optional
from typing import Dict, List, Optional

from andromede.model.parsing import InputModel
from andromede.model.resolve_library import _resolve_model_identifier
Expand All @@ -25,11 +25,11 @@ def resolve_components_and_cnx(input_comp: InputComponent) -> Components:
- connections between components"""
components_list = [_resolve_component(m, m.id) for m in input_comp.components]
components_list.extend(_resolve_component(n, n.id) for n in input_comp.nodes)
connections = []
connections = {}

for cnx in input_comp.connections:
resolved_cnx = _resolve_connections(cnx, components_list)
connections.extend(resolved_cnx)
connections.update(resolved_cnx)

return components(components_list, connections)

Expand All @@ -43,7 +43,7 @@ def _resolve_component(model_for_component: InputModel, component_id: str) -> Co
def _resolve_connections(
connection: InputPortConnections,
components_list: List[Component],
) -> List[PortRef]:
) -> Dict[str, List[PortRef]]:
cnx_component1 = connection.component1
cnx_component2 = connection.component2
port1 = connection.port_1
Expand All @@ -54,7 +54,7 @@ def _resolve_connections(
assert component_1 is not None and component_2 is not None
port_ref_1 = PortRef(component_1, port1)
port_ref_2 = PortRef(component_2, port2)
return [port_ref_1, port_ref_2]
return {connection.id: [port_ref_1, port_ref_2]}


def _get_component_by_id(
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/study/test_components_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ def test_parsing_components_ok(data_dir: Path):
result = resolve_components_and_cnx(input_compo)

assert len(result.components) == 3
assert len(result.connections) == 4
assert len(result.connections) == 2

0 comments on commit 6d84cf1

Please sign in to comment.