From b226e09c6c2cc3c375dd5dea676e2bf009402613 Mon Sep 17 00:00:00 2001 From: liuyihui Date: Thu, 30 Dec 2021 16:37:58 +0800 Subject: [PATCH] add: personal info page --- app.py | 18 +++++++- lib/__init__.py | 5 ++- lib/db_init.py | 2 +- lib/elo.py | 2 +- lib/utils.py | 8 +++- templates/index.html | 18 ++++---- templates/info.html | 102 +++++++++++++++++++++++++++++++++++++++++++ templates/list.html | 2 +- 8 files changed, 140 insertions(+), 17 deletions(-) diff --git a/app.py b/app.py index 15eb026..4892bea 100644 --- a/app.py +++ b/app.py @@ -66,12 +66,28 @@ def rank_list_data(): for k in range(limit): kw["data"].append({ "rank": ind + k, - "name": res[k].name, + "name": "{:s}".format(res[k].id, res[k].name), "rate": "{:.2f}".format(res[k].rate) }) return kw +@app.route('/info', methods=["GET"]) +def info(): + id = request.args.get('id') + res = get_person(id, ses) + hist = list(map(float, res.hist.split(','))) + + kw = { + "name": res.name, + "work": res.work, + "rate": "{:.2f}".format(res.rate), + "hist": hist, + "count": res.count, + "picsrc": './static/pic/{:d}.jpeg'.format(res.id), + } + return render_template('info.html', **kw) + if __name__ == '__main__': app.run(debug=True, host='0.0.0.0', port=4002) diff --git a/lib/__init__.py b/lib/__init__.py index 559be1e..d124fda 100644 --- a/lib/__init__.py +++ b/lib/__init__.py @@ -9,13 +9,14 @@ # here put the import lib from .db_init import Person from .elo import set_result -from .utils import match, get_session, get_counts, get_rank +from .utils import match, get_session, get_counts, get_person, get_rank __all__ = [ "match", "Person", "set_result", "get_session", - "get_rank", "get_counts", + "get_person", + "get_rank" ] diff --git a/lib/db_init.py b/lib/db_init.py index 4cc4aab..d592156 100644 --- a/lib/db_init.py +++ b/lib/db_init.py @@ -20,7 +20,7 @@ class Person(Base): name = Column(String) work = Column(String, default='无') rate = Column(Float, default=1400.0) - hist = Column(String, default='') + hist = Column(String, default='1400') count = Column(Integer, default=0) def __repr__(self): diff --git a/lib/elo.py b/lib/elo.py index 0c073cf..4a3b45f 100644 --- a/lib/elo.py +++ b/lib/elo.py @@ -35,7 +35,7 @@ def __compute_K(P: Person) -> float: def __add_history(P: Person): P.count += 1 if P.count % 10 == 0: - P.hist += str('{:.2f}'.format(P.rate)) + P.hist += str(',{:.2f}'.format(P.rate)) def set_result(A: Person, B: Person, res: float) -> None: '''set result of this game diff --git a/lib/utils.py b/lib/utils.py index 2e2c44e..4b28705 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -32,7 +32,11 @@ def get_counts(ses: Session) -> int: res = ses.query(Person).count() return res -def get_person(ses: Session) -> Person: +def get_person(id: int, ses: Session) -> Person: + res = ses.query(Person).filter_by(id=id).first() + return res + +def get_random_person(ses: Session) -> Person: '''get random person Parameters @@ -104,6 +108,6 @@ def match(ses: Session) -> Person: ------- : two persons ''' - A = get_person(ses) + A = get_random_person(ses) B = get_enemy(A, ses) return A, B diff --git a/templates/index.html b/templates/index.html index 228f3f2..76edf51 100644 --- a/templates/index.html +++ b/templates/index.html @@ -19,7 +19,7 @@ max-width: 60%;max-height : 100%;position: absolute; top: 0; left: 0;right: 0;bottom: 0;margin: auto; } - a { + .layui-header a, .layui-footer a { color: #fff;text-decoration: none; } @@ -41,22 +41,22 @@

你对谁更有好感?

-
+
- Person 0 + Person 0
- 姓名

{{ p0name }}


- 代表作

{{ p0work }}


+ 姓名

{{ p0name }}


+ 代表作

{{ p0work }}


-
+
- Person 1 + Person 1
- 姓名

{{ p1name }}


- 代表作

{{ p1work }}


+ 姓名

{{ p1name }}


+ 代表作

{{ p1work }}


diff --git a/templates/info.html b/templates/info.html index e69de29..be0d88b 100644 --- a/templates/info.html +++ b/templates/info.html @@ -0,0 +1,102 @@ + + + + + + ELO Star + + + + + + + + + +
+
+

{{ name }}

+
+
+
+
+ {{ name }} +
+
+

代表作: {{ work }}


+

分 数: {{ rate }}


+

比较数: {{ count }}


+
+
+
+
+
+
+
+
+
+ + + + + \ No newline at end of file diff --git a/templates/list.html b/templates/list.html index 21d7de7..ec74907 100644 --- a/templates/list.html +++ b/templates/list.html @@ -15,7 +15,7 @@ text-align: center;background: #fff;height: 80vh; margin-top: 2vh;padding-top: 1vh;padding-bottom: 1vh;border-radius: 20px; } - a { + .layui-header a, .layui-footer a { color: #fff;text-decoration: none; }