bug: fix some issues with adding hashrate types

This commit is contained in:
Brett Rowan
2024-12-20 09:21:06 -07:00
parent 92820a362d
commit 8046c532a6

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
from abc import ABC, abstractmethod
from pydantic import BaseModel
@@ -27,35 +29,35 @@ class AlgoHashRateType(BaseModel, ABC):
return round(self.rate, n)
def __add__(self, other: Self | int | float) -> Self:
if isinstance(other, self.__class__):
if isinstance(other, AlgoHashRateType):
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__):
if isinstance(other, AlgoHashRateType):
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__):
if isinstance(other, AlgoHashRateType):
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__):
if isinstance(other, AlgoHashRateType):
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__):
if isinstance(other, AlgoHashRateType):
return self.__class__(
rate=self.rate * other.into(self.unit).rate, unit=self.unit
)