Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from utils import round_down_to_odd, moving_average, json_to_df, random_color, sav_filter
# DATA ACQUISITION GOES HERE
from dash.exceptions import PreventUpdate

from dash_datetimepicker import DashDatetimepicker
import query_service

external_stylesheets = [
Expand Down Expand Up @@ -117,13 +117,23 @@
],
className="header",
),
dbc.Row(
[
dbc.Col(html.Div(tz_dropdown), width='auto'),
dcc.Loading(dbc.Col(html.Div(user_dropdown), width='auto'), type='circle', color="#8a51ffff"),
dcc.Loading(dbc.Col(html.Div(miner_dropdown), width='auto'), type='circle', color="#8a51ffff"),
dbc.Col(html.Div(stats_type_dropdown), width='auto'),
],
dbc.Row([
dbc.Col([
dbc.Row(
dbc.Col(
html.Div(tz_dropdown),
)
),
dbc.Row(
dbc.Col(
html.Div(DashDatetimepicker(id='date_picker_range')),
)
)
], width='auto'),
dcc.Loading(dbc.Col(html.Div(user_dropdown), width='auto'), type='circle', color="#8a51ffff"),
dcc.Loading(dbc.Col(html.Div(miner_dropdown), width='auto'), type='circle', color="#8a51ffff"),
dbc.Col(html.Div(stats_type_dropdown), width='auto'),
],
justify='center'
),
dbc.Row(
Expand Down Expand Up @@ -174,11 +184,15 @@ def update_miners_dropdown(user_id):

@app.callback(
Output('miner_shares_data', 'data'),
[Input('miner_dropdown', 'value')])
def update_miner_shares(miner_id):
[Input('miner_dropdown', 'value'),
Input('date_picker_range', 'startDate'),
Input('date_picker_range', 'endDate')
])
def update_miner_shares(miner_id, start_date, end_date):

if not miner_id:
raise PreventUpdate
shares_frame = query_service.get_miner_shares(miner_id)
shares_frame = query_service.get_miner_shares(miner_id, start_date, end_date)
if shares_frame.empty:
return html.Div(
dbc.Alert("No share data to display for the selected timeframe", color='danger')
Expand All @@ -189,11 +203,15 @@ def update_miner_shares(miner_id):

@app.callback(
Output('miner_healths_data', 'data'),
[Input('miner_dropdown', 'value')])
def update_miner_healths(miner_id):
[Input('miner_dropdown', 'value'),
Input('date_picker_range', 'startDate'),
Input('date_picker_range', 'endDate')
])
def update_miner_healths(miner_id, start_date, end_date):

if not miner_id:
raise PreventUpdate
healths_frame = query_service.get_miner_healths(miner_id)
healths_frame = query_service.get_miner_healths(miner_id, start_date, end_date)
if healths_frame.empty:
return html.Div(
dbc.Alert("No health data to display for the selected timeframe", color='danger')
Expand Down Expand Up @@ -301,6 +319,7 @@ def update_combined_graph(healths_data, stat, timezone):
fig.update_yaxes(title=dict(text='Clock (Mhz)'))

fig.update_xaxes(title=dict(text='Time'))
fig.update_xaxes(rangeslider_visible=True)

return dcc.Graph(id=f'combined', figure=fig)

Expand Down
16 changes: 12 additions & 4 deletions query_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ def get_miners(user_id):
return None


def get_miner_shares(miner_id):
def get_miner_shares(miner_id, start_date, end_date):
try:
response = requests.get(API_URL + f"/miner/{miner_id}/share")
params = {
'start': start_date,
'end': end_date
}
response = requests.get(API_URL + f"/miner/{miner_id}/share", params=params)
if response.ok:
# create a dataframe from the share data
frame = pd.json_normalize(response.json())
Expand All @@ -62,9 +66,13 @@ def get_miner_shares(miner_id):
print(e)


def get_miner_healths(miner_id):
def get_miner_healths(miner_id, start_date, end_date):
try:
response = requests.get(API_URL + f"/miner/{miner_id}/health")
params = {
'start': start_date,
'end': end_date
}
response = requests.get(API_URL + f"/miner/{miner_id}/health", params=params)
if response.ok:
# create a dataframe from the share share_data
frame = pd.json_normalize(response.json())
Expand Down
14 changes: 13 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ Brotli==1.0.9
certifi==2020.12.5
chardet==4.0.0
click==7.1.2
colorama==0.4.4
colorhash==1.0.3
colorlog==5.0.1
colormap==1.0.3
cycler==0.10.0
dash==1.19.0
dash-bootstrap-components==0.12.2
dash-core-components==1.15.0
dash-datetimepicker==0.0.4
dash-html-components==1.1.2
dash-renderer==1.9.0
dash-table==4.11.2
easydev==0.11.1
Flask==1.1.2
Flask-Compress==1.9.0
Flask-SQLAlchemy==2.5.1
Expand All @@ -17,11 +24,17 @@ gunicorn==20.1.0
idna==2.10
itsdangerous==1.1.0
Jinja2==2.11.3
kiwisolver==1.3.1
MarkupSafe==1.1.1
matplotlib==3.4.2
numpy==1.20.2
pandas==1.2.3
pexpect==4.8.0
Pillow==8.2.0
plotly==4.14.3
ptyprocess==0.7.0
pyodbc==4.0.30
pyparsing==2.4.7
python-dateutil==2.8.1
python-dotenv==0.17.0
pytz==2021.1
Expand All @@ -33,4 +46,3 @@ SQLAlchemy==1.4.5
timeloop==1.0.2
urllib3==1.26.4
Werkzeug==1.0.1
matplotlib~=3.4.2