master
SeanChenTaipei 2 years ago
parent f97fc13c0a
commit 18e401c4db
  1. 45
      main.py
  2. 14
      templates/404.html
  3. 37
      templates/result.html
  4. 2
      templates/strategy_tw.html

@ -368,20 +368,49 @@ def custom():
return render_template('custom.html', message='No') return render_template('custom.html', message='No')
@app.route('/result') @app.route('/result', methods=['GET', 'POST'])
def result(): def result():
if login_required(): if login_required():
pass pass
else: else:
flash('使用投組功能請先登入。', 'warning') flash('使用投組功能請先登入。', 'warning')
return redirect(url_for('login')) return redirect(url_for('login'))
if request.method=='GET':
sql="""select id, date, name, username, annual_ret, vol, annual_sr, mdd\ conn = psycopg2.connect(**SQL_CONFIG)
from strategy order by id desc limit 50;""" with conn:
with conn.cursor() as curs:
sql="select id, date, name, username, annual_ret, vol, annual_sr, mdd\
from strategy order by id desc limit 50"
curs.execute(sql)
data= curs.fetchall()
conn.close()
return render_template('result.html', strategy_data=data)
elif request.method=='POST':
role = request.form.get('role')
comp = request.form.get('competition')
if role in ['id', 'annual_ret', 'annual_sr', 'volatility']:
pass
else:
role='id'
if comp == 'none':
comp=None
print("result", type(role), type(comp))
conn = psycopg2.connect(**SQL_CONFIG) conn = psycopg2.connect(**SQL_CONFIG)
with conn: with conn:
with conn.cursor() as curs: with conn.cursor() as curs:
if comp is None:
if role is None:
sql="select id, date, name, username, annual_ret, vol, annual_sr, mdd\
from strategy order by id desc limit 50"
curs.execute(sql) curs.execute(sql)
else:
sql=f"select id, date, name, username, annual_ret, vol, annual_sr, mdd\
from strategy order by {role} desc limit 50"
curs.execute(sql)
else:
sql=f"select id, date, name, username, annual_ret, vol, annual_sr, mdd\
from strategy where competition=%s order by {role} desc limit 50;"
curs.execute(sql, (comp, ))
data= curs.fetchall() data= curs.fetchall()
conn.close() conn.close()
return render_template('result.html', strategy_data=data) return render_template('result.html', strategy_data=data)
@ -428,10 +457,10 @@ def result_view():
data['bar'] = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder) data['bar'] = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)
return render_template('result_view.html', data=data) return render_template('result_view.html', data=data)
# handle login failed @app.errorhandler(404)
# @app.errorhandler(401) def page_not_found(e):
# def page_not_found(e): # note that we set the 404 status explicitly
# return response('<p>Failed</p>') return render_template('404.html'), 404

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body style="background-image: linear-gradient(to bottom right, #5d9faa , #c4e0e5);">
<div class="container-fluid justify-content-center">
<h1 class="font-bold text-4xl">404 Error</h1>
</div>
</body>
</html>

@ -20,35 +20,36 @@
</div> </div>
<hr class="my-3 px-5"> <hr class="my-3 px-5">
<form method="POST">
<div class='d-flex justify-content-end'> <div class="input-group mb-1">
<div class="input-group mb-3">
<span class="input-group-text" id="in">選擇競賽</span> <span class="input-group-text" id="in">選擇競賽</span>
<select id="competition" class="form-select" size="1" aria-label="size 5 select example"> <select id="competition" class="form-select" size="1" name="competition">
{% include 'competitions.html' %} {% include 'competitions.html' %}
</select> </select>
</div> </div>
<div> <div class="input-group mb-3">
<button id="changeComp" type="button" class="btn btn-secondary"><i class="bi bi-arrow-right-square-fill"></i></button> <span class="input-group-text">排序方式</span>
<select id="rrr" class="form-select" size="1" name="role">
<option value="id">時間排序</option>
<option value="annual_ret">報酬率排序</option>
<option value="annual_sr">夏普率排序</option>
<option value="volatility">波動率排序</option>
</select>
</div>
<div class="d-flex flex-column-reverse">
<div class="ms-auto">
<button id="changeComp" type="submit" class="btn btn-secondary"><i class="bi bi-arrow-right-square-fill"></i></button>
</div> </div>
</div> </div>
</form>
</div> </div>
<div class="card m-3"> <div class="card m-3">
<div card="card p-3 m-3"> <div card="card p-3 m-3">
<div class="card-header"> <div class="card-header">
<div class="d-flex"> <div class="d-flex">
<div class="dropdown me-auto py-2"> Hello
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
排行方式
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">我的策略</a></li>
<li><a class="dropdown-item" href="#">時間排行</a></li>
<li><a class="dropdown-item" href="#">報酬排行</a></li>
<li><a class="dropdown-item" href="#">SR排行</a></li>
<li><a class="dropdown-item" href="#">波動率排行</a></li>
</ul>
</div>
</div> </div>

@ -62,7 +62,7 @@ div.card{
</li> </li>
<li class="list-group-item"> <li class="list-group-item">
<span class="ps-2">選擇所參加的課程或競賽。</span> <span class="ps-2">選擇所參加的課程或競賽。</span>
<select id="competition" class="form-select" size="1"> <select id="competition" class="form-select" size="1" name="competition">
{% include 'competitions.html' %} {% include 'competitions.html' %}
</select> </select>
</li> </li>

Loading…
Cancel
Save