improved handling of MinerData by improving dataclass

This commit is contained in:
UpstreamData
2022-05-25 14:01:52 -06:00
parent 6fbd9faffd
commit 3b702aac2c

View File

@@ -1,4 +1,4 @@
from dataclasses import dataclass from dataclasses import dataclass, field, asdict
@dataclass @dataclass
@@ -13,15 +13,37 @@ class MinerData:
left_chips: int = 0 left_chips: int = 0
center_chips: int = 0 center_chips: int = 0
right_chips: int = 0 right_chips: int = 0
total_chips: int = field(init=False)
nominal: int = field(init=False)
pool_split: str = 0 pool_split: str = 0
pool_1_url: str = "Unknown" pool_1_url: str = "Unknown"
pool_1_user: str = "Unknown" pool_1_user: str = "Unknown"
pool_2_url: str = "" pool_2_url: str = ""
pool_2_user: str = "" pool_2_user: str = ""
@property
def total_chips(self): # noqa - Skip PyCharm inspection
return self.right_chips + self.center_chips + self.left_chips
@total_chips.setter
def total_chips(self, val):
pass
@property
def nominal(self): # noqa - Skip PyCharm inspection
return self.ideal_chips == self.total_chips
@nominal.setter
def nominal(self, val):
pass
def __post_init__(self): def __post_init__(self):
self.total_chips = self.right_chips + self.center_chips + self.left_chips self.total_chips = self.right_chips + self.center_chips + self.left_chips
self.nominal = self.ideal_chips == self.total_chips self.nominal = self.ideal_chips == self.total_chips
def asdict(self): def asdict(self):
return {k: v for k, v in self.__dict__.items()} return asdict(self)
if __name__ == "__main__":
print(MinerData(ip="192.168.1.1").asdict())