|
|
@ -20,8 +20,8 @@ pd.options.plotting.backend = "plotly" |
|
|
|
|
|
|
|
|
|
|
|
# PARAMETERS |
|
|
|
# PARAMETERS |
|
|
|
CONFIGS = { |
|
|
|
CONFIGS = { |
|
|
|
"ENV": "development", |
|
|
|
# "ENV": "development", |
|
|
|
"DEBUG": True, |
|
|
|
# "DEBUG": True, |
|
|
|
"SECRET_KEY": os.urandom(30), # Set the secret key for session authentication |
|
|
|
"SECRET_KEY": os.urandom(30), # Set the secret key for session authentication |
|
|
|
"PERMANENT_SESSION_LIFETIME": timedelta(minutes=60) |
|
|
|
"PERMANENT_SESSION_LIFETIME": timedelta(minutes=60) |
|
|
|
} |
|
|
|
} |
|
|
@ -238,16 +238,17 @@ def submit_stock_list(): |
|
|
|
## Query DB |
|
|
|
## Query DB |
|
|
|
conn = psycopg2.connect(**SQL_CONFIG) |
|
|
|
conn = psycopg2.connect(**SQL_CONFIG) |
|
|
|
port = get_stock(conn, stock_list, session['tw']) |
|
|
|
port = get_stock(conn, stock_list, session['tw']) |
|
|
|
|
|
|
|
if len(port.index) > 750: |
|
|
|
|
|
|
|
port = port.iloc[-750:, :] |
|
|
|
conn.close() |
|
|
|
conn.close() |
|
|
|
|
|
|
|
|
|
|
|
fig = port.plot(title = 'Assets in portfolio', |
|
|
|
fig = port.plot(title='資產價格走勢', labels=dict(index="Date", value="Price", variable="Assets")) |
|
|
|
labels=dict(index="Date", value="Price", variable="Assets")) |
|
|
|
|
|
|
|
fig['layout'] = dict( |
|
|
|
fig['layout'] = dict( |
|
|
|
autosize=True, |
|
|
|
autosize=True, |
|
|
|
legend={'title': {'text': 'Assets'}, 'tracegroupgap': 0}, |
|
|
|
legend={'title': {'text': '資產價格走勢'}, 'tracegroupgap': 0}, |
|
|
|
title= {'text': 'Assets in portfolio'}, |
|
|
|
title= {'text': 'Assets in portfolio'}, |
|
|
|
xaxis= {'anchor': 'y', 'domain': [0.0, 1.0], 'title': {'text': 'Date'}}, |
|
|
|
xaxis= {'anchor': 'y', 'domain': [0.0, 1.0], 'title': {'text': '日期'}}, |
|
|
|
yaxis= {'anchor': 'x', 'domain': [0.0, 1.0], 'title': {'text': 'Price'}} |
|
|
|
yaxis= {'anchor': 'x', 'domain': [0.0, 0.75], 'title': {'text': '價格'}} |
|
|
|
) |
|
|
|
) |
|
|
|
fig.update_layout(legend=dict( |
|
|
|
fig.update_layout(legend=dict( |
|
|
|
yanchor="top", |
|
|
|
yanchor="top", |
|
|
@ -395,9 +396,9 @@ def result(): |
|
|
|
# return render_template('result_tw.html') |
|
|
|
# return render_template('result_tw.html') |
|
|
|
|
|
|
|
|
|
|
|
# handle login failed |
|
|
|
# handle login failed |
|
|
|
@app.errorhandler(401) |
|
|
|
# @app.errorhandler(401) |
|
|
|
def page_not_found(e): |
|
|
|
# def page_not_found(e): |
|
|
|
return Response('<p>Failed</p>') |
|
|
|
# return response('<p>Failed</p>') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|