feature: add custom hashrate types and conversion.

This commit is contained in:
Upstream Data
2024-05-09 15:01:40 -06:00
parent f6a134342a
commit 7eb61473a8
24 changed files with 314 additions and 108 deletions

View File

@@ -17,7 +17,7 @@
from typing import List, Optional
from pyasic.config import MinerConfig
from pyasic.data import Fan, HashBoard
from pyasic.data import AlgoHashRate, Fan, HashBoard, HashUnit
from pyasic.errors import APIError
from pyasic.miners.data import DataFunction, DataLocations, DataOptions, RPCAPICommand
from pyasic.miners.device.firmware import StockFirmware
@@ -119,7 +119,9 @@ class BMMiner(StockFirmware):
if rpc_summary is not None:
try:
return round(float(rpc_summary["SUMMARY"][0]["GHS 5s"] / 1000), 2)
return AlgoHashRate.SHA256(
rpc_summary["SUMMARY"][0]["GHS 5s"], HashUnit.SHA256.GH
).into(self.algo.unit.default)
except (LookupError, ValueError, TypeError):
pass
@@ -176,7 +178,9 @@ class BMMiner(StockFirmware):
hashrate = boards[1].get(f"chain_rate{i}")
if hashrate:
hashboard.hashrate = round(float(hashrate) / 1000, 2)
hashboard.hashrate = AlgoHashRate.SHA256(
hashrate, HashUnit.SHA256.GH
).into(self.algo.unit.default)
chips = boards[1].get(f"chain_acn{i}")
if chips:
@@ -234,12 +238,9 @@ class BMMiner(StockFirmware):
rate_unit = rpc_stats["STATS"][1]["rate_unit"]
except KeyError:
rate_unit = "GH"
if rate_unit == "GH":
return round(expected_rate / 1000, 2)
if rate_unit == "MH":
return round(expected_rate / 1000000, 2)
else:
return round(expected_rate, 2)
return AlgoHashRate.SHA256(
expected_rate, HashUnit.SHA256.from_str(rate_unit)
).int(self.algo.unit.default)
except LookupError:
pass