feature: add generic hashrate type for doing sums

This commit is contained in:
Brett Rowan
2024-12-20 09:25:52 -07:00
parent d918d93f4a
commit 136ff6a688
2 changed files with 21 additions and 1 deletions

View File

@@ -5,7 +5,7 @@ from abc import ABC, abstractmethod
from pydantic import BaseModel
from typing_extensions import Self
from .unit.base import AlgoHashRateUnitType
from .unit.base import AlgoHashRateUnitType, GenericUnit
class AlgoHashRateType(BaseModel, ABC):
@@ -62,3 +62,10 @@ class AlgoHashRateType(BaseModel, ABC):
rate=self.rate * other.into(self.unit).rate, 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
)

View File

@@ -53,3 +53,16 @@ class AlgoHashRateUnitType(IntEnum):
def __repr__(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