Compare commits
3
Commits
149e98c543
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a484e2fe15 | ||
|
|
4cb9cfa8fa | ||
|
|
ca498db3bc |
+21
-12
@@ -41,12 +41,12 @@ class ThermalCapWrapper:
|
|||||||
clock = get_component("clock")
|
clock = get_component("clock")
|
||||||
default_threshold = 0.98
|
default_threshold = 0.98
|
||||||
|
|
||||||
def __init__(self, cap: ThermalCap | str, threshold: float = 0.99, outposts: list[OutpostComponent] | OutpostComponent | OutpostRef | str | None = None):
|
def __init__(self, cap: ThermalCap | str, threshold: float = 0.98, outposts: list[OutpostComponent] | OutpostComponent | OutpostRef | str | None = None):
|
||||||
"""init wrapper for `ThermalCap`
|
"""init wrapper for `ThermalCap`
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
cap (`ThermalCap`): thermal cap component. usally self.
|
cap (`ThermalCap`): thermal cap component. usally self.
|
||||||
threshold (`float`, optional): percent level what thermal cap hold this pressure level. (0-1). default 0.99.
|
threshold (`float`, optional): percent level what thermal cap hold this pressure level. (0-1). default 0.98.
|
||||||
outpost (`OutpostComposnent` | `OutpostRef` | `str` | `None`, optional): outpost for steam out. None = nearest. default None.
|
outpost (`OutpostComposnent` | `OutpostRef` | `str` | `None`, optional): outpost for steam out. None = nearest. default None.
|
||||||
"""
|
"""
|
||||||
self.cap = cap
|
self.cap = cap
|
||||||
@@ -125,7 +125,7 @@ class ThermalCapWrapper:
|
|||||||
@property
|
@property
|
||||||
def cap(self) -> ThermalCap:
|
def cap(self) -> ThermalCap:
|
||||||
if isinstance(self.__cap, ThermalCap): return self.__cap
|
if isinstance(self.__cap, ThermalCap): return self.__cap
|
||||||
raise TypeError(f"{self.__cap=} ({type(self.__cap)=} is not a ThermalCap)")
|
raise TypeError(f"{self.__cap=} ({type(self.__cap)=}) is not a ThermalCap)")
|
||||||
|
|
||||||
@cap.setter
|
@cap.setter
|
||||||
def cap(self, value: ThermalCap | str):
|
def cap(self, value: ThermalCap | str):
|
||||||
@@ -177,6 +177,7 @@ class SteamTurbineWrapper:
|
|||||||
"""wrapper class wor `SteamTurbine`"""
|
"""wrapper class wor `SteamTurbine`"""
|
||||||
default_threshold = 25
|
default_threshold = 25
|
||||||
notify_threshold = 10
|
notify_threshold = 10
|
||||||
|
notify_timeout = 100
|
||||||
|
|
||||||
def __init__(self, turbine: SteamTurbine, threshold: int = 25, storages: list[GasTank] = None):
|
def __init__(self, turbine: SteamTurbine, threshold: int = 25, storages: list[GasTank] = None):
|
||||||
"""init wrapper for `SteamTurbine`
|
"""init wrapper for `SteamTurbine`
|
||||||
@@ -191,6 +192,7 @@ class SteamTurbineWrapper:
|
|||||||
self.storages = storages
|
self.storages = storages
|
||||||
self.pcontrol = get_component("power_control")
|
self.pcontrol = get_component("power_control")
|
||||||
self.steam_in = turbine.steam_in
|
self.steam_in = turbine.steam_in
|
||||||
|
self.__notify_timeout = 0
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""run loop for `SteamTurbine`"""
|
"""run loop for `SteamTurbine`"""
|
||||||
@@ -201,11 +203,19 @@ class SteamTurbineWrapper:
|
|||||||
|
|
||||||
def check_health(self):
|
def check_health(self):
|
||||||
"""check own function and notify if not in expected parameters"""
|
"""check own function and notify if not in expected parameters"""
|
||||||
if self.steam_in.level() < self.notify_threshold:
|
if self.__notify_timeout:
|
||||||
notify(f"{self.turbine.id}: steam level under {self.notify_threshold}", "warn", 30)
|
self.__notify_timeout -= 1
|
||||||
|
return
|
||||||
if self.turbine.is_stalled() or self.steam_in.level() == 0:
|
if self.turbine.is_stalled() or self.steam_in.level() == 0:
|
||||||
notify(f"{self.turbine.id}: stopped working or has low efficency ({self.turbine.efficiency()*100}%)", "error", 30)
|
notify(f"{self.turbine.id}: stopped working or has low efficency ({self.turbine.efficiency()*100}%)", "error", 30)
|
||||||
sleep(30)
|
return
|
||||||
|
if self.turbine.power_output() == 108 and get_component("power_control").grid(self.turbine.id).net < self.notify_threshold * -1:
|
||||||
|
notify(f"{self.turbine.id}: insufficient energy supply", "error", 30)
|
||||||
|
return
|
||||||
|
if self.steam_in.level() < self.notify_threshold:
|
||||||
|
notify(f"{self.turbine.id}: steam level under {self.notify_threshold}", "warn", 30)
|
||||||
|
return
|
||||||
|
self.notify_timeout = 100
|
||||||
|
|
||||||
def fill_steam(self):
|
def fill_steam(self):
|
||||||
"""fills steam if own steam under threshold"""
|
"""fills steam if own steam under threshold"""
|
||||||
@@ -248,19 +258,18 @@ class SteamTurbineWrapper:
|
|||||||
`list[GasTank]`
|
`list[GasTank]`
|
||||||
"""
|
"""
|
||||||
gastanks = [ get_component(s.id) for s in get_component(self.turbine.outpost.id).buildings("gas_tank") ]
|
gastanks = [ get_component(s.id) for s in get_component(self.turbine.outpost.id).buildings("gas_tank") ]
|
||||||
if prefiled:
|
if prefiled: return [ s for s in gastanks if s.fluid() == "steam" ]
|
||||||
return [ s for s in gastanks if s.fluid() == "steam" ]
|
|
||||||
else: return gastanks
|
else: return gastanks
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def turbine(self) -> SteamTurbine:
|
def turbine(self) -> SteamTurbine:
|
||||||
if isinstance(self.__turbine, SteamTurbine): return self.__turbine
|
if isinstance(self.__turbine, SteamTurbine): return self.__turbine
|
||||||
raise TypeError(f"{self.__turbine=} ({type(self.__turbine)=} is not a SteamTurbine)")
|
raise TypeError(f"{self.__turbine=} ({type(self.__turbine)=}) is not a SteamTurbine)")
|
||||||
|
|
||||||
@turbine.setter
|
@turbine.setter
|
||||||
def turbine(self, value: SteamTurbine | str):
|
def turbine(self, value: SteamTurbine | str):
|
||||||
if isinstance(value, str): value = get_component(value)
|
if isinstance(value, str): value = get_component(value)
|
||||||
if not isinstance(value, SteamTurbine): raise TypeError(f"{self.__turbine=} ({type(self.__turbine)=} is not a SteamTurbine)")
|
if not isinstance(value, SteamTurbine): raise TypeError(f"{self.__turbine=} ({type(self.__turbine)=}) is not a SteamTurbine)")
|
||||||
self.__turbine = value
|
self.__turbine = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -276,7 +285,7 @@ class SteamTurbineWrapper:
|
|||||||
@threshold.setter
|
@threshold.setter
|
||||||
def threshold(self, value: int):
|
def threshold(self, value: int):
|
||||||
if not isinstance(value, int) or not 0 < value < 100:
|
if not isinstance(value, int) or not 0 < value < 100:
|
||||||
warn(f"set threshold: {value=} ({type(value)=} is not a int, use {self.default_threshold=}")
|
warn(f"set threshold: {value=} ({type(value)=}) is not a int, use {self.default_threshold=}")
|
||||||
self.__threshold = self.default_threshold
|
self.__threshold = self.default_threshold
|
||||||
return
|
return
|
||||||
self.__threshold = value
|
self.__threshold = value
|
||||||
@@ -298,5 +307,5 @@ class SteamTurbineWrapper:
|
|||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
self.__storages = [ s for s in value if isinstance(s, GasTank) ]
|
self.__storages = [ s for s in value if isinstance(s, GasTank) ]
|
||||||
return
|
return
|
||||||
warn(f"set storages: given {value=} ({type(value)=} has incorrect type, use default.")
|
warn(f"set storages: given {value=} ({type(value)=}) has incorrect type, use default.")
|
||||||
self.__storages = self.get_local_storages()
|
self.__storages = self.get_local_storages()
|
||||||
|
|||||||
Reference in New Issue
Block a user