diff --git a/main.py b/main.py index aafa1b5..d81c2d0 100644 --- a/main.py +++ b/main.py @@ -140,7 +140,7 @@ def login_post(): flash('使用者代號不對或密碼不對,請再試一次。', 'danger') return render_template('login.html') elif check_password_hash(data[2], password): - session['username'] = username + session['username'] = username.split('@')[0] session['user_id'] = data[0] session['privilege'] = data[-1] session['update_freq'] = 100 @@ -388,32 +388,37 @@ def result(): elif request.method=='POST': role = request.form.get('role') comp = request.form.get('competition') + if role == "my": + conn = psycopg2.connect(**SQL_CONFIG) + with conn: + with conn.cursor() as curs: + sql=f"select id, date, name, username, annual_ret, vol, annual_sr, mdd\ + from strategy where username=%s order by id desc limit 50;" + curs.execute(sql, (session['username'], )) + data= curs.fetchall() + conn.close() + return render_template('result.html', strategy_data=data) if role in ['id', 'annual_ret', 'annual_sr', 'vol']: pass else: role='id' + if role == 'vol': + order= 'asc' + else: + order= 'desc' if comp == 'none': comp=None - print("result", type(role), type(comp)) + print("result", role) 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) - elif role=='vol': - sql=f"select id, date, name, username, annual_ret, vol, annual_sr, mdd\ - from strategy order by {role} asc 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) + sql=f"select id, date, name, username, annual_ret, vol, annual_sr, mdd\ + from strategy order by {role} {order} 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;" + from strategy where competition=%s order by {role} {order} limit 50;" curs.execute(sql, (comp, )) data= curs.fetchall() conn.close() diff --git a/templates/result.html b/templates/result.html index 4b80b83..c64e6a4 100644 --- a/templates/result.html +++ b/templates/result.html @@ -2,14 +2,16 @@ {% set active_page = 'result' %} {% block style %} - +.card-header { + color: #000093; +} {% endblock style %} {% block title %}Result Page{% endblock%} {% block content %}
-