diff --git a/.gitignore b/.gitignore index e61bca2..736a205 100644 --- a/.gitignore +++ b/.gitignore @@ -114,3 +114,5 @@ dmypy.json # Pyre type checker .pyre/ +# Vim swap file +.*.sw[mnop] diff --git a/app.py b/app.py new file mode 100644 index 0000000..ce595a5 --- /dev/null +++ b/app.py @@ -0,0 +1,145 @@ +#!/usr/bin/python3 + +from flask import Flask,render_template,session,request,redirect,abort +import json +import sys +import logging +import datetime +import toml + +SECRET_KEY = '!Êrû÷FwÙxIER' +CONFIG_FILE = 'config.toml' + + + +app = Flask(__name__) +app.secret_key = SECRET_KEY +app.logger.setLevel(logging.DEBUG) +SERVER_NAME = '127.0.0.1' + +config = {} +with open(CONFIG_FILE) as f: + config = toml.load(f) +print(config) +if not config["orgs"]: + app.logger.error("Orgs part of config file missing") + sys.exit(1) +if not config["teams"]: + app.logger.error("Teams part of config file missing") + sys.exit(1) +if not config["times"]: + app.logger.error("Times part of config file missing") + sys.exit(1) + +order = [{"id":i,"value":str(i+1)+"."} for i in range(len(config["teams"]))] +order.append({"id":"t", "value":"Třezalka"}) +order.append({"id":"n", "value":"Neběžel"}) + +around = 0 + +def check_form(form,config): + errors = [] + for t in config["teams"]: + if "poradi1_"+str(t['id']) not in form: + errors.append("Tým "+t['name']+" nemá vyplněné pořadí u 1. člověka") + if "poradi2_"+str(t['id']) not in form: + errors.append("Tým "+t['name']+" nemá vyplněné pořadí u 2. člověka") + + return errors + +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) + + pts = 0 + # Pokud neběžel první, neběžel ani druhý + if order1 == 'n': + return config['no_pts'] + + # První měl třezalku + if order1 == 't': + pts += config['base_pts'] + + # První běžel normálně + else: + org = get_org_by_id(per1,config) + pts +=config['base_pts']*config['order_coeff'][int(order1)]*org['coeff'] + # Druhý neběžěl, body za oba jsou body prvního, můžeme vrátit + if order2 == 'n': + return pts + + # Druhý měl třezalku + if order2 == 't': + pts += config['base_pts'] + + # Druhý běžel normálně + else: + org = get_org_by_id(per2,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: + return o + +@app.route('/') +def hello_world(): + return 'Hello, World!' + +@app.route('/form',methods=['GET','POST']) +def form_page(): + if request.method == 'GET': + return render_template("form.html", + round = config["times"][around], + people = config["orgs"], + order = order, + teams = config["teams"], + ) + + if request.method == 'POST': + print(request.form) + errors = check_form(request.form,config) + if errors: + return render_template("form.html", + round = config["times"][around], + people = config["orgs"], + order = order, + teams = config["teams"], + errors = errors + ) + for team in config["teams"]: + order1 = request.form['poradi1_'+str(team['id'])] + order2 = request.form['poradi2_'+str(team['id'])] + per1 = request.form['clovek1_'+str(team['id'])] + per2 = request.form.get('clovek2_'+str(team['id']),None) + team["points"] += team_points(per1,order1,per2,order2,config) + return render_template("form.html", + round = config["times"][around], + people = config["orgs"], + order = order, + teams = config["teams"], + errors = [] + ) + + + +@app.route('/tablo') +def tablo(): + return render_template("tablo.html",teams=config["teams"]) + diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..b98fa81 --- /dev/null +++ b/config.toml @@ -0,0 +1,82 @@ +# Označení kol +times = [ + "pondělí ráno", + "pondělí v poledne", + "pondělí večer", + "úterý ráno", + "úterý v poledne", + "úterý večer", + "středa ráno", + "středa v poledne", + "středa večer", + "čtvrtek ráno", + "čtvrtek v poledne", + "čtvrtek večer", + "pátek ráno", + "pátek v poledne", + "pátek večer", + ] + +order_coeff = [ + 1.5, 1.4, 1.3, 1.2, 1.1 +] +start_pts = 100 +base_pts = 20 +no_pts = -20 + +# Přiřazení léků k orgům +[[orgs]] + value = "Borek" + id = "Paralen" + coeff = 3 +[[orgs]] + value = "Jane" + id = "Penicilin" + coeff = 4 +[[orgs]] + value = "Kristý" + id = "Olynth" + coeff = 2 +[[orgs]] + value = "Matej" + id = "ACC" + coeff = 2.5 +[[orgs]] + value = "Karel" + id = "Strepsils" + coeff = 2 +[[orgs]] + value = "Lída" + id = "Coldrex" + coeff = 3.5 +[[orgs]] + value = "Béďa" + id = "Kodein" + coeff = 3 +[[orgs]] + value = "Účastník" + id = "Doktor" + coeff = 1 + + +# Jména týmů +[[teams]] + name = "Doktoři" + id = 1 + points = 100 + +[[teams]] + name = "Lékaři" + id = 2 + points = 100 + +[[teams]] + name = "Medici" + id = 3 + points = 100 + +[[teams]] + name = "Hrobaři" + id = 4 + points = 100 + diff --git a/poznamky b/poznamky new file mode 100644 index 0000000..d84730c --- /dev/null +++ b/poznamky @@ -0,0 +1,30 @@ +1. notebook +----------- +- 4 lifebary +- výchozí rozsah 0--1000 +- nemusí se přeškálovávat, pokud přešvihnou 1000, ale musí tam být číslo +- číslo nemusí být celé, zobrazení zaokrouhlit na 1 desetinné místo +- černé tečky za záchranky +- počitadlo kol + - pondělí -- pátek; ráno, poledne, večer + +2.notebook +---------- +- 4 týmy +- 7 orgů + účastník +- je potřeba, aby bylo možné zadat pořadí doběhnutí (1. -- 4. + třezalka + neběžel) a orga resp. účastníka + - to celé 2x pro tým, protože až 2 léky na tým a běh + - pokud třezalka, pak koeficient 1 + - pokud neběžel, pak záporné body +- za jeden tým může běžet 0 -- 2 lidí + - nikdy neběží lék a lékař +- týmy navzájem neinteragují není potřeba při výpočtu bodů jednoho týmu zkoumat výsledky jiného týmu +- pokud zdraví účastníků klesne pod 100, můžou si zavolat záchranku, která jím vrátí zdraví na 100 + - lze jen jednou za hru + - projeví se jen na zadávací stránce, aby nešlo zvolit 2x +- pokud zdraví účastníků <= 0, tak se záchranka volá automaticky, opět srovná na 100 bodů + - projeví se na bodovací stránce černým puntíkem +- počitadlo kol + - úterý poledne: -30 zdraví + - pátek ráno a oběd: -100 zdraví +- tlačítko zpět o kolo diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..ab0e115 --- /dev/null +++ b/static/style.css @@ -0,0 +1,29 @@ +#content { + width: 100%; + height: 100%; + display: flex; + flex-direction: row; + justify-content: space-around; + align-items: flex-end; + +} +.team { + display: flex; + flex-direction: column; + justify-content: flex-end; + align-items: center; + +} +.points { + font-size: 32pt; +} + + +.bar { + float: left; + width: 100px; + margin: 5px; + border: 1px solid rgba(0, 0, 0, .2); + background-color: blue; +} + diff --git a/templates/form.html b/templates/form.html new file mode 100644 index 0000000..9024ad5 --- /dev/null +++ b/templates/form.html @@ -0,0 +1,39 @@ + + + + +

Zadávání pořadí - {{round}}

+
+

Problémy

+ +{% for team in teams %} +

Tým {{team.name}}

+

Člověk 1:

+{% for c in people %} + + +{% endfor %} +

Pořadí

+{% for p in order %} + + +{% endfor %} +

Člověk 2:

+{% for c in people %} + + +{% endfor %} +

Pořadí

+{% for p in order %} + + +{% endfor %} +{% endfor %} + + +
+ diff --git a/templates/tablo.html b/templates/tablo.html new file mode 100644 index 0000000..091cfe9 --- /dev/null +++ b/templates/tablo.html @@ -0,0 +1,18 @@ + + + + Zdraví pacientů + + +
+{% for t in teams %} +
+
+
+
+{{t.points}} +
+
+{% endfor %} +
+