2021-12-29 16:53:57 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- encoding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
@File : app.py
|
|
|
|
@Author: liuyihui
|
|
|
|
@Email : liuyihui02@gmail.com
|
|
|
|
'''
|
|
|
|
|
|
|
|
# here put the import lib
|
2021-12-29 20:57:23 +08:00
|
|
|
import os
|
2021-12-30 13:24:57 +08:00
|
|
|
from lib import *
|
2021-12-30 00:50:09 +08:00
|
|
|
from flask import Flask, request, redirect, render_template
|
2021-12-29 16:53:57 +08:00
|
|
|
|
2021-12-30 13:24:57 +08:00
|
|
|
P0, P1 = None, None
|
|
|
|
ses = get_session()
|
2021-12-30 00:50:09 +08:00
|
|
|
app = Flask(__name__, template_folder='./templates/', static_folder='./static/')
|
2021-12-29 20:57:23 +08:00
|
|
|
app.config['ROOT_FOLDER'] = os.path.abspath('.')
|
2021-12-29 16:53:57 +08:00
|
|
|
|
2021-12-30 00:50:09 +08:00
|
|
|
@app.route('/', methods=["GET"])
|
|
|
|
@app.route('/new', methods=["GET"])
|
2021-12-29 16:53:57 +08:00
|
|
|
def root():
|
2021-12-30 00:50:09 +08:00
|
|
|
global P0, P1
|
2021-12-30 13:24:57 +08:00
|
|
|
|
|
|
|
P0, P1 = match(ses)
|
2021-12-30 00:50:09 +08:00
|
|
|
return render_template(
|
|
|
|
'index.html',
|
|
|
|
p0src='./static/pic/{:d}.jpeg'.format(P0.id),
|
|
|
|
p0name=P0.name,
|
2021-12-30 13:24:57 +08:00
|
|
|
p0work=P0.work,
|
2021-12-30 00:50:09 +08:00
|
|
|
p1src='./static/pic/{:d}.jpeg'.format(P1.id),
|
|
|
|
p1name=P1.name,
|
2021-12-30 13:24:57 +08:00
|
|
|
p1work=P1.work
|
2021-12-30 00:50:09 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
@app.route('/elo', methods=["GET"])
|
|
|
|
def elo_res():
|
2021-12-30 13:24:57 +08:00
|
|
|
global P0, P1
|
|
|
|
|
2021-12-30 00:50:09 +08:00
|
|
|
res = request.args.get('win')
|
2021-12-30 13:24:57 +08:00
|
|
|
set_result(P0, P1, int(res))
|
|
|
|
|
2021-12-30 00:50:09 +08:00
|
|
|
ses.commit()
|
2021-12-30 13:24:57 +08:00
|
|
|
P0, P1 = None, None
|
|
|
|
|
2021-12-30 00:50:09 +08:00
|
|
|
return redirect('/new')
|
2021-12-29 16:53:57 +08:00
|
|
|
|
2021-12-30 13:24:57 +08:00
|
|
|
@app.route('/list', methods=["GET"])
|
|
|
|
def rank_list():
|
|
|
|
b = int(request.args.get('b'))
|
|
|
|
len = int(request.args.get('len')) if request.args.get('len') else 10
|
|
|
|
|
|
|
|
res = get_rank(ses, b, len)
|
|
|
|
kw = dict()
|
|
|
|
for k in range(len):
|
|
|
|
kw["P{:d}rank".format(k)] = b + k
|
|
|
|
kw["P{:d}name".format(k)] = res[k].name
|
|
|
|
kw["P{:d}rate".format(k)] = '{:.2f}'.format(res[k].rate)
|
|
|
|
|
|
|
|
return render_template('list.html', **kw)
|
|
|
|
|
2021-12-29 16:53:57 +08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app.run(debug=True, host='0.0.0.0', port=4002)
|