Skip to content

Commit

Permalink
Added comments for better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinLinkl committed Jul 31, 2024
1 parent 25a9922 commit ca61d43
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 139 deletions.
51 changes: 20 additions & 31 deletions dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,43 @@
yahoo_tickers = load_yahoo_tk_data()

# Create a Dash web application instance


app = dash.Dash(__name__, external_stylesheets=[dbc.themes.SUPERHERO])

# Check if the database exists
if os.path.exists("data.db"):
print("Checking for new reports...")
# If the database exists, check for any new records
check_for_new_records()
else:
print("Database does not exist.")
print("Creating database.")
# If the database does not exist, fetch all reports to create the database
fetch_all_reports()


app.title = "Positions Explorer"

# Define the layout of the web application
app.layout = dbc.Container(
[
dbc.Row(
[
# Dropdown for selecting CFTC report
dbc.Col(
[
dbc.Label("Select CFTC report:"),
dcc.Dropdown(
id="report-dropdown",
options=get_reports_opts(),
value="report_legacy_futures_only",
options=get_reports_opts(), # Populate with options from get_reports_opts
value="report_legacy_futures_only", # Default value
placeholder="Select a report",
optionHeight=50,
className="dash-dropdown",
style={
"borderRadius": "15px",
},
style={"borderRadius": "15px"},
),
],
className="col-lg-6 col-12 my-2 text-center",
),
# Dropdown for selecting commodity subgroup
dbc.Col(
[
dbc.Label("Select a commodity subgroup:"),
Expand All @@ -63,11 +63,10 @@
],
className="col-lg-6 col-12 my-2 text-center",
),
# Dropdown for selecting market and exchange names
dbc.Col(
[
dbc.Label(
"Select a specific commodity market/commodity exchange name: "
),
dbc.Label("Select a specific commodity market/commodity exchange name: "),
dcc.Dropdown(
id="market-and-exchange-names-dropdown",
placeholder="Select a market/exchange",
Expand All @@ -82,6 +81,7 @@
),
dbc.Row(
[
# RangeSlider for selecting date range
dbc.Col(
[
dbc.Label("Select min max dates:"),
Expand All @@ -98,6 +98,7 @@
),
dbc.Row(
[
# Dropdown for selecting price chart
dbc.Col(
[
dbc.Label("Select a price chart: ", id="price-chart-label"),
Expand All @@ -115,6 +116,7 @@
],
className="col-lg-6 col-12 my-2 text-center",
),
# Dropdown for selecting position types
dbc.Col(
[
dbc.Label("Position types : "),
Expand All @@ -123,10 +125,7 @@
multi=True,
placeholder="Select a position type",
className="dash-bootstrap",
style={
"borderRadius": "15px",
# "text-align": "left"
},
style={"borderRadius": "15px"},
),
],
className="col-lg-6 col-12 my-2 text-center",
Expand All @@ -135,14 +134,12 @@
),
dbc.Row(
[
# Checklists and buttons for additional chart options
dbc.Col(
dbc.Checklist(
id="display-chart",
options=[
{
"label": "Display additional price",
"value": True,
},
{"label": "Display additional price", "value": True},
],
value=[True],
inline=True,
Expand All @@ -161,10 +158,7 @@
dbc.Checklist(
id="add-price-line",
options=[
{
"label": "Add price line",
"value": True,
},
{"label": "Add price line", "value": True},
],
value=False,
inline=True,
Expand All @@ -179,6 +173,7 @@
),
className="col-lg-2 col-6 my-2",
),
# Buttons to show or hide correlation card
dbc.Col(
dbc.Button(
"Show correlations",
Expand Down Expand Up @@ -213,6 +208,7 @@
),
className="col-lg-2 col-3 my-2 text-center",
),
# Checklist to show different options
dbc.Col(
dbc.Checklist(
id="show-option",
Expand All @@ -236,6 +232,7 @@
),
dbc.Row(
[
# Display for correlation card and graphs
dbc.Col(
dbc.Card(
[html.Div(id="correlation-card", style={"display": "none"})],
Expand Down Expand Up @@ -270,7 +267,6 @@
fluid=True,
)


# Callback to update commodities dropdown options based on the selected report
@app.callback(
Output("commodities-subgroup-dropdown", "options"),
Expand All @@ -281,7 +277,6 @@ def update_commodities_dropdown(report):
return []
return get_commodities_subgroup_opts(report)


# Callback to update market dropdown options based on selected commodity and report
@app.callback(
Output("market-and-exchange-names-dropdown", "options"),
Expand All @@ -296,7 +291,6 @@ def update_market_dropdown(selected_commodity_subgroup, selected_report):
else:
return [], []


# Callback to update various components including price chart label, slider, and more
@app.callback(
Output("price-chart-label", "children"),
Expand All @@ -323,7 +317,6 @@ def update_year_slider_and_price_dropdown_value(selected, report):
min_y, max_y, values, marks = get_slider_opts(selected, report)
return price_chart_label, ticker_dropdown, min_y, max_y, values, marks


# Callback to update position types based on the selected report
@app.callback(
Output("position-type", "options"),
Expand All @@ -340,7 +333,6 @@ def update_position_types(report):

return options, [default_value]


# Callback to toggle the visibility of the price graph based on user input
@app.callback(
Output("price-graph", "style"),
Expand All @@ -349,7 +341,6 @@ def update_position_types(report):
def toggle_price_graph_visibility(chart_together_value):
return {"display": "none"} if chart_together_value != [True] else {}


# Callback to toggle the correlation card's visibility
@app.callback(
Output("correlation-card", "style"),
Expand All @@ -370,7 +361,6 @@ def toggle_correlation_card(show_clicks, hide_clicks):
else:
return dash.no_update


# Callback to update various graphs based on user input
@app.callback(
Output("price-graph", "figure"),
Expand Down Expand Up @@ -401,7 +391,6 @@ def update_graphs_callback(
add_price,
)


# Main entry point of the application
if __name__ == "__main__":
app.run(debug=False, port=2077)
Loading

0 comments on commit ca61d43

Please sign in to comment.