From 853756ebcb901ac41a5c8f80634258ff8ee53ebc Mon Sep 17 00:00:00 2001 From: UpstreamData Date: Thu, 13 Apr 2023 14:26:03 -0600 Subject: [PATCH] feature: sum hashrate in MinerData from hashboards, with the hashrate item being a backup. --- pyasic/data/__init__.py | 13 ++++++++++++- pyasic/miners/btc/antminer/hiveon/X9/T9.py | 1 - 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pyasic/data/__init__.py b/pyasic/data/__init__.py index bfaab8a7..591782c4 100644 --- a/pyasic/data/__init__.py +++ b/pyasic/data/__init__.py @@ -116,7 +116,8 @@ class MinerData: api_ver: str = "Unknown" fw_ver: str = "Unknown" hostname: str = "Unknown" - hashrate: float = 0 + hashrate: float = field(init=False) + _hashrate: float = field(init=False) nominal_hashrate: float = 0 hashboards: List[HashBoard] = field(default_factory=list) ideal_hashboards: int = 1 @@ -213,6 +214,16 @@ class MinerData: setattr(cp, key, item & other_item) return cp + @property + def hashrate(self): # noqa - Skip PyCharm inspection + if len(self.hashboards) > 0: + return round(sum(map(lambda x: x.hashrate, self.hashboards)), 2) + return self._hashrate + + @hashrate.setter + def hashrate(self, val): + self._hashrate = val + @property def fan_1(self): # noqa - Skip PyCharm inspection if len(self.fans) > 0: diff --git a/pyasic/miners/btc/antminer/hiveon/X9/T9.py b/pyasic/miners/btc/antminer/hiveon/X9/T9.py index 0effec2f..8fe80344 100644 --- a/pyasic/miners/btc/antminer/hiveon/X9/T9.py +++ b/pyasic/miners/btc/antminer/hiveon/X9/T9.py @@ -69,7 +69,6 @@ class HiveonT9(Hiveon, T9): try: hashrate += api_stats["STATS"][1][f"chain_rate{chipset}"] chips += api_stats["STATS"][1][f"chain_acn{chipset}"] - print(chips) except (KeyError, IndexError): pass hashboard.hashrate = round(hashrate / 1000, 2)