94 lines
2.1 KiB
Python
94 lines
2.1 KiB
Python
#!/usr/bin/env python
|
|
# -*- encoding: utf-8 -*-
|
|
'''
|
|
@File : app.py
|
|
@Author: liuyihui
|
|
@Email : liuyihui02@gmail.com
|
|
'''
|
|
|
|
# here put the import lib
|
|
import os
|
|
from lib import *
|
|
from flask import Flask, request, redirect, render_template
|
|
|
|
P0, P1 = None, None
|
|
ses = get_session()
|
|
app = Flask(__name__, template_folder='./templates/', static_folder='./static/')
|
|
app.config['ROOT_FOLDER'] = os.path.abspath('.')
|
|
|
|
@app.route('/', methods=["GET"])
|
|
@app.route('/new', methods=["GET"])
|
|
def root():
|
|
global P0, P1
|
|
|
|
P0, P1 = match(ses)
|
|
return render_template(
|
|
'index.html',
|
|
p0src='./static/pic/{:d}.jpeg'.format(P0.id),
|
|
p0name=P0.name,
|
|
p0work=P0.work,
|
|
p1src='./static/pic/{:d}.jpeg'.format(P1.id),
|
|
p1name=P1.name,
|
|
p1work=P1.work
|
|
)
|
|
|
|
@app.route('/elo', methods=["GET"])
|
|
def elo_res():
|
|
global P0, P1
|
|
|
|
res = request.args.get('win')
|
|
set_result(P0, P1, int(res))
|
|
|
|
ses.commit()
|
|
P0, P1 = None, None
|
|
|
|
return redirect('/new')
|
|
|
|
@app.route('/list', methods=["GET"])
|
|
def rank_list():
|
|
return render_template('list.html')
|
|
|
|
@app.route('/listdata', methods=["GET"])
|
|
def rank_list_data():
|
|
page = int(request.args.get('page'))
|
|
limit = int(request.args.get('limit'))
|
|
|
|
ind = (page-1)*limit + 1
|
|
num = get_counts(ses)
|
|
res = get_rank(ses, ind, limit)
|
|
|
|
kw = {
|
|
"code": 0,
|
|
"msg": "",
|
|
"count": num,
|
|
"data": []
|
|
}
|
|
for k in range(limit):
|
|
kw["data"].append({
|
|
"rank": ind + k,
|
|
"name": "<a href=\"/info?id={:d}\">{:s}</a>".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)
|