Fix efficiency_fract property to correctly return computed value. See #334.
This commit is contained in:
@@ -70,6 +70,7 @@ class MinerData(BaseModel):
|
|||||||
errors: A list of errors on the miner.
|
errors: A list of errors on the miner.
|
||||||
fault_light: Whether the fault light is on as a boolean.
|
fault_light: Whether the fault light is on as a boolean.
|
||||||
efficiency: Efficiency of the miner in J/TH (Watts per TH/s). Calculated automatically.
|
efficiency: Efficiency of the miner in J/TH (Watts per TH/s). Calculated automatically.
|
||||||
|
efficiency_fract: Same as efficiency, but is not rounded to integer. Calculated automatically.
|
||||||
is_mining: Whether the miner is mining.
|
is_mining: Whether the miner is mining.
|
||||||
pools: A list of PoolMetrics instances, each representing metrics for a pool.
|
pools: A list of PoolMetrics instances, each representing metrics for a pool.
|
||||||
"""
|
"""
|
||||||
@@ -293,7 +294,7 @@ class MinerData(BaseModel):
|
|||||||
@computed_field # type: ignore[misc]
|
@computed_field # type: ignore[misc]
|
||||||
@property
|
@property
|
||||||
def efficiency_fract(self) -> float | None:
|
def efficiency_fract(self) -> float | None:
|
||||||
self._efficiency(2)
|
return self._efficiency(2)
|
||||||
|
|
||||||
def _efficiency(self, ndigits: int) -> float | None:
|
def _efficiency(self, ndigits: int) -> float | None:
|
||||||
if self.hashrate is None or self.wattage is None:
|
if self.hashrate is None or self.wattage is None:
|
||||||
@@ -301,7 +302,7 @@ class MinerData(BaseModel):
|
|||||||
try:
|
try:
|
||||||
return round(self.wattage / float(self.hashrate), ndigits)
|
return round(self.wattage / float(self.hashrate), ndigits)
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError:
|
||||||
return 0
|
return 0.0
|
||||||
|
|
||||||
@computed_field # type: ignore[misc]
|
@computed_field # type: ignore[misc]
|
||||||
@property
|
@property
|
||||||
|
|||||||
Reference in New Issue
Block a user