Coverage for backend/common/src/common/config_types.py: 100%
86 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-12-18 04:00 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2025-12-18 04:00 +0000
1from enum import StrEnum
2from typing import Union
3from pydantic import BaseModel, Field, RootModel
4from typing import Literal, Tuple, Dict, List, Any
7PropertyPackageKey = str
8PortKey = str
10Transformer = Literal["inverse"]
12class PropertyType(BaseModel):
13 """
14 - propertySetGroup:
15 key of the property set group. If not specified, the property
16 will be added to the default property set group.
17 - value:
18 default value of the property. If not specified, the value will
19 be set to empty.
20 - unit:
21 default unit of the property. If not specified, the unit will
22 be set to the default unit of the unit type.
23 - unit_type (Required):
24 type of the unit (temperature, pressure, etc.) or "dimensionless" for no unit
25 - description:
26 description of the property
27 - type (Required):
28 type of the property (numeric, dropdown, checkbox, segmented, text, numeric_arg)
29 """
30 propertySetGroup: str = Field("default", description="Property set group")
31 displayName: str = Field(..., description="Display name of the property")
32 indexSets: List[str] = Field(None, description="Index sets of the property")
33 sumToOne: bool = Field(None, description="Flag indicating whether the property should sum to one. If true, the last instance of the first index set will be calcualted from the others. See compound_propogation.py")
34 value: Union[int, float,bool,str,List[str]] = Field(None, description="Default value of the property")
35 unit: str = Field(None, description="Default unit of the property")
36 unitType: str = Field(..., description="Type of the unit")
37 description: str = Field(None, description="Description of the property")
38 type: Literal["numeric", "dropdown", "checkbox", "segmented", "text", "numeric_arg"] = Field(..., description="Type of the property")
39 many: bool = Field(None, description="Flag indicating whether there are multiple properties by this key")
40 default: int = Field(None, description="Default number of properties if many=True")
41 options: Dict[str, str] = Field(None, description="Options for the dropdown property. Key is the value, value is the display name")
42 hasTimeIndex: bool = Field(True, description="Flag indicating whether the property has a time index.")
45class PropertiesType(RootModel):
46 root: Dict[str, PropertyType]
48 def __iter__(self):
49 return iter(self.root)
51 def __getitem__(self, key):
52 return self.root[key]
54 def get(self, key, default=None):
55 return self.root.get(key, default)
57 def items(self):
58 return self.root.items()
60 def keys(self):
61 return self.root.keys()
63class ConType(StrEnum):
64 Inlet = "inlet"
65 Outlet = "outlet"
66 Branch = "branch"
69class PropertySetType(BaseModel):
70 type: Literal["All", "None", "composition", "stateVars", "exceptLast"]
71 displayName: str = Field(..., description="Display name of the property set")
72 stateVars: Tuple[str, ...] = Field(None, description="State variables of the property set")
73 toggle: str = Field(None, description="Key of property that is used to enable/disable the property set. Must be within the property set group.")
76class PortType(BaseModel):
77 displayName: str = Field(..., description="Display name of the port")
78 type: ConType = Field(..., description="Type of the port")
79 streamType: str = Field("stream", description="Type of the stream e.g stream, energy_stream")
80 many: bool = Field(None, description="Flag indicating whether the port can have multiple connections")
81 default: int = Field(None, description="Amount of ports to create if many=True")
82 minimum: int = Field(None, description="Minimum amount of ports if many=True")
83 makeStream: bool = Field(True, description="Flag indicating whether the port is a power stream port")
84 streamOffset: float = Field(0.75, description="Offset in grid units from unit opp to stream")
85 streamName: str = Field("Stream", description="default name of the stream")
87class ArgType(BaseModel):
88 PropertyPackage: str = Field(None, description="Property Package")
89 SteamPropertyPackage: str = Field(None, description="Property Package")
90 InletPropertyPackage: str = Field(None, description="Property Package")
91 OutletPropertyPackage: str = Field(None, description="Property Package")
92 Dynamic: str = Field(None, description="Is Dynamic or not")
93 HasHoldUp: str = Field(None, description="Has holdup")
94 HasPressureChange: str = Field(None, description="Pressure change")
95 NumInlets: str = Field(None, description="Number of inlets")
96 NumOutlets: str = Field(None, description="Number of outlets")
97 HotSide: str = Field(None, description="Hot side properties")
98 ColdSide: str = Field(None, description="Cold side properties")
99 EnableCoefficients: str = Field(None, description="Are coefficients enabled?")
100 ValveFunction: str = Field(None, description="Valve Function")
101 Model: str = Field(None, description="Machine Learning model")
102 IDs: str = Field(None, description="Machine Learning IDs")
103 UnitOpNames: str = Field(None, description="ML unitOp names")
106class GraphicObjectType(BaseModel):
107 width: float = Field(..., description="Width of the object")
108 height: float = Field(..., description="Height of the object")
109 autoHeight: bool = Field(False, description="Flag indicating whether the height should be automatically adjusted based on number of ports")
112class ObjectType(BaseModel):
113 displayType: str = Field(..., description="Display type of the object")
114 displayName: str | None = Field(
115 default=None, description="Display name of the object"
116 )
117 ports: Dict[PortKey, PortType] = Field(None, description="Ports contained in the object")
118 graphicObject: GraphicObjectType = Field(..., description="Graphic object of the object")
119 indexSets: List[str] = Field([], description="Index sets of the object")
120 properties: PropertiesType = Field({}, description="Properties of the object")
121 propertySetGroups: Dict[str, PropertySetType] = Field({}, description="Property set groups of the object")
122 propertyPackagePorts: Dict[str, List[PortKey]] = Field(None, description="Which ports are used by which property packages")
123 is_stream: bool = Field(False, description="Flag indicating whether the object is a stream")
124 info: str = Field(None, description="Info about the object")
125 keyProperties: List[str] | Dict[str, List[str]] = Field(None, description="Key properties of the object")
126 splitter_fraction_name: str | None = Field(None, description="Property for configuring outlet names for indexed items")