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.
This commit is contained in:
DJObleezy 2025-04-17 15:00:11 -07:00
parent d98d496bd6
commit 982fe295d2
3 changed files with 33 additions and 7 deletions

View File

@ -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}")

View File

@ -151,7 +151,8 @@
#workers_hashing,
#last_share,
#blocks_found,
#last_block_height {
#last_block_height,
#pool_fees_percentage {
color: #ffffff;
text-shadow: 0 0 6px rgba(255, 255, 255, 0.6);
}

View File

@ -39,6 +39,17 @@
<strong>Last Share:</strong>
<span id="last_share" class="metric-value">{{ metrics.total_last_share or "N/A" }}</span>
</p>
<p>
<strong>Pool Fees:</strong>
<span id="pool_fees_percentage" class="metric-value">
{% if metrics and metrics.pool_fees_percentage is defined %}
{{ metrics.pool_fees_percentage }}%
{% else %}
N/A
{% endif %}
</span>
<span id="indicator_pool_fees_percentage"></span>
</p>
</div>
</div>
</div>