refactor: more optimizations to hashrate types with metaclass

This commit is contained in:
Upstream Data
2024-11-21 15:30:01 -07:00
parent 82552390c8
commit 01b96227e0
24 changed files with 129 additions and 457 deletions

View File

@@ -12,7 +12,7 @@ class DeviceInfo(BaseModel):
make: MinerMake | None = None
model: MinerModelType | None = None
firmware: MinerFirmware | None = None
algo: MinerAlgoType | None = None
algo: type[MinerAlgoType] | None = None
@field_serializer("make")
def serialize_make(self, make: MinerMake, _info):

View File

@@ -4,6 +4,13 @@ from .hashrate.base import AlgoHashRateType
from .hashrate.unit.base import AlgoHashRateUnitType
class MinerAlgoType(str):
class MinerAlgoMeta(type):
name: str
def __str__(cls):
return cls.name
class MinerAlgoType(metaclass=MinerAlgoMeta):
hashrate: type[AlgoHashRateType]
unit: type[AlgoHashRateUnitType]

View File

@@ -6,12 +6,8 @@ from .hashrate.unit import Blake256Unit
# make this json serializable
class _Blake256Algo(MinerAlgoType):
hashrate = Blake256HashRate
unit = Blake256Unit
class Blake256Algo(MinerAlgoType):
hashrate: type[Blake256HashRate] = Blake256HashRate
unit: type[Blake256Unit] = Blake256Unit
def __repr__(self):
return "Blake256Algo"
Blake256Algo = _Blake256Algo("Blake256")
name = "Blake256"

View File

@@ -6,12 +6,8 @@ from .hashrate.unit import EaglesongUnit
# make this json serializable
class _EaglesongAlgo(MinerAlgoType):
hashrate = EaglesongHashRate
unit = EaglesongUnit
class EaglesongAlgo(MinerAlgoType):
hashrate: type[EaglesongHashRate] = EaglesongHashRate
unit: type[EaglesongUnit] = EaglesongUnit
def __repr__(self):
return "EaglesongAlgo"
EaglesongAlgo = _EaglesongAlgo("Eaglesong")
name = "Eaglesong"

View File

@@ -6,12 +6,8 @@ from .hashrate.unit import EquihashUnit
# make this json serializable
class _EquihashAlgo(MinerAlgoType):
hashrate = EquihashHashRate
unit = EquihashUnit
class EquihashAlgo(MinerAlgoType):
hashrate: type[EquihashHashRate] = EquihashHashRate
unit: type[EquihashUnit] = EquihashUnit
def __repr__(self):
return "EquihashAlgo"
EquihashAlgo = _EquihashAlgo("Equihash")
name = "Equihash"

View File

@@ -5,13 +5,8 @@ from .hashrate import EtHashHashRate
from .hashrate.unit import EtHashUnit
# make this json serializable
class _EtHashAlgo(MinerAlgoType):
hashrate = EtHashHashRate
unit = EtHashUnit
class EtHashAlgo(MinerAlgoType):
hashrate: type[EtHashHashRate] = EtHashHashRate
unit: type[EtHashUnit] = EtHashUnit
def __repr__(self):
return "EtHashAlgo"
EtHashAlgo = _EtHashAlgo("EtHash")
name = "EtHash"

View File

@@ -6,12 +6,8 @@ from .hashrate.unit import HandshakeUnit
# make this json serializable
class _HandshakeAlgo(MinerAlgoType):
hashrate = HandshakeHashRate
unit = HandshakeUnit
class HandshakeAlgo(MinerAlgoType):
hashrate: type[HandshakeHashRate] = HandshakeHashRate
unit: type[HandshakeUnit] = HandshakeUnit
def __repr__(self):
return "HandshakeAlgo"
HandshakeAlgo = _HandshakeAlgo("Handshake")
name = "Handshake"

View File

@@ -1,6 +1,7 @@
from abc import ABC, abstractmethod
from typing import Self
from pydantic import BaseModel
from pydantic import BaseModel, Field
from .unit.base import AlgoHashRateUnitType
@@ -24,3 +25,38 @@ class AlgoHashRateType(BaseModel, ABC):
def __round__(self, n: int = None):
return round(self.rate, n)
def __add__(self, other: Self | int | float) -> Self:
if isinstance(other, self.__class__):
return self.__class__(
rate=self.rate + other.into(self.unit).rate, unit=self.unit
)
return self.__class__(rate=self.rate + other, unit=self.unit)
def __sub__(self, other: Self | int | float) -> Self:
if isinstance(other, self.__class__):
return self.__class__(
rate=self.rate - other.into(self.unit).rate, unit=self.unit
)
return self.__class__(rate=self.rate - other, unit=self.unit)
def __truediv__(self, other: Self | int | float) -> Self:
if isinstance(other, self.__class__):
return self.__class__(
rate=self.rate / other.into(self.unit).rate, unit=self.unit
)
return self.__class__(rate=self.rate / other, unit=self.unit)
def __floordiv__(self, other: Self | int | float) -> Self:
if isinstance(other, self.__class__):
return self.__class__(
rate=self.rate // other.into(self.unit).rate, unit=self.unit
)
return self.__class__(rate=self.rate // other, unit=self.unit)
def __mul__(self, other: Self | int | float) -> Self:
if isinstance(other, self.__class__):
return self.__class__(
rate=self.rate * other.into(self.unit).rate, unit=self.unit
)
return self.__class__(rate=self.rate * other, unit=self.unit)

View File

@@ -1,5 +1,7 @@
from __future__ import annotations
from typing import Self
from pyasic.device.algorithm.hashrate.base import AlgoHashRateType
from pyasic.device.algorithm.hashrate.unit.blake256 import Blake256Unit
@@ -10,42 +12,7 @@ class Blake256HashRate(AlgoHashRateType):
rate: float
unit: Blake256Unit = HashUnit.BLAKE256.default
def __add__(self, other: Blake256HashRate | int | float) -> Blake256HashRate:
if isinstance(other, Blake256HashRate):
return Blake256HashRate(
rate=self.rate + other.into(self.unit).rate, unit=self.unit
)
return Blake256HashRate(rate=self.rate + other, unit=self.unit)
def __sub__(self, other: Blake256HashRate | int | float) -> Blake256HashRate:
if isinstance(other, Blake256HashRate):
return Blake256HashRate(
rate=self.rate - other.into(self.unit).rate, unit=self.unit
)
return Blake256HashRate(rate=self.rate - other, unit=self.unit)
def __truediv__(self, other: Blake256HashRate | int | float):
if isinstance(other, Blake256HashRate):
return Blake256HashRate(
rate=self.rate / other.into(self.unit).rate, unit=self.unit
)
return Blake256HashRate(rate=self.rate / other, unit=self.unit)
def __floordiv__(self, other: Blake256HashRate | int | float):
if isinstance(other, Blake256HashRate):
return Blake256HashRate(
rate=self.rate // other.into(self.unit).rate, unit=self.unit
)
return Blake256HashRate(rate=self.rate // other, unit=self.unit)
def __mul__(self, other: Blake256HashRate | int | float):
if isinstance(other, Blake256HashRate):
return Blake256HashRate(
rate=self.rate * other.into(self.unit).rate, unit=self.unit
)
return Blake256HashRate(rate=self.rate * other, unit=self.unit)
def into(self, other: Blake256Unit) -> Blake256HashRate:
return Blake256HashRate(
def into(self, other: Blake256Unit) -> Self:
return self.__class__(
rate=self.rate / (other.value / self.unit.value), unit=other
)

View File

@@ -1,5 +1,7 @@
from __future__ import annotations
from typing import Self
from pyasic.device.algorithm.hashrate.base import AlgoHashRateType
from pyasic.device.algorithm.hashrate.unit.eaglesong import EaglesongUnit
@@ -10,42 +12,7 @@ class EaglesongHashRate(AlgoHashRateType):
rate: float
unit: EaglesongUnit = HashUnit.EAGLESONG.default
def __add__(self, other: EaglesongHashRate | int | float) -> EaglesongHashRate:
if isinstance(other, EaglesongHashRate):
return EaglesongHashRate(
rate=self.rate + other.into(self.unit).rate, unit=self.unit
)
return EaglesongHashRate(rate=self.rate + other, unit=self.unit)
def __sub__(self, other: EaglesongHashRate | int | float) -> EaglesongHashRate:
if isinstance(other, EaglesongHashRate):
return EaglesongHashRate(
rate=self.rate - other.into(self.unit).rate, unit=self.unit
)
return EaglesongHashRate(rate=self.rate - other, unit=self.unit)
def __truediv__(self, other: EaglesongHashRate | int | float):
if isinstance(other, EaglesongHashRate):
return EaglesongHashRate(
rate=self.rate / other.into(self.unit).rate, unit=self.unit
)
return EaglesongHashRate(rate=self.rate / other, unit=self.unit)
def __floordiv__(self, other: EaglesongHashRate | int | float):
if isinstance(other, EaglesongHashRate):
return EaglesongHashRate(
rate=self.rate // other.into(self.unit).rate, unit=self.unit
)
return EaglesongHashRate(rate=self.rate // other, unit=self.unit)
def __mul__(self, other: EaglesongHashRate | int | float):
if isinstance(other, EaglesongHashRate):
return EaglesongHashRate(
rate=self.rate * other.into(self.unit).rate, unit=self.unit
)
return EaglesongHashRate(rate=self.rate * other, unit=self.unit)
def into(self, other: EaglesongUnit) -> EaglesongHashRate:
return EaglesongHashRate(
def into(self, other: EaglesongUnit) -> Self:
return self.__class__(
rate=self.rate / (other.value / self.unit.value), unit=other
)

View File

@@ -1,5 +1,7 @@
from __future__ import annotations
from typing import Self
from pyasic.device.algorithm.hashrate.base import AlgoHashRateType
from pyasic.device.algorithm.hashrate.unit.equihash import EquihashUnit
@@ -10,42 +12,7 @@ class EquihashHashRate(AlgoHashRateType):
rate: float
unit: EquihashUnit = HashUnit.ETHASH.default
def __add__(self, other: EquihashHashRate | int | float) -> EquihashHashRate:
if isinstance(other, EquihashHashRate):
return EquihashHashRate(
rate=self.rate + other.into(self.unit).rate, unit=self.unit
)
return EquihashHashRate(rate=self.rate + other, unit=self.unit)
def __sub__(self, other: EquihashHashRate | int | float) -> EquihashHashRate:
if isinstance(other, EquihashHashRate):
return EquihashHashRate(
rate=self.rate - other.into(self.unit).rate, unit=self.unit
)
return EquihashHashRate(rate=self.rate - other, unit=self.unit)
def __truediv__(self, other: EquihashHashRate | int | float):
if isinstance(other, EquihashHashRate):
return EquihashHashRate(
rate=self.rate / other.into(self.unit).rate, unit=self.unit
)
return EquihashHashRate(rate=self.rate / other, unit=self.unit)
def __floordiv__(self, other: EquihashHashRate | int | float):
if isinstance(other, EquihashHashRate):
return EquihashHashRate(
rate=self.rate // other.into(self.unit).rate, unit=self.unit
)
return EquihashHashRate(rate=self.rate // other, unit=self.unit)
def __mul__(self, other: EquihashHashRate | int | float):
if isinstance(other, EquihashHashRate):
return EquihashHashRate(
rate=self.rate * other.into(self.unit).rate, unit=self.unit
)
return EquihashHashRate(rate=self.rate * other, unit=self.unit)
def into(self, other: EquihashUnit) -> EquihashHashRate:
return EquihashHashRate(
def into(self, other: EquihashUnit) -> Self:
return self.__class__(
rate=self.rate / (other.value / self.unit.value), unit=other
)

View File

@@ -1,5 +1,7 @@
from __future__ import annotations
from typing import Self
from pyasic.device.algorithm.hashrate.base import AlgoHashRateType
from pyasic.device.algorithm.hashrate.unit.ethash import EtHashUnit
@@ -10,42 +12,7 @@ class EtHashHashRate(AlgoHashRateType):
rate: float
unit: EtHashUnit = HashUnit.ETHASH.default
def __add__(self, other: EtHashHashRate | int | float) -> EtHashHashRate:
if isinstance(other, EtHashHashRate):
return EtHashHashRate(
rate=self.rate + other.into(self.unit).rate, unit=self.unit
)
return EtHashHashRate(rate=self.rate + other, unit=self.unit)
def __sub__(self, other: EtHashHashRate | int | float) -> EtHashHashRate:
if isinstance(other, EtHashHashRate):
return EtHashHashRate(
rate=self.rate - other.into(self.unit).rate, unit=self.unit
)
return EtHashHashRate(rate=self.rate - other, unit=self.unit)
def __truediv__(self, other: EtHashHashRate | int | float):
if isinstance(other, EtHashHashRate):
return EtHashHashRate(
rate=self.rate / other.into(self.unit).rate, unit=self.unit
)
return EtHashHashRate(rate=self.rate / other, unit=self.unit)
def __floordiv__(self, other: EtHashHashRate | int | float):
if isinstance(other, EtHashHashRate):
return EtHashHashRate(
rate=self.rate // other.into(self.unit).rate, unit=self.unit
)
return EtHashHashRate(rate=self.rate // other, unit=self.unit)
def __mul__(self, other: EtHashHashRate | int | float):
if isinstance(other, EtHashHashRate):
return EtHashHashRate(
rate=self.rate * other.into(self.unit).rate, unit=self.unit
)
return EtHashHashRate(rate=self.rate * other, unit=self.unit)
def into(self, other: EtHashUnit) -> EtHashHashRate:
return EtHashHashRate(
def into(self, other: EtHashUnit) -> Self:
return self.__class__(
rate=self.rate / (other.value / self.unit.value), unit=other
)

View File

@@ -1,5 +1,7 @@
from __future__ import annotations
from typing import Self
from pyasic.device.algorithm.hashrate.base import AlgoHashRateType
from pyasic.device.algorithm.hashrate.unit.handshake import HandshakeUnit
@@ -10,42 +12,7 @@ class HandshakeHashRate(AlgoHashRateType):
rate: float
unit: HandshakeUnit = HashUnit.HANDSHAKE.default
def __add__(self, other: HandshakeHashRate | int | float) -> HandshakeHashRate:
if isinstance(other, HandshakeHashRate):
return HandshakeHashRate(
rate=self.rate + other.into(self.unit).rate, unit=self.unit
)
return HandshakeHashRate(rate=self.rate + other, unit=self.unit)
def __sub__(self, other: HandshakeHashRate | int | float) -> HandshakeHashRate:
if isinstance(other, HandshakeHashRate):
return HandshakeHashRate(
rate=self.rate - other.into(self.unit).rate, unit=self.unit
)
return HandshakeHashRate(rate=self.rate - other, unit=self.unit)
def __truediv__(self, other: HandshakeHashRate | int | float):
if isinstance(other, HandshakeHashRate):
return HandshakeHashRate(
rate=self.rate / other.into(self.unit).rate, unit=self.unit
)
return HandshakeHashRate(rate=self.rate / other, unit=self.unit)
def __floordiv__(self, other: HandshakeHashRate | int | float):
if isinstance(other, HandshakeHashRate):
return HandshakeHashRate(
rate=self.rate // other.into(self.unit).rate, unit=self.unit
)
return HandshakeHashRate(rate=self.rate // other, unit=self.unit)
def __mul__(self, other: HandshakeHashRate | int | float):
if isinstance(other, HandshakeHashRate):
return HandshakeHashRate(
rate=self.rate * other.into(self.unit).rate, unit=self.unit
)
return HandshakeHashRate(rate=self.rate * other, unit=self.unit)
def into(self, other: HandshakeUnit) -> HandshakeHashRate:
return HandshakeHashRate(
def into(self, other: HandshakeUnit) -> Self:
return self.__class__(
rate=self.rate / (other.value / self.unit.value), unit=other
)

View File

@@ -1,5 +1,7 @@
from __future__ import annotations
from typing import Self
from pyasic.device.algorithm.hashrate.base import AlgoHashRateType
from pyasic.device.algorithm.hashrate.unit.kadena import KadenaUnit
@@ -10,42 +12,7 @@ class KadenaHashRate(AlgoHashRateType):
rate: float
unit: KadenaUnit = HashUnit.KADENA.default
def __add__(self, other: KadenaHashRate | int | float) -> KadenaHashRate:
if isinstance(other, KadenaHashRate):
return KadenaHashRate(
rate=self.rate + other.into(self.unit).rate, unit=self.unit
)
return KadenaHashRate(rate=self.rate + other, unit=self.unit)
def __sub__(self, other: KadenaHashRate | int | float) -> KadenaHashRate:
if isinstance(other, KadenaHashRate):
return KadenaHashRate(
rate=self.rate - other.into(self.unit).rate, unit=self.unit
)
return KadenaHashRate(rate=self.rate - other, unit=self.unit)
def __truediv__(self, other: KadenaHashRate | int | float):
if isinstance(other, KadenaHashRate):
return KadenaHashRate(
rate=self.rate / other.into(self.unit).rate, unit=self.unit
)
return KadenaHashRate(rate=self.rate / other, unit=self.unit)
def __floordiv__(self, other: KadenaHashRate | int | float):
if isinstance(other, KadenaHashRate):
return KadenaHashRate(
rate=self.rate // other.into(self.unit).rate, unit=self.unit
)
return KadenaHashRate(rate=self.rate // other, unit=self.unit)
def __mul__(self, other: KadenaHashRate | int | float):
if isinstance(other, KadenaHashRate):
return KadenaHashRate(
rate=self.rate * other.into(self.unit).rate, unit=self.unit
)
return KadenaHashRate(rate=self.rate * other, unit=self.unit)
def into(self, other: KadenaUnit) -> KadenaHashRate:
return KadenaHashRate(
def into(self, other: KadenaUnit) -> Self:
return self.__class__(
rate=self.rate / (other.value / self.unit.value), unit=other
)

View File

@@ -1,5 +1,7 @@
from __future__ import annotations
from typing import Self
from pyasic.device.algorithm.hashrate.base import AlgoHashRateType
from pyasic.device.algorithm.hashrate.unit.kheavyhash import KHeavyHashUnit
@@ -10,42 +12,7 @@ class KHeavyHashHashRate(AlgoHashRateType):
rate: float
unit: KHeavyHashUnit = HashUnit.KHEAVYHASH.default
def __add__(self, other: KHeavyHashHashRate | int | float) -> KHeavyHashHashRate:
if isinstance(other, KHeavyHashHashRate):
return KHeavyHashHashRate(
rate=self.rate + other.into(self.unit).rate, unit=self.unit
)
return KHeavyHashHashRate(rate=self.rate + other, unit=self.unit)
def __sub__(self, other: KHeavyHashHashRate | int | float) -> KHeavyHashHashRate:
if isinstance(other, KHeavyHashHashRate):
return KHeavyHashHashRate(
rate=self.rate - other.into(self.unit).rate, unit=self.unit
)
return KHeavyHashHashRate(rate=self.rate - other, unit=self.unit)
def __truediv__(self, other: KHeavyHashHashRate | int | float):
if isinstance(other, KHeavyHashHashRate):
return KHeavyHashHashRate(
rate=self.rate / other.into(self.unit).rate, unit=self.unit
)
return KHeavyHashHashRate(rate=self.rate / other, unit=self.unit)
def __floordiv__(self, other: KHeavyHashHashRate | int | float):
if isinstance(other, KHeavyHashHashRate):
return KHeavyHashHashRate(
rate=self.rate // other.into(self.unit).rate, unit=self.unit
)
return KHeavyHashHashRate(rate=self.rate // other, unit=self.unit)
def __mul__(self, other: KHeavyHashHashRate | int | float):
if isinstance(other, KHeavyHashHashRate):
return KHeavyHashHashRate(
rate=self.rate * other.into(self.unit).rate, unit=self.unit
)
return KHeavyHashHashRate(rate=self.rate * other, unit=self.unit)
def into(self, other: KHeavyHashUnit) -> KHeavyHashHashRate:
return KHeavyHashHashRate(
def into(self, other: KHeavyHashUnit) -> Self:
return self.__class__(
rate=self.rate / (other.value / self.unit.value), unit=other
)

View File

@@ -1,5 +1,7 @@
from __future__ import annotations
from typing import Self
from pyasic.device.algorithm.hashrate.base import AlgoHashRateType
from pyasic.device.algorithm.hashrate.unit.scrypt import ScryptUnit
@@ -10,42 +12,7 @@ class ScryptHashRate(AlgoHashRateType):
rate: float
unit: ScryptUnit = HashUnit.SCRYPT.default
def __add__(self, other: ScryptHashRate | int | float) -> ScryptHashRate:
if isinstance(other, ScryptHashRate):
return ScryptHashRate(
rate=self.rate + other.into(self.unit).rate, unit=self.unit
)
return ScryptHashRate(rate=self.rate + other, unit=self.unit)
def __sub__(self, other: ScryptHashRate | int | float) -> ScryptHashRate:
if isinstance(other, ScryptHashRate):
return ScryptHashRate(
rate=self.rate - other.into(self.unit).rate, unit=self.unit
)
return ScryptHashRate(rate=self.rate - other, unit=self.unit)
def __truediv__(self, other: ScryptHashRate | int | float):
if isinstance(other, ScryptHashRate):
return ScryptHashRate(
rate=self.rate / other.into(self.unit).rate, unit=self.unit
)
return ScryptHashRate(rate=self.rate / other, unit=self.unit)
def __floordiv__(self, other: ScryptHashRate | int | float):
if isinstance(other, ScryptHashRate):
return ScryptHashRate(
rate=self.rate // other.into(self.unit).rate, unit=self.unit
)
return ScryptHashRate(rate=self.rate // other, unit=self.unit)
def __mul__(self, other: ScryptHashRate | int | float):
if isinstance(other, ScryptHashRate):
return ScryptHashRate(
rate=self.rate * other.into(self.unit).rate, unit=self.unit
)
return ScryptHashRate(rate=self.rate * other, unit=self.unit)
def into(self, other: ScryptUnit) -> ScryptHashRate:
return ScryptHashRate(
def into(self, other: ScryptUnit) -> Self:
return self.__class__(
rate=self.rate / (other.value / self.unit.value), unit=other
)

View File

@@ -1,5 +1,7 @@
from __future__ import annotations
from typing import Self
from pyasic.device.algorithm.hashrate.base import AlgoHashRateType
from pyasic.device.algorithm.hashrate.unit.sha256 import SHA256Unit
@@ -10,42 +12,7 @@ class SHA256HashRate(AlgoHashRateType):
rate: float
unit: SHA256Unit = HashUnit.SHA256.default
def __add__(self, other: SHA256HashRate | int | float) -> SHA256HashRate:
if isinstance(other, SHA256HashRate):
return SHA256HashRate(
rate=self.rate + other.into(self.unit).rate, unit=self.unit
)
return SHA256HashRate(rate=self.rate + other, unit=self.unit)
def __sub__(self, other: SHA256HashRate | int | float) -> SHA256HashRate:
if isinstance(other, SHA256HashRate):
return SHA256HashRate(
rate=self.rate - other.into(self.unit).rate, unit=self.unit
)
return SHA256HashRate(rate=self.rate - other, unit=self.unit)
def __truediv__(self, other: SHA256HashRate | int | float):
if isinstance(other, SHA256HashRate):
return SHA256HashRate(
rate=self.rate / other.into(self.unit).rate, unit=self.unit
)
return SHA256HashRate(rate=self.rate / other, unit=self.unit)
def __floordiv__(self, other: SHA256HashRate | int | float):
if isinstance(other, SHA256HashRate):
return SHA256HashRate(
rate=self.rate // other.into(self.unit).rate, unit=self.unit
)
return SHA256HashRate(rate=self.rate // other, unit=self.unit)
def __mul__(self, other: SHA256HashRate | int | float):
if isinstance(other, SHA256HashRate):
return SHA256HashRate(
rate=self.rate * other.into(self.unit).rate, unit=self.unit
)
return SHA256HashRate(rate=self.rate * other, unit=self.unit)
def into(self, other: SHA256Unit) -> SHA256HashRate:
return SHA256HashRate(
def into(self, other: SHA256Unit) -> Self:
return self.__class__(
rate=self.rate / (other.value / self.unit.value), unit=other
)

View File

@@ -1,5 +1,7 @@
from __future__ import annotations
from typing import Self
from pyasic.device.algorithm.hashrate.base import AlgoHashRateType
from pyasic.device.algorithm.hashrate.unit.x11 import X11Unit
@@ -10,40 +12,7 @@ class X11HashRate(AlgoHashRateType):
rate: float
unit: X11Unit = HashUnit.X11.default
def __add__(self, other: X11HashRate | int | float) -> X11HashRate:
if isinstance(other, X11HashRate):
return X11HashRate(
rate=self.rate + other.into(self.unit).rate, unit=self.unit
)
return X11HashRate(rate=self.rate + other, unit=self.unit)
def __sub__(self, other: X11HashRate | int | float) -> X11HashRate:
if isinstance(other, X11HashRate):
return X11HashRate(
rate=self.rate - other.into(self.unit).rate, unit=self.unit
)
return X11HashRate(rate=self.rate - other, unit=self.unit)
def __truediv__(self, other: X11HashRate | int | float):
if isinstance(other, X11HashRate):
return X11HashRate(
rate=self.rate / other.into(self.unit).rate, unit=self.unit
)
return X11HashRate(rate=self.rate / other, unit=self.unit)
def __floordiv__(self, other: X11HashRate | int | float):
if isinstance(other, X11HashRate):
return X11HashRate(
rate=self.rate // other.into(self.unit).rate, unit=self.unit
)
return X11HashRate(rate=self.rate // other, unit=self.unit)
def __mul__(self, other: X11HashRate | int | float):
if isinstance(other, X11HashRate):
return X11HashRate(
rate=self.rate * other.into(self.unit).rate, unit=self.unit
)
return X11HashRate(rate=self.rate * other, unit=self.unit)
def into(self, other: X11Unit) -> X11HashRate:
return X11HashRate(rate=self.rate / (other.value / self.unit.value), unit=other)
def into(self, other: X11Unit) -> Self:
return self.__class__(
rate=self.rate / (other.value / self.unit.value), unit=other
)

View File

@@ -6,12 +6,8 @@ from .hashrate.unit import KadenaUnit
# make this json serializable
class _KadenaAlgo(MinerAlgoType):
hashrate = KadenaHashRate
unit = KadenaUnit
class KadenaAlgo(MinerAlgoType):
hashrate: type[KadenaHashRate] = KadenaHashRate
unit: type[KadenaUnit] = KadenaUnit
def __repr__(self):
return "KadenaAlgo"
KadenaAlgo = _KadenaAlgo("Kadena")
name = "Kadena"

View File

@@ -6,12 +6,8 @@ from .hashrate.unit import KHeavyHashUnit
# make this json serializable
class _KHeavyHashAlgo(MinerAlgoType):
hashrate = KHeavyHashHashRate
unit = KHeavyHashUnit
class KHeavyHashAlgo(MinerAlgoType):
hashrate: type[KHeavyHashHashRate] = KHeavyHashHashRate
unit: type[KHeavyHashUnit] = KHeavyHashUnit
def __repr__(self):
return "KHeavyHashAlgo"
KHeavyHashAlgo = _KHeavyHashAlgo("KHeavyHash")
name = "KHeavyHash"

View File

@@ -5,13 +5,8 @@ from .hashrate import ScryptHashRate
from .hashrate.unit import ScryptUnit
# make this json serializable
class _ScryptAlgo(MinerAlgoType):
hashrate = ScryptHashRate
unit = ScryptUnit
class ScryptAlgo(MinerAlgoType):
hashrate: type[ScryptHashRate] = ScryptHashRate
unit: type[ScryptUnit] = ScryptUnit
def __repr__(self):
return "ScryptAlgo"
ScryptAlgo = _ScryptAlgo("Scrypt")
name = "Scrypt"

View File

@@ -6,12 +6,8 @@ from .hashrate.unit import SHA256Unit
# make this json serializable
class _SHA256Algo(MinerAlgoType):
hashrate = SHA256HashRate
unit = SHA256Unit
class SHA256Algo(MinerAlgoType):
hashrate: type[SHA256HashRate] = SHA256HashRate
unit: type[SHA256Unit] = SHA256Unit
def __repr__(self):
return "SHA256Algo"
SHA256Algo = _SHA256Algo("SHA256")
name = "SHA256"

View File

@@ -6,12 +6,8 @@ from .hashrate.unit import X11Unit
# make this json serializable
class _X11Algo(MinerAlgoType):
hashrate = X11HashRate
unit = X11Unit
class X11Algo(MinerAlgoType):
hashrate: type[X11HashRate] = X11HashRate
unit: type[X11Unit] = X11Unit
def __repr__(self):
return "X11Algo"
X11Algo = _X11Algo("X11")
name = "X11"

View File

@@ -46,7 +46,7 @@ class MinerProtocol(Protocol):
make: MinerMake = None
raw_model: MinerModelType = None
firmware: MinerFirmware = None
algo: MinerAlgoType = None
algo: type[MinerAlgoType] = None
expected_hashboards: int = None
expected_chips: int = None
@@ -496,7 +496,6 @@ class MinerProtocol(Protocol):
function = getattr(self, getattr(self.data_locations, data_name).cmd)
miner_data[data_name] = await function(**args_to_send)
except Exception as e:
raise e
raise APIError(
f"Failed to call {data_name} on {self} while getting data."
) from e