First (almost) working version.
This commit is contained in:
parent
a08eaf1e11
commit
d5c042a9a9
7 changed files with 345 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -114,3 +114,5 @@ dmypy.json
|
|||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# Vim swap file
|
||||
.*.sw[mnop]
|
||||
|
|
145
app.py
Normal file
145
app.py
Normal file
|
@ -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"])
|
||||
|
82
config.toml
Normal file
82
config.toml
Normal file
|
@ -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
|
||||
|
30
poznamky
Normal file
30
poznamky
Normal file
|
@ -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
|
29
static/style.css
Normal file
29
static/style.css
Normal file
|
@ -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;
|
||||
}
|
||||
|
39
templates/form.html
Normal file
39
templates/form.html
Normal file
|
@ -0,0 +1,39 @@
|
|||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Zadávání pořadí - {{round}}</h1>
|
||||
<form method="post" action="">
|
||||
<h2> Problémy </h2>
|
||||
<ul>
|
||||
{% for e in errors %}
|
||||
<li>{{e}}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% for team in teams %}
|
||||
<h2>Tým {{team.name}}</h2>
|
||||
<h3>Člověk 1:</h3>
|
||||
{% for c in people %}
|
||||
<input type="radio" name="clovek1_{{team.id}}" id="clovek1_{{team.id}}_{{c.id}}" value="{{c.id}}">
|
||||
<label for="clovek1_{{team.id}}_{{c.id}}">{{c.value}}</label>
|
||||
{% endfor %}
|
||||
<h3>Pořadí</h3>
|
||||
{% for p in order %}
|
||||
<input type="radio" name="poradi1_{{team.id}}" id="p1_{{team.id}}_{{p.id}}" value="{{p.id}}">
|
||||
<label for="p1_{{team.id}}_{{p.id}}">{{p.value}}</label>
|
||||
{% endfor %}
|
||||
<h3>Člověk 2:</h3>
|
||||
{% for c in people %}
|
||||
<input type="radio" name="clovek2_{{team.id}}" id="clovek2_{{team.id}}_{{c.id}}" value="{{c.id}}">
|
||||
<label for="clovek2_{{team.id}}_{{c.id}}">{{c.value}}</label>
|
||||
{% endfor %}
|
||||
<h3>Pořadí</h3>
|
||||
{% for p in order %}
|
||||
<input type="radio" name="poradi2_{{team.id}}" id="p2_{{team.id}}_{{p.id}}" value="{{p.id}}">
|
||||
<label for="p2_{{team.id}}_{{p.id}}">{{p.value}}</label>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
||||
<input type="submit" value="Odeslat">
|
||||
</form>
|
||||
</body>
|
18
templates/tablo.html
Normal file
18
templates/tablo.html
Normal file
|
@ -0,0 +1,18 @@
|
|||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
<title>Zdraví pacientů</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="content">
|
||||
{% for t in teams %}
|
||||
<div class="team">
|
||||
<div class="bar" id="bar_{{t.id}}" style="height:{{t.points}}">
|
||||
</div>
|
||||
<div class="points">
|
||||
{{t.points}}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</body>
|
Loading…
Reference in a new issue