From 18e401c4db3cc205517805dd74dde756d8c1133d Mon Sep 17 00:00:00 2001 From: SeanChenTaipei Date: Sun, 12 Mar 2023 01:15:06 +0800 Subject: [PATCH] cool --- main.py | 59 ++++++++++++++++++++++++++++---------- templates/404.html | 14 +++++++++ templates/result.html | 39 +++++++++++++------------ templates/strategy_tw.html | 2 +- 4 files changed, 79 insertions(+), 35 deletions(-) create mode 100644 templates/404.html diff --git a/main.py b/main.py index 6509069..b435a53 100644 --- a/main.py +++ b/main.py @@ -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('

Failed

') +@app.errorhandler(404) +def page_not_found(e): + # note that we set the 404 status explicitly + return render_template('404.html'), 404 diff --git a/templates/404.html b/templates/404.html new file mode 100644 index 0000000..17151ef --- /dev/null +++ b/templates/404.html @@ -0,0 +1,14 @@ + + + + + + + Document + + +
+

404 Error

+
+ + \ No newline at end of file diff --git a/templates/result.html b/templates/result.html index 5ac27db..887330f 100644 --- a/templates/result.html +++ b/templates/result.html @@ -20,35 +20,36 @@
- -
-
+
+
選擇競賽 - {% include 'competitions.html' %}
-
- +
+ 排序方式 + +
+
+
+ +
-
+
+ +
- + Hello
diff --git a/templates/strategy_tw.html b/templates/strategy_tw.html index 3032e53..c6a0774 100644 --- a/templates/strategy_tw.html +++ b/templates/strategy_tw.html @@ -62,7 +62,7 @@ div.card{
  • 選擇所參加的課程或競賽。 - {% include 'competitions.html' %}