|
|
@ -6,9 +6,11 @@ import sys |
|
|
|
import logging |
|
|
|
import datetime |
|
|
|
import toml |
|
|
|
import os |
|
|
|
|
|
|
|
SECRET_KEY = '!Êrû÷FwÙxIER' |
|
|
|
CONFIG_FILE = 'config.toml' |
|
|
|
CONFIG_LOG_FILE = 'config_log.json' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -36,6 +38,21 @@ order.append({"id":"t", "value":"Třezalka"}) |
|
|
|
order.append({"id":"n", "value":"Neběžel"}) |
|
|
|
|
|
|
|
|
|
|
|
def log_state(config): |
|
|
|
with open(CONFIG_LOG_FILE) as f: |
|
|
|
log = json.load(f) |
|
|
|
if type(log) != list: |
|
|
|
raise ValueError('Config log file must contain list!') |
|
|
|
log.append(config) |
|
|
|
os.rename(CONFIG_LOG_FILE,CONFIG_LOG_FILE+'.old') |
|
|
|
with open(CONFIG_LOG_FILE,'w') as f: |
|
|
|
json.dump(log,f) |
|
|
|
|
|
|
|
|
|
|
|
log_state(config) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_form(form,config): |
|
|
|
errors = [] |
|
|
|
for t in config["teams"]: |
|
|
@ -48,11 +65,11 @@ def check_form(form,config): |
|
|
|
|
|
|
|
def team_points(per1,order1,per2,order2,config): |
|
|
|
# FIXME hardcoded interactions |
|
|
|
if (per1 == 'Kodein' and per2 == 'Paralen') or \ |
|
|
|
(per1 == 'Penicilin' and per2 == 'Strepsils'): |
|
|
|
# FIXME co třezalka? |
|
|
|
order1 = min(order1,order2) |
|
|
|
order2 = min(order1,order2) |
|
|
|
if (per1 not in ['n','t'] and per2 not in ['n','t']) and \ |
|
|
|
((per1 == 'Kodein' and per2 == 'Paralen') or \ |
|
|
|
(per1 == 'Penicilin' and per2 == 'Strepsils')): |
|
|
|
order1 = min(int(order1),int(order2)) |
|
|
|
order2 = order1 |
|
|
|
|
|
|
|
pts = 0 |
|
|
|
# Pokud neběžel první, neběžel ani druhý |
|
|
@ -81,17 +98,6 @@ def team_points(per1,order1,per2,order2,config): |
|
|
|
pts += config['base_pts']*config['order_coeff'][int(order2)]*org['coeff'] |
|
|
|
return pts |
|
|
|
|
|
|
|
def get_person(form,tid,pid,config): |
|
|
|
for org in config["orgs"]: |
|
|
|
if form["clovek{}_{}_{}".format(pid,tid,org["id"])] == "true": |
|
|
|
return org["id"] |
|
|
|
return None |
|
|
|
|
|
|
|
def get_team_by_id(aid,config): |
|
|
|
for t in config["teams"]: |
|
|
|
if t["id"] == aid: |
|
|
|
return t |
|
|
|
|
|
|
|
def get_org_by_id(aid,config): |
|
|
|
for o in config["orgs"]: |
|
|
|
if o["id"] == aid: |
|
|
@ -136,12 +142,14 @@ def form_page(): |
|
|
|
team["points"] = 100 |
|
|
|
team['emerg_remain'] -= 1 |
|
|
|
config["round"] += 1 |
|
|
|
log_state(config) |
|
|
|
return render_template("form.html", |
|
|
|
round = config["times"][config['round']], |
|
|
|
people = config["orgs"], |
|
|
|
order = order, |
|
|
|
teams = config["teams"], |
|
|
|
errors = [] |
|
|
|
errors = [], |
|
|
|
success = True |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
@ -150,3 +158,16 @@ def form_page(): |
|
|
|
def tablo(): |
|
|
|
return render_template("tablo.html",teams=config["teams"]) |
|
|
|
|
|
|
|
@app.route('/rollback',methods=['GET','POST']) |
|
|
|
def rollback(): |
|
|
|
global config |
|
|
|
with open(CONFIG_LOG_FILE) as f: |
|
|
|
log = json.load(f) |
|
|
|
if request.method == 'GET': |
|
|
|
return render_template("rollback.html",log=log) |
|
|
|
|
|
|
|
if request.method == 'POST': |
|
|
|
version = request.form['version'] |
|
|
|
config = log[int(version)] |
|
|
|
return render_template('rollback.html',log=log,success=True) |
|
|
|
|
|
|
|