mirror of
https://github.com/Retropex/custom-ocean.xyz-dashboard.git
synced 2025-05-12 19:20:45 +02:00
Update models.py
This commit is contained in:
parent
7fb94e1c00
commit
41e2da5829
63
models.py
63
models.py
@ -2,6 +2,7 @@
|
|||||||
Data models for the Bitcoin Mining Dashboard.
|
Data models for the Bitcoin Mining Dashboard.
|
||||||
"""
|
"""
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
import logging
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class OceanData:
|
class OceanData:
|
||||||
@ -31,7 +32,25 @@ class OceanData:
|
|||||||
total_last_share: str = "N/A"
|
total_last_share: str = "N/A"
|
||||||
last_block_earnings: str = None
|
last_block_earnings: str = None
|
||||||
|
|
||||||
def convert_to_ths(value: float, unit: str) -> float:
|
@dataclass
|
||||||
|
class WorkerData:
|
||||||
|
"""Data structure for individual worker information."""
|
||||||
|
name: str = None
|
||||||
|
status: str = "offline"
|
||||||
|
type: str = "ASIC" # ASIC or FPGA
|
||||||
|
model: str = "Unknown"
|
||||||
|
hashrate_60sec: float = 0
|
||||||
|
hashrate_60sec_unit: str = "TH/s"
|
||||||
|
hashrate_3hr: float = 0
|
||||||
|
hashrate_3hr_unit: str = "TH/s"
|
||||||
|
efficiency: float = 0
|
||||||
|
last_share: str = "N/A"
|
||||||
|
earnings: float = 0
|
||||||
|
acceptance_rate: float = 0
|
||||||
|
power_consumption: float = 0
|
||||||
|
temperature: float = 0
|
||||||
|
|
||||||
|
def convert_to_ths(value, unit):
|
||||||
"""
|
"""
|
||||||
Convert any hashrate unit to TH/s equivalent.
|
Convert any hashrate unit to TH/s equivalent.
|
||||||
|
|
||||||
@ -42,18 +61,30 @@ def convert_to_ths(value: float, unit: str) -> float:
|
|||||||
Returns:
|
Returns:
|
||||||
float: The hashrate value in TH/s
|
float: The hashrate value in TH/s
|
||||||
"""
|
"""
|
||||||
unit = unit.lower()
|
if value is None or value == 0:
|
||||||
if 'ph/s' in unit:
|
return 0
|
||||||
return value * 1000 # 1 PH/s = 1000 TH/s
|
|
||||||
elif 'eh/s' in unit:
|
try:
|
||||||
return value * 1000000 # 1 EH/s = 1,000,000 TH/s
|
unit = unit.lower() if unit else 'th/s'
|
||||||
elif 'gh/s' in unit:
|
|
||||||
return value / 1000 # 1 TH/s = 1000 GH/s
|
if 'ph/s' in unit:
|
||||||
elif 'mh/s' in unit:
|
return value * 1000 # 1 PH/s = 1000 TH/s
|
||||||
return value / 1000000 # 1 TH/s = 1,000,000 MH/s
|
elif 'eh/s' in unit:
|
||||||
elif 'th/s' in unit:
|
return value * 1000000 # 1 EH/s = 1,000,000 TH/s
|
||||||
return value
|
elif 'gh/s' in unit:
|
||||||
else:
|
return value / 1000 # 1 TH/s = 1000 GH/s
|
||||||
# Log unexpected unit
|
elif 'mh/s' in unit:
|
||||||
logging.warning(f"Unexpected hashrate unit: {unit}, defaulting to treating as TH/s")
|
return value / 1000000 # 1 TH/s = 1,000,000 MH/s
|
||||||
return value
|
elif 'kh/s' in unit:
|
||||||
|
return value / 1000000000 # 1 TH/s = 1,000,000,000 KH/s
|
||||||
|
elif 'h/s' in unit and not any(prefix in unit for prefix in ['th/s', 'ph/s', 'eh/s', 'gh/s', 'mh/s', 'kh/s']):
|
||||||
|
return value / 1000000000000 # 1 TH/s = 1,000,000,000,000 H/s
|
||||||
|
elif 'th/s' in unit:
|
||||||
|
return value
|
||||||
|
else:
|
||||||
|
# Log unexpected unit
|
||||||
|
logging.warning(f"Unexpected hashrate unit: {unit}, defaulting to treating as TH/s")
|
||||||
|
return value
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"Error in convert_to_ths: {e}")
|
||||||
|
return value # Return original value as fallback
|
||||||
|
Loading…
Reference in New Issue
Block a user