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

@ -368,23 +368,52 @@ def custom():
return render_template('custom.html', message='No')
@app.route('/result')
@app.route('/result', methods=['GET', 'POST'])
def result():
if login_required():
pass
else:
flash('使用投組功能請先登入。', 'warning')
return redirect(url_for('login'))
sql="""select id, date, name, username, annual_ret, vol, annual_sr, mdd\
from strategy order by id desc limit 50;"""
conn = psycopg2.connect(**SQL_CONFIG)
with conn:
with conn.cursor() as curs:
curs.execute(sql)
data= curs.fetchall()
conn.close()
return render_template('result.html', strategy_data=data)
if request.method=='GET':
conn = psycopg2.connect(**SQL_CONFIG)
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)
with conn:
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)
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()
conn.close()
return render_template('result.html', strategy_data=data)
@app.route('/result_view')
def result_view():
@ -428,10 +457,10 @@ def result_view():
data['bar'] = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)
return render_template('result_view.html', data=data)
# handle login failed
# @app.errorhandler(401)
# def page_not_found(e):
# return response('<p>Failed</p>')
@app.errorhandler(404)
def page_not_found(e):
# note that we set the 404 status explicitly
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>
<hr class="my-3 px-5">
<div class='d-flex justify-content-end'>
<div class="input-group mb-3">
<form method="POST">
<div class="input-group mb-1">
<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' %}
</select>
</div>
<div>
<button id="changeComp" type="button" class="btn btn-secondary"><i class="bi bi-arrow-right-square-fill"></i></button>
<div class="input-group mb-3">
<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>
</form>
</div>
<div class="card m-3">
<div card="card p-3 m-3">
<div class="card-header">
<div class="d-flex">
<div class="dropdown me-auto py-2">
<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>
Hello
</div>

@ -62,7 +62,7 @@ div.card{
</li>
<li class="list-group-item">
<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' %}
</select>
</li>

Loading…
Cancel
Save