Coverage for backend/django/idaes_factory/adapters/stream_properties.py: 100%
24 statements
« prev ^ index » next coverage.py v7.10.7, created at 2026-05-13 02:47 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2026-05-13 02:47 +0000
1from ahuora_builder_types import PropertiesSchema
2from .property_info_adapter import SerialisePropertiesAdapter
3from ..queryset_lookup import get_property
6"""
7Stream serialisation using SerialisePropertiesAdapter.
8Handles material streams, energy streams, and other stream types.
9"""
11_stream_adapter = SerialisePropertiesAdapter()
13def should_serialise_stream(stream, is_inlet: bool) -> bool:
14 """
15 Check if a stream should be serialised.
16 """
17 if stream.connectedPorts.count() == 1:
18 # ie. inlet or outlet port
19 return True
20 if stream.has_recycle_connection:
21 # serialise both the inlet (for guesses) and outlet (for set points)
22 return True
23 else:
24 # serialise the outlet for intermediate ports
25 return not is_inlet
28def serialise_stream(ctx, stream, is_inlet: bool) -> PropertiesSchema:
29 """
30 Serialise the properties of a material stream.
31 """
32 if not should_serialise_stream(stream, is_inlet):
33 return {}
35 tear_inlet = stream.has_recycle_connection and is_inlet
36 tear_outlet = stream.has_recycle_connection and not is_inlet
38 # Serialize all properties with the correct is_tear flag
39 result = _stream_adapter.serialise(ctx, stream, is_tear=tear_inlet)
41 # For tear outlets, filter out properties that are not set points
42 if tear_outlet:
43 for prop in stream.properties.containedProperties.all():
44 for value in prop.values.all():
45 if not value.is_control_set_point() or not value.is_externally_controlled():
46 result.pop(prop.key, None)
47 break # Exit values loop once we decide to remove this property
49 return result