feature: add generic hashrate type for doing sums
This commit is contained in:
@@ -5,7 +5,7 @@ from abc import ABC, abstractmethod
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from typing_extensions import Self
|
from typing_extensions import Self
|
||||||
|
|
||||||
from .unit.base import AlgoHashRateUnitType
|
from .unit.base import AlgoHashRateUnitType, GenericUnit
|
||||||
|
|
||||||
|
|
||||||
class AlgoHashRateType(BaseModel, ABC):
|
class AlgoHashRateType(BaseModel, ABC):
|
||||||
@@ -62,3 +62,10 @@ class AlgoHashRateType(BaseModel, ABC):
|
|||||||
rate=self.rate * other.into(self.unit).rate, unit=self.unit
|
rate=self.rate * other.into(self.unit).rate, unit=self.unit
|
||||||
)
|
)
|
||||||
return self.__class__(rate=self.rate * other, unit=self.unit)
|
return self.__class__(rate=self.rate * other, unit=self.unit)
|
||||||
|
|
||||||
|
|
||||||
|
class GenericHashrate(AlgoHashRateType):
|
||||||
|
def into(self, other: GenericUnit):
|
||||||
|
return self.__class__(
|
||||||
|
rate=self.rate / (other.value / self.unit.value), unit=other
|
||||||
|
)
|
||||||
|
|||||||
@@ -53,3 +53,16 @@ class AlgoHashRateUnitType(IntEnum):
|
|||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return str(self)
|
return str(self)
|
||||||
|
|
||||||
|
|
||||||
|
class GenericUnit(AlgoHashRateUnitType):
|
||||||
|
H = 1
|
||||||
|
KH = int(H) * 1000
|
||||||
|
MH = int(KH) * 1000
|
||||||
|
GH = int(MH) * 1000
|
||||||
|
TH = int(GH) * 1000
|
||||||
|
PH = int(TH) * 1000
|
||||||
|
EH = int(PH) * 1000
|
||||||
|
ZH = int(EH) * 1000
|
||||||
|
|
||||||
|
default = H
|
||||||
|
|||||||
Reference in New Issue
Block a user