Coverage for backend/django/flowsheetInternals/propertyPackages/models/StreamFactory.py: 98%
32 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 flowsheetInternals.unitops.models import SimulationObject
2from flowsheetInternals.unitops.models.simulation_object_factory import SimulationObjectFactory
3from core.auxiliary.models.IndexedItem import IndexedItem
4from flowsheetInternals.unitops.models.flow_tracking import track_stream_flow
6class StreamFactory:
7 def __init__(self, stream: SimulationObject):
8 self.simulation_object = stream
9 self.property_package = stream.propertyPackageType
10 unit_ops, self.streams = track_stream_flow(self.simulation_object)
12 def check_and_update_stream(self):
13 if self.property_package == "humid_air":
14 self.swap_to_humid_air()
15 else:
16 self.check_swap_back()
18 def swap_to_humid_air(self):
19 for stream in self.streams:
20 if stream.objectType == "stream": 20 ↛ 19line 20 didn't jump to line 19 because the condition on line 20 was always true
21 swap_stream_to(stream, "humid_air_stream")
23 def check_swap_back(self):
24 for stream in self.streams:
25 if stream.objectType == "humid_air_stream":
26 swap_stream_to(stream, "stream")
28def swap_stream_to(stream, objectType):
29 # 1. get rid of indexeditems
30 IndexedItem.objects.filter(owner=stream).delete()
32 # 2. switch stream objectType
33 stream.objectType = objectType
34 stream.save()
36 # 3. Store old properties and delete them
37 factory = SimulationObjectFactory()
38 factory._flowsheet = stream.flowsheet
39 factory.store_old_properties(stream)
40 stream.properties.delete()
42 # 4. create indexeditems & propertyset
43 factory.replace_the_gut(stream)
44 factory.simulation_objects = []
45 factory.perform_bulk_create()