2828"""The component ID for non-existent components in the components graph.
2929
3030The non-existing component ID is commonly used in scenarios where a formula
31- engine requires a component ID but there are no available components in the
32- graph to associate with it. Thus, the non-existing component ID is subscribed
33- instead so that the formula engine can send `None` or `0` values at the same
34- frequency as the other streams.
31+ requires a component ID but there are no available components in the graph to
32+ associate with it. Thus, the non-existing component ID is subscribed instead so
33+ that the formula can send `None` or `0` values at the same frequency as the
34+ other streams.
3535"""
3636
3737
3838class FormulaPool :
39- """Creates and owns formula engines from string formulas, or formula generators .
39+ """Creates and owns formulas from string formulas.
4040
41- If an engine already exists with a given name, it is reused instead.
41+ If a formula already exists with a given name, it is reused instead.
4242 """
4343
4444 def __init__ (
@@ -62,13 +62,13 @@ def __init__(
6262 resampler_subscription_sender
6363 )
6464
65- self ._string_engines : dict [str , Formula [Quantity ]] = {}
66- self ._power_engines : dict [str , Formula [Power ]] = {}
67- self ._reactive_power_engines : dict [str , Formula [ReactivePower ]] = {}
68- self ._current_engines : dict [str , Formula3Phase [Current ]] = {}
65+ self ._string_formulas : dict [str , Formula [Quantity ]] = {}
66+ self .power_formulas : dict [str , Formula [Power ]] = {}
67+ self ._reactive_power_formulas : dict [str , Formula [ReactivePower ]] = {}
68+ self ._current_formulas : dict [str , Formula3Phase [Current ]] = {}
6969
70- self ._power_3_phase_engines : dict [str , Formula3Phase [Power ]] = {}
71- self ._current_3_phase_engines : dict [str , Formula3Phase [Current ]] = {}
70+ self ._power_3_phase_formulas : dict [str , Formula3Phase [Power ]] = {}
71+ self ._current_3_phase_formulas : dict [str , Formula3Phase [Current ]] = {}
7272
7373 def from_string (
7474 self ,
@@ -83,18 +83,18 @@ def from_string(
8383 actor.
8484
8585 Returns:
86- A Formula engine that streams values with the formulas applied.
86+ A Formula that streams values with the formulas applied.
8787 """
8888 channel_key = formula_str + str (metric .value )
89- if channel_key in self ._string_engines :
90- return self ._string_engines [channel_key ]
89+ if channel_key in self ._string_formulas :
90+ return self ._string_formulas [channel_key ]
9191 formula = parse (
9292 name = channel_key ,
9393 formula = formula_str ,
9494 telemetry_fetcher = self ._telemetry_fetcher (metric ),
9595 create_method = Quantity ,
9696 )
97- self ._string_engines [channel_key ] = formula
97+ self ._string_formulas [channel_key ] = formula
9898 return formula
9999
100100 def from_power_formula (self , channel_key : str , formula_str : str ) -> Formula [Power ]:
@@ -106,10 +106,10 @@ def from_power_formula(self, channel_key: str, formula_str: str) -> Formula[Powe
106106 formula_str: The formula string.
107107
108108 Returns:
109- A formula engine that evaluates the given formula.
109+ A formula that evaluates the given formula.
110110 """
111- if channel_key in self ._power_engines :
112- return self ._power_engines [channel_key ]
111+ if channel_key in self .power_formulas :
112+ return self .power_formulas [channel_key ]
113113
114114 if formula_str == "0.0" :
115115 formula_str = f"coalesce(#{ NON_EXISTING_COMPONENT_ID } , 0.0)"
@@ -120,7 +120,7 @@ def from_power_formula(self, channel_key: str, formula_str: str) -> Formula[Powe
120120 telemetry_fetcher = self ._telemetry_fetcher (Metric .AC_POWER_ACTIVE ),
121121 create_method = Power .from_watts ,
122122 )
123- self ._power_engines [channel_key ] = formula
123+ self .power_formulas [channel_key ] = formula
124124
125125 return formula
126126
@@ -135,10 +135,10 @@ def from_reactive_power_formula(
135135 formula_str: The formula string.
136136
137137 Returns:
138- A formula engine that evaluates the given formula.
138+ A formula that evaluates the given formula.
139139 """
140- if channel_key in self ._power_engines :
141- return self ._reactive_power_engines [channel_key ]
140+ if channel_key in self .power_formulas :
141+ return self ._reactive_power_formulas [channel_key ]
142142
143143 if formula_str == "0.0" :
144144 formula_str = f"coalesce(#{ NON_EXISTING_COMPONENT_ID } , 0.0)"
@@ -149,7 +149,7 @@ def from_reactive_power_formula(
149149 telemetry_fetcher = self ._telemetry_fetcher (Metric .AC_POWER_REACTIVE ),
150150 create_method = ReactivePower .from_volt_amperes_reactive ,
151151 )
152- self ._reactive_power_engines [channel_key ] = formula
152+ self ._reactive_power_formulas [channel_key ] = formula
153153
154154 return formula
155155
@@ -164,10 +164,10 @@ def from_power_3_phase_formula(
164164 formula_str: The formula string.
165165
166166 Returns:
167- A formula engine that evaluates the given formula.
167+ A formula that evaluates the given formula.
168168 """
169- if channel_key in self ._power_3_phase_engines :
170- return self ._power_3_phase_engines [channel_key ]
169+ if channel_key in self ._power_3_phase_formulas :
170+ return self ._power_3_phase_formulas [channel_key ]
171171
172172 if formula_str == "0.0" :
173173 formula_str = f"coalesce(#{ NON_EXISTING_COMPONENT_ID } , 0.0)"
@@ -199,7 +199,7 @@ def from_power_3_phase_formula(
199199 create_method = Power .from_watts ,
200200 ),
201201 )
202- self ._power_3_phase_engines [channel_key ] = formula
202+ self ._power_3_phase_formulas [channel_key ] = formula
203203
204204 return formula
205205
@@ -214,10 +214,10 @@ def from_current_3_phase_formula(
214214 formula_str: The formula string.
215215
216216 Returns:
217- A formula engine that evaluates the given formula.
217+ A formula that evaluates the given formula.
218218 """
219- if channel_key in self ._current_3_phase_engines :
220- return self ._current_3_phase_engines [channel_key ]
219+ if channel_key in self ._current_3_phase_formulas :
220+ return self ._current_3_phase_formulas [channel_key ]
221221
222222 if formula_str == "0.0" :
223223 formula_str = f"coalesce(#{ NON_EXISTING_COMPONENT_ID } , 0.0)"
@@ -243,27 +243,27 @@ def from_current_3_phase_formula(
243243 create_method = Current .from_amperes ,
244244 ),
245245 )
246- self ._current_3_phase_engines [channel_key ] = formula
246+ self ._current_3_phase_formulas [channel_key ] = formula
247247
248248 return formula
249249
250250 async def stop (self ) -> None :
251- """Stop all formula engines ."""
252- for pf in self ._power_engines .values ():
251+ """Stop all formulas ."""
252+ for pf in self .power_formulas .values ():
253253 await pf .stop ()
254- self ._power_engines .clear ()
254+ self .power_formulas .clear ()
255255
256- for rpf in self ._reactive_power_engines .values ():
256+ for rpf in self ._reactive_power_formulas .values ():
257257 await rpf .stop ()
258- self ._reactive_power_engines .clear ()
258+ self ._reactive_power_formulas .clear ()
259259
260- for p3pf in self ._power_3_phase_engines .values ():
260+ for p3pf in self ._power_3_phase_formulas .values ():
261261 await p3pf .stop ()
262- self ._power_3_phase_engines .clear ()
262+ self ._power_3_phase_formulas .clear ()
263263
264- for c3pf in self ._current_3_phase_engines .values ():
264+ for c3pf in self ._current_3_phase_formulas .values ():
265265 await c3pf .stop ()
266- self ._current_3_phase_engines .clear ()
266+ self ._current_3_phase_formulas .clear ()
267267
268268 def _telemetry_fetcher (self , metric : Metric ) -> ResampledStreamFetcher :
269269 """Create a ResampledStreamFetcher for the given metric.
0 commit comments