Skip to content

Commit

Permalink
Merge 06e3c95 into 9b4d93d
Browse files Browse the repository at this point in the history
  • Loading branch information
marctheshark3 authored Apr 8, 2024
2 parents 9b4d93d + 06e3c95 commit 33984b0
Show file tree
Hide file tree
Showing 37 changed files with 2,627 additions and 4,150 deletions.
43 changes: 4 additions & 39 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def display_page(pathname):
mining_address = unquote(pathname.lstrip('/'))
# Use the mining address to generate the page content
# This is where you might call a function to get the layout based on the mining address
return mining_page.get_layout()
return mining_page.get_layout(reader)
else:
return front_page.get_layout()
return front_page.get_layout(reader)

# Define callback to update page content or handle business logic
@app.callback(
Expand All @@ -52,43 +52,8 @@ def navigate_to_main(n_clicks, value):
# If there's no input or the button hasn't been clicked, stay on the current page
return '/'

# @app.callback(
# Output('metrics-stats', 'children'),
# [Input('interval-component', 'n_intervals')],
# [State('url', 'pathname')]
# )
# def update_crypto_prices(n, pathname):
# if pathname:
# wallet = unquote(pathname.split('/')[1])
# # print(wallet)
# if wallet or n > 0:
# print(n, wallet, 'yoyoyoy')
# metric_style = {
# 'padding': '20px',
# 'fontSize': '20px',
# 'margin': '10px',
# 'border': '1px solid #555', # Adjusted for dark mode
# 'borderRadius': '5px',
# 'background': '#333', # Dark background
# 'color': '#fff', # Light text color
# # 'boxShadow': '0 2px 4px rgba(255,255,255,.1)', # Subtle white shadow for depth
# # 'minWidth': '150px', # Ensure blocks don't become too narrow
# 'textAlign': 'center' # Center text horizontally
# }
# btc_price, erg_price, your_total_hash, pool_hash, net_hash, avg_block_effort, net_diff = reader.get_main_page_metrics(wallet, True)
# layout = html.Div([
# html.Div(f"BTC: ${btc_price}", style=metric_style),
# html.Div(f"ERG: ${erg_price}", style=metric_style),
# html.Div(f"Total Hashrate: {your_total_hash} Mh/s", style=metric_style),
# html.Div(f"Pool Hashrate: {pool_hash} Gh/s", style=metric_style),
# html.Div(f"Network Hashrate: {net_hash} Th/s", style=metric_style),
# html.Div(f"Average Block Effort: {avg_block_effort}", style=metric_style),
# html.Div(f"Network Difficulty: {net_diff} P", style=metric_style),
# ], style={'display': 'flex', 'flexDirection': 'row', 'justifyContent': 'center'})
# return layout

setup_front_page_callbacks(app)
setup_mining_page_callbacks(app)
setup_front_page_callbacks(app, reader)
setup_mining_page_callbacks(app, reader)

if __name__ == '__main__':
app.run_server(debug=True, host='0.0.0.0', port=8050)
75 changes: 75 additions & 0 deletions app1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# app.py
from dash import Dash, html, dcc, Input, Output, State

from layouts import front_page_1, mining_page_1
from urllib.parse import quote, unquote
import dash_bootstrap_components as dbc
from utils.api_reader import SigmaWalletReader, PriceReader
from layouts.front_page_1 import setup_front_page_callbacks
# from layouts.main_page import setup_main_page_callbacks
from layouts.mining_page_1 import setup_mining_page_callbacks
from flask_login import LoginManager, UserMixin, login_user
from flask import Flask, request, session, redirect, url_for
from flask_session import Session

# Initialize Flask app
server = Flask(__name__)
server.config['SECRET_KEY'] = 'your_super_secret_key' # Change this to a random secret key
server.config['SESSION_TYPE'] = 'filesystem' # Example: filesystem-based session storage
Session(server)

# Initialize Flask-Login
login_manager = LoginManager()
login_manager.init_app(server)

# Mock user database (you will replace this with your actual user authentication mechanism)
class User(UserMixin):
pass

@login_manager.user_loader
def load_user(user_id):
# Load user from database or other source
user = User()
user.id = user_id

reader = SigmaWalletReader('../conf')
reader.update_data()
app = Dash(__name__, url_base_pathname='/', server=server, external_stylesheets=[dbc.themes.BOOTSTRAP], suppress_callback_exceptions=True)
server = app.server
app.layout = html.Div([
dcc.Location(id='url', refresh=False),
html.Div(id='page-content')
])

@app.callback(Output('page-content', 'children'),
[Input('url', 'pathname')])
def display_page(pathname):
if pathname and pathname != "/":
# Decode the mining address from the URL
mining_address = unquote(pathname.lstrip('/'))
# Use the mining address to generate the page content
# This is where you might call a function to get the layout based on the mining address
return mining_page_1.get_layout(reader)
else:
return front_page_1.get_layout(reader)

# Define callback to update page content or handle business logic
@app.callback(
Output('url', 'pathname'),
Input('start-mining-button', 'n_clicks'),
State('mining-address-input', 'value')
)
def navigate_to_main(n_clicks, value):
if n_clicks and value:
# Encode the user input to ensure it's safe for URL use
safe_value = quote(value)
# Redirect user to a dynamic path based on their input
return f'/{safe_value}'
# If there's no input or the button hasn't been clicked, stay on the current page
return '/'

setup_front_page_callbacks(app, reader)
setup_mining_page_callbacks(app, reader)

if __name__ == '__main__':
app.run_server(debug=True, host='0.0.0.0', port=8050)
1 change: 0 additions & 1 deletion assets/.~lock.emmisions.ods#

This file was deleted.

11 changes: 11 additions & 0 deletions assets/emissions.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Date,Coins/Block,% from today,Block Left,Days,New Block,Daily Emissions,$ERG to maintain
Today,30,,17470,24,4/7/2024,"21,600",@ $2.29
4/7/2024,27,10%,64800,90,7/6/2024,"19,440",$2.54
7/6/2024,24,20%,64800,90,10/4/2024,"17,280",$2.86
10/4/2024,21,30%,64800,90,1/2/2025,"15,120",$3.27
1/2/2025,18,40%,64800,90,4/2/2025,"12,960",$3.82
4/2/2025,15,50%,64800,90,7/1/2025,"10,800",$4.58
7/1/2025,12,60%,64800,90,9/29/2025,"8,640",$5.73
9/29/2025,9,70%,64800,90,12/28/2025,"6,480",$7.63
12/28/2025,6,80%,64800,90,3/28/2026,"4,320",$11.45
3/28/2026,3,90%,64800,,,"2,160",$22.90
Binary file removed assets/emmisions.ods
Binary file not shown.
Binary file added layouts/__pycache__/front_page.cpython-312.pyc
Binary file not shown.
Binary file modified layouts/__pycache__/front_page.cpython-36.pyc
Binary file not shown.
Binary file modified layouts/__pycache__/front_page.cpython-39.pyc
Binary file not shown.
Binary file not shown.
Binary file added layouts/__pycache__/front_page_1.cpython-39.pyc
Binary file not shown.
Binary file added layouts/__pycache__/main_page.cpython-312.pyc
Binary file not shown.
Binary file added layouts/__pycache__/main_page.cpython-36.pyc
Binary file not shown.
Binary file modified layouts/__pycache__/main_page.cpython-39.pyc
Binary file not shown.
Binary file added layouts/__pycache__/mining_page.cpython-312.pyc
Binary file not shown.
Binary file modified layouts/__pycache__/mining_page.cpython-39.pyc
Binary file not shown.
Binary file added layouts/__pycache__/mining_page_1.cpython-312.pyc
Binary file not shown.
Binary file added layouts/__pycache__/mining_page_1.cpython-39.pyc
Binary file not shown.
23 changes: 12 additions & 11 deletions layouts/front_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from dash import html
price_reader = PriceReader()
sigma_reader = SigmaWalletReader(config_path="../conf")
# sigma_reader = SigmaWalletReader(config_path="../conf")

debug = False

Expand Down Expand Up @@ -82,7 +82,7 @@ def create_row_card(image, h2_text, p_text):
html.H2(h2_text, style={'color': large_text_color}),
html.P(p_text)]), style={'marginRight': 'auto', 'marginLeft': 'auto'}, width=4,)

def setup_front_page_callbacks(app):
def setup_front_page_callbacks(app, reader):

@app.callback([Output('metric-1', 'children'),
Output('metric-2', 'children'),],
Expand All @@ -91,7 +91,7 @@ def setup_front_page_callbacks(app):
def update_metrics(n):
print('UPDATING FRONT PAGE')

data = sigma_reader.get_front_page_data() #
data = reader.get_front_page_data() #
_, ergo = price_reader.get(debug=debug)
# payout_schema = 'Schema: {}'.format(data['payoutScheme'])
n_miners = '{}'.format(data['connectedMiners'])
Expand Down Expand Up @@ -133,7 +133,7 @@ def update_metrics(n):
def update_plots(n, value):

if value == 'effort':
block_df, _, _ = sigma_reader.get_block_stats('') #
block_df = reader.get_block_stats('') #
title = 'EFFORT AND DIFFICULTY'

block_df = block_df.sort_values('Time Found')
Expand Down Expand Up @@ -167,8 +167,9 @@ def update_plots(n, value):
yaxis2=dict(title='Network Difficulty', color='#FFFFFF', overlaying='y', side='right'),
)
return effort_response_chart, title

title = 'HASHRATE OVER TIME'
total_hashrate_df = sigma_reader.get_total_hash()
total_hashrate_df = reader.get_total_hash()
total_hashrate_df = total_hashrate_df.sort_values(['Date'])

total_hashrate_plot={'data': [go.Scatter(x=total_hashrate_df['Date'], y=total_hashrate_df['Hashrate'],
Expand All @@ -190,7 +191,7 @@ def update_plots(n, value):
Input('dataset-dropdown', 'value')])

def update_content(n, selected_data):
block_df, _, _ = sigma_reader.get_block_stats('')
block_df= reader.get_block_stats('')
latest = max(block_df['Time Found'])

if selected_data == 'blocks':
Expand All @@ -202,8 +203,8 @@ def update_content(n, selected_data):
df = block_df
title = 'Blocks Data'
elif selected_data == 'miners':
data = sigma_reader.get_front_page_data() #
top_miner_df = sigma_reader.get_all_miner_data('')
data = reader.get_front_page_data() #
top_miner_df = reader.get_all_miner_data('')
ls = []
print(latest)
for miner in top_miner_df.miner.unique():
Expand All @@ -221,8 +222,8 @@ def update_content(n, selected_data):


temp_hash = round(temp.hashrate.sum(), 3)
effort = sigma_reader.calculate_mining_effort(data['networkDifficulty'], data['networkHashrate'], temp_hash, temp_latest)
ttf = sigma_reader.calculate_time_to_find_block(data['networkDifficulty'], data['networkHashrate'], temp_hash, temp_latest)
effort = reader.calculate_mining_effort(data['networkDifficulty'], data['networkHashrate'], temp_hash, temp_latest)
ttf = reader.calculate_time_to_find_block(data['networkDifficulty'], data['networkHashrate'], temp_hash, temp_latest)
ls.append([miner, temp_hash, round(temp.sharesPerSecond.sum(), 2), effort, ttf])

df = DataFrame(ls, columns=['Miner', 'Hashrate', 'SharesPerSecond', 'Effort', 'Time To Find'])
Expand All @@ -239,7 +240,7 @@ def update_content(n, selected_data):
return table_data, title


def get_layout():
def get_layout(reader):
return html.Div([dbc.Container(fluid=True, style={'backgroundColor': background_color, 'padding': '10px', 'justifyContent': 'center', 'fontFamily': 'sans-serif', 'color': '#FFFFFF', 'maxWidth': '960px' },
children=[
dcc.Interval(id='fp-int-1', interval=60*1000, n_intervals=0),
Expand Down
Loading

0 comments on commit 33984b0

Please sign in to comment.