From 982fe295d22032136d4d9fb882cad4d7d2d6fe4d Mon Sep 17 00:00:00 2001
From: DJObleezy
Date: Thu, 17 Apr 2025 15:00:11 -0700
Subject: [PATCH] Add pool fees percentage metric to dashboard
Updated `MiningDashboardService` to calculate and display
the `pool_fees_percentage` metric, reflecting earnings lost
to pool fees. Enhanced error handling for earnings processing.
Updated styles in `dashboard.css` for the new metric and
added corresponding HTML elements in `dashboard.html` to
ensure proper display and conditional rendering.
---
data_service.py | 22 ++++++++++++++++++----
static/css/dashboard.css | 7 ++++---
templates/dashboard.html | 11 +++++++++++
3 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/data_service.py b/data_service.py
index ac52e3f..400855f 100644
--- a/data_service.py
+++ b/data_service.py
@@ -128,7 +128,8 @@ class MiningDashboardService:
'last_block_time': ocean_data.last_block_time,
'total_last_share': ocean_data.total_last_share,
'blocks_found': ocean_data.blocks_found or "0",
- 'last_block_earnings': ocean_data.last_block_earnings
+ 'last_block_earnings': ocean_data.last_block_earnings,
+ 'pool_fees_percentage': ocean_data.pool_fees_percentage,
}
metrics['estimated_earnings_per_day_sats'] = int(round(estimated_earnings_per_day * self.sats_per_btc))
metrics['estimated_earnings_next_block_sats'] = int(round(estimated_earnings_next_block * self.sats_per_btc))
@@ -213,15 +214,28 @@ class MiningDashboardService:
latest_row = earnings_table.find('tr', class_='table-row')
if latest_row:
cells = latest_row.find_all('td', class_='table-cell')
- if len(cells) >= 3:
+ if len(cells) >= 4: # Ensure there are enough cells for earnings and pool fees
earnings_text = cells[2].get_text(strip=True)
+ pool_fees_text = cells[3].get_text(strip=True)
+
+ # Parse earnings and pool fees
earnings_value = earnings_text.replace('BTC', '').strip()
+ pool_fees_value = pool_fees_text.replace('BTC', '').strip()
+
try:
+ # Convert earnings to BTC and sats
btc_earnings = float(earnings_value)
- sats = int(round(btc_earnings * 100000000))
+ sats = int(round(btc_earnings * 100_000_000))
data.last_block_earnings = str(sats)
- except Exception:
+
+ # Calculate percentage lost to pool fees
+ btc_pool_fees = float(pool_fees_value)
+ percentage_lost = (btc_pool_fees / btc_earnings) * 100 if btc_earnings > 0 else 0
+ data.pool_fees_percentage = round(percentage_lost, 2)
+ except Exception as e:
+ logging.error(f"Error converting earnings or calculating percentage: {e}")
data.last_block_earnings = earnings_value
+ data.pool_fees_percentage = None
except Exception as e:
logging.error(f"Error parsing earnings data: {e}")
diff --git a/static/css/dashboard.css b/static/css/dashboard.css
index dacd22b..83a3bd9 100644
--- a/static/css/dashboard.css
+++ b/static/css/dashboard.css
@@ -151,9 +151,10 @@
#workers_hashing,
#last_share,
#blocks_found,
-#last_block_height {
- color: #ffffff;
- text-shadow: 0 0 6px rgba(255, 255, 255, 0.6);
+#last_block_height,
+#pool_fees_percentage {
+ color: #ffffff;
+ text-shadow: 0 0 6px rgba(255, 255, 255, 0.6);
}
/* Blue metrics (time data) */
diff --git a/templates/dashboard.html b/templates/dashboard.html
index 11f7412..5db26cb 100644
--- a/templates/dashboard.html
+++ b/templates/dashboard.html
@@ -39,6 +39,17 @@
Last Share:
{{ metrics.total_last_share or "N/A" }}
+
+ Pool Fees:
+
+ {% if metrics and metrics.pool_fees_percentage is defined %}
+ {{ metrics.pool_fees_percentage }}%
+ {% else %}
+ N/A
+ {% endif %}
+
+
+