|
|
@ -4,8 +4,9 @@ import datetime |
|
|
|
import random |
|
|
|
import django.contrib.auth |
|
|
|
from django.db import transaction |
|
|
|
import unidecode |
|
|
|
|
|
|
|
from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni, Soustredeni_Ucastnici |
|
|
|
from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni, Soustredeni_Ucastnici, Osoba, Organizator |
|
|
|
|
|
|
|
from django.contrib.flatpages.models import FlatPage |
|
|
|
from django.contrib.sites.models import Site |
|
|
@ -14,89 +15,213 @@ User = django.contrib.auth.get_user_model() |
|
|
|
|
|
|
|
@transaction.atomic |
|
|
|
def create_test_data(size = 6, rnd = None): |
|
|
|
assert size >= 1 |
|
|
|
# pevna pseudo-nahodnost |
|
|
|
rnd = rnd or random.Random(x=42) |
|
|
|
|
|
|
|
# static URL stranky |
|
|
|
s = Site.objects.filter(name="example.com") |
|
|
|
f = FlatPage.objects.create(url="/", title="Seminář M&M", content = "<p>Vítejte na stránce semináře MaM!</p>") |
|
|
|
f.sites.add(s[0]) |
|
|
|
f.save() |
|
|
|
|
|
|
|
# users |
|
|
|
admin = User.objects.create_superuser(username='admin', email='', password='admin') |
|
|
|
|
|
|
|
usernames = ['anet', 'bara', 'cyril', 'david', 'eva', 'filip'] |
|
|
|
orgs = [] |
|
|
|
for org in usernames[:size]: |
|
|
|
o = User.objects.create_user(username=org, password=org) |
|
|
|
o.first_name = org.capitalize() |
|
|
|
o.save() |
|
|
|
orgs.append(o) |
|
|
|
|
|
|
|
# skoly |
|
|
|
Skola.objects.create(mesto = u'Praha', stat='CZ', psc='101 00', ulice=u'Krátká 5', nazev=u'První ZŠ', je_zs=True, je_ss=False) |
|
|
|
Skola.objects.create(mesto = u'Praha', stat='CZ', psc='101 00', ulice=u'Krátká 5', nazev=u'První SŠ', je_zs=False, je_ss=True) |
|
|
|
Skola.objects.create(mesto = u'Praha', stat='CZ', psc='102 00', ulice=u'Dlouhá 5', nazev=u'Druhá SŠ', je_zs=False, je_ss=True) |
|
|
|
Skola.objects.create(mesto = u'Praha', stat='CZ', psc='103 00', ulice=u'Široká 3', nazev=u'Třetí SŠ a ZŠ', je_zs=True, je_ss=True) |
|
|
|
Skola.objects.create(mesto = u'Ostrava', stat='CZ', psc='700 00', ulice=u'Hluboká 42', nazev=u'Hutní gympl', je_zs=False, je_ss=True) |
|
|
|
Skola.objects.create(mesto = u'Humenné', stat='SK', psc='012 34', ulice=u'Pltká 1', nazev=u'Sredná škuola', je_zs=False, je_ss=True) |
|
|
|
|
|
|
|
# resitele |
|
|
|
jmena_m = ['Aleš', 'Tomáš', 'Martin', 'Jakub', 'Petr', 'Lukáš', 'Cyril'] |
|
|
|
jmena_f = ['Eva', 'Karolína', 'Zuzana', 'Sylvie', 'Iva', 'Jana', 'Marie'] |
|
|
|
prijmeni_m = ['Novotný', 'Svoboda', 'Pecha', 'Kořen', 'Holan', 'Uhlíř', 'Chytráček', 'Pokora', 'Koch', 'Szegedy', 'Rudý'] |
|
|
|
prijmeni_f = ['Novotná', 'Svobodová', 'Machová', 'Zelená', 'Yu-Xin', 'Mlsná', 'Dubná', 'Mrkvová', 'Suchá', 'Lovelace', 'Holcová'] |
|
|
|
for i in range(3*size): |
|
|
|
skola = rnd.choice(Skola.objects.all()) |
|
|
|
pohlavi = rnd.randint(0,1) |
|
|
|
jmeno = rnd.choice([jmena_m, jmena_f][pohlavi]) |
|
|
|
prijmeni = rnd.choice([prijmeni_m, prijmeni_f][pohlavi]) |
|
|
|
Resitel.objects.create(skola = skola, datum_prihlaseni = datetime.date(rnd.randint(2002, 2014), rnd.randint(1,12), 1), |
|
|
|
jmeno =jmeno, prijmeni = prijmeni, rok_maturity = rnd.randint(2015, 2019), |
|
|
|
stat = skola.stat, zasilat = Resitel.ZASILAT_NIKAM, pohlavi_muz = pohlavi) |
|
|
|
resitele = list(Resitel.objects.all()) |
|
|
|
|
|
|
|
# rocniky |
|
|
|
last_rocnik = 21 |
|
|
|
for ri in range(last_rocnik - size, last_rocnik + 1): |
|
|
|
r = Rocnik.objects.create(prvni_rok = 1993 + ri, rocnik = ri) |
|
|
|
|
|
|
|
# cisla |
|
|
|
cisel = rnd.randint(4, 6) |
|
|
|
|
|
|
|
cs = {} |
|
|
|
for ci in range(1, cisel + 1): |
|
|
|
vydano = datetime.date(r.prvni_rok, ci + 6, 1) |
|
|
|
deadline = datetime.date(r.prvni_rok, ci + 8, 1) if ci + 2 < cisel else None |
|
|
|
c = Cislo.objects.create(rocnik = r, cislo = str(ci), datum_vydani=vydano, datum_deadline=deadline, verejne_db=True) |
|
|
|
cs[ci] = c |
|
|
|
|
|
|
|
# problemy resene v ci |
|
|
|
seq='#ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
|
|
|
if ci >= 3: |
|
|
|
for pi in range(1, ((size + 1) // 2) + 1): |
|
|
|
p = Problem.objects.create(autor = rnd.choice(orgs), cislo_zadani=cs[ci-2], cislo_reseni=cs[ci], |
|
|
|
opravovatel = rnd.choice(orgs), kod = str(pi), nazev = u'Dummy úloha %s-%s' % (seq[ci], seq[pi]), |
|
|
|
stav = Problem.STAV_ZADANY, typ = Problem.TYP_ULOHA, body = rnd.randint(1, 5)) |
|
|
|
p.text_problemu = (u"<p>Text problému <strong>%s.%s %s</strong><em> [id %d]</em> za %d body.</p>" % |
|
|
|
(p.cislo_zadani.kod(), p.kod, p.nazev, p.id, p.body)) |
|
|
|
p.text_problemu_org = u"<p><strong>Neveřejný</strong> text problému.</p>" |
|
|
|
p.save() |
|
|
|
|
|
|
|
poc_reseni = rnd.randint(size // 2, size * 2) |
|
|
|
res_sel = rnd.sample(resitele, min(poc_reseni, len(resitele) - 2)) |
|
|
|
for resitel in res_sel: |
|
|
|
res = Reseni.objects.create(problem = p, resitel = resitel, |
|
|
|
body = rnd.randint(0, p.body), cislo_body = cs[ci]) |
|
|
|
|
|
|
|
sous = Soustredeni.objects.create(rocnik=Rocnik.objects.first(), verejne_db=True, misto=u'Někde', |
|
|
|
datum_zacatku=datetime.date(2000, 11, 23), datum_konce=datetime.date(2000, 11, 27)) |
|
|
|
for res in rnd.sample(resitele, 6): |
|
|
|
Soustredeni_Ucastnici.objects.create(resitel=res, soustredeni=sous) |
|
|
|
sous.save() |
|
|
|
|
|
|
|
nastaveni = Nastaveni.objects.create(aktualni_rocnik = Rocnik.objects.last(), |
|
|
|
aktualni_cislo = Cislo.objects.all()[1]) |
|
|
|
assert size >= 1 |
|
|
|
# pevna pseudo-nahodnost |
|
|
|
rnd = rnd or random.Random(x=42) |
|
|
|
|
|
|
|
# static URL stranky |
|
|
|
# FIXME: nakopirovat sem vsechny z produkcni databaze |
|
|
|
s = Site.objects.filter(name="example.com") |
|
|
|
f = FlatPage.objects.create(url="/", title="Seminář M&M", |
|
|
|
content = "<p>Vítejte na stránce semináře MaM!</p>") |
|
|
|
f.sites.add(s[0]) |
|
|
|
f.save() |
|
|
|
|
|
|
|
# users |
|
|
|
admin = User.objects.create_superuser(username='admin', email='', password='admin') |
|
|
|
|
|
|
|
usernames = ['anet', 'bara', 'cyril', 'david', 'eva', 'filip'] |
|
|
|
orgs = [] |
|
|
|
for org in usernames[:size]: |
|
|
|
o = User.objects.create_user(username=org, password=org) |
|
|
|
o.first_name = org.capitalize() |
|
|
|
o.save() |
|
|
|
orgs.append(o) |
|
|
|
|
|
|
|
# skoly |
|
|
|
skoly = [] |
|
|
|
# prvnizs = Skola.objects.create(mesto='Praha', stat='CZ', psc='101 00', ulice='Krátká 5', nazev='První ZŠ', je_zs=True, je_ss=False) |
|
|
|
# skoly.append(prvnizs) |
|
|
|
# skoly.append(Skola.objects.create(mesto='Praha', stat='CZ', psc='101 00', |
|
|
|
# ulice='Krátká 5', nazev='První SŠ', je_zs=False, je_ss=True)) |
|
|
|
# skoly.append(Skola.objects.create(mesto='Praha', stat='CZ', psc='102 00', |
|
|
|
# ulice='Dlouhá 5', nazev='Druhá SŠ', je_zs=False, je_ss=True)) |
|
|
|
# skoly.append(Skola.objects.create(mesto='Praha', stat='CZ', psc='103 00', |
|
|
|
# ulice='Široká 3', nazev='Třetí SŠ a ZŠ', je_zs=True, je_ss=True)) |
|
|
|
# skoly.append(Skola.objects.create(mesto='Ostrava', stat='CZ', psc='700 00', |
|
|
|
# ulice='Hluboká 42', nazev='Hutní gympl', je_zs=False, je_ss=True)) |
|
|
|
# skoly.append(Skola.objects.create(mesto='Humenné', stat='SK', psc='012 34', |
|
|
|
# ulice='Pltká 1', nazev='Sredná škuola', je_zs=False, je_ss=True)) |
|
|
|
# #FIXME pridat kontaktni osobu alespon nekde |
|
|
|
# skoly.append(zlinska = Skola.objects.create(mesto = 'Zlín', stat='CZ', psc='76001', |
|
|
|
# ulice='náměstí T.G. Masaryka 2734-9', |
|
|
|
# nazev='Gymnázium a Střední jazyková škola s právem SJZ', |
|
|
|
# kratky_nazev="GaSJŠspSJZ", je_zs=True, je_ss=True)) |
|
|
|
|
|
|
|
# osoby |
|
|
|
jmena_m = ['Aleš', 'Tomáš', 'Martin', 'Jakub', 'Petr', 'Lukáš', 'Cyril', 'Pavel Karel'] |
|
|
|
jmena_f = ['Eva', 'Karolína', 'Zuzana', 'Sylvie', 'Iva', 'Jana', 'Marie', |
|
|
|
'Marta Iva', 'Shu Shan'] |
|
|
|
prijmeni_m = ['Novotný', 'Svoboda', 'Pecha', 'Kořen', 'Holan', 'Uhlíř', 'Chytráček', |
|
|
|
'Pokora', 'Koch', 'Szegedy', 'Rudý', "von Neumann", "d'Este"] |
|
|
|
prijmeni_f = ['Novotná', 'Svobodová', 'Machová', 'Zelená', 'Yu-Xin', 'Mlsná', 'Dubná', |
|
|
|
'Mrkvová', 'Suchá', 'Lovelace', 'Holcová', 'Rui'] |
|
|
|
prezdivka = ['Kaki', 'Hurdur', 'Maracuja', 'Bobbo', "", "", "", "", "", |
|
|
|
"", "", 'Riki', 'Sapa', "", '', '---', 'Koko'] |
|
|
|
domain = ['example.com', 'dolujeme.eu', 'mff.cuni.cz', 'strcprstskrzkrk.cz', |
|
|
|
'british.co.uk', 'splachni.to', 'haha.org'] |
|
|
|
seznam_ulic = ['Krátká', 'Vlhká', 'Jungmanova', '17. listopadu', '4. října', 'Roztocká', |
|
|
|
'Forstova', 'Generála Františka Janouška', 'Náměstí Války', |
|
|
|
'Svratecké náměstí', 'Zelená lhota', 'Z Plynu', 'K Jezeru', 'U Kocourkova', |
|
|
|
'Uštěpačná', 'Ostrorepská', 'Zubří'] |
|
|
|
seznam_mest = ['Praha', 'Brno', 'Ostrava', 'Horní Jelení', 'Dolní Zábrdovice', 'Prdelkov', |
|
|
|
'Stará myslivna', 'Kocourkov', 'Šalingrad', 'Medvědí hora', 'Basilej', |
|
|
|
'Unterschiedlich', 'Old York', 'Lancastershire', 'Vóloďháza'] |
|
|
|
|
|
|
|
osoby = [] |
|
|
|
for i in range(3 * size): |
|
|
|
pohlavi = rnd.randint(0,1) |
|
|
|
jmeno = rnd.choice([jmena_m, jmena_f][pohlavi]) |
|
|
|
prijmeni = rnd.choice([prijmeni_m, prijmeni_f][pohlavi]) |
|
|
|
prezdivka = rnd.choice([prezdivka]) |
|
|
|
email = "@".join([unidecode.unidecode(jmeno), rnd.choice(domain)]) |
|
|
|
telefon = [rnd.choice([k for k in range(10)]) for i in range(10)] |
|
|
|
narozeni = datetime.date(rnd.randint(1980, 2020), rnd.randint(1, 12), |
|
|
|
rnd.randint(1, 28)) |
|
|
|
ulic = rnd.choice(seznam_ulic) |
|
|
|
print(ulic) |
|
|
|
cp = rnd.randint(1, 99) |
|
|
|
ulice = " ".join([ulic, str(cp)]) |
|
|
|
mesto = rnd.choice([seznam_mest]) |
|
|
|
psc = [rnd.choice([k for k in range(10)]) for i in range(6)] |
|
|
|
osoby.append(Osoba.objects.create(jmeno = jmeno, prijmeni = prijmeni, |
|
|
|
prezdivka = prezdivka, pohlavi_muz = pohlavi, email = email, |
|
|
|
telefon = telefon, datum_narozeni = narozeni, ulice = ulice, |
|
|
|
mesto = mesto, psc = psc, |
|
|
|
datum_registrace = datetime.date(rnd.randint(2019, 2029), |
|
|
|
rnd.randint(1, 12), rnd.randint(1, 28)))) |
|
|
|
#TODO pridat foto male a velke. Jak? |
|
|
|
|
|
|
|
# resitele a organizatori |
|
|
|
last_rocnik = 25 |
|
|
|
resitele = [] |
|
|
|
organizatori = [] |
|
|
|
for os in osoby: |
|
|
|
rand = rnd.randint(0, 8) |
|
|
|
if not (rand % 8 == 0): |
|
|
|
resitele.append(Resitel.objects.create(osoba=os, skola=rnd.choice([skoly]), |
|
|
|
rok_maturity=rnd.randint(2019, 2029), |
|
|
|
zasilat=rnd.choice(Resitel.ZASILAT_CHOICES))) |
|
|
|
else: |
|
|
|
pusobnost = rnd.randint(1, last_rocnik) |
|
|
|
od = 1993 + last_rocnik - pusobnost |
|
|
|
do = od + rnd.randint(1, 6) |
|
|
|
# aktualni organizatori jeste nemaji vyplnene organizuje_do |
|
|
|
#if do > datetime.datetime.now().year: |
|
|
|
# do = None |
|
|
|
organizatori.append(Organizator.objects.create(osoba=os)) |
|
|
|
#organizuje_od=od)) |
|
|
|
#, organizuje_do=do)) |
|
|
|
|
|
|
|
# prijemci |
|
|
|
prijemci = [] |
|
|
|
for i in range(10): |
|
|
|
randos = rnd.choice(osoby) |
|
|
|
prijemci.add(Prijemce.objects.create(osoba=randos)) |
|
|
|
|
|
|
|
zlinska.kontaktni_osoba=rnd.choice(osoby) |
|
|
|
zlinska.save() |
|
|
|
|
|
|
|
# rocniky |
|
|
|
for ri in range(min(last_rocnik - size, 1), last_rocnik + 1): |
|
|
|
r = Rocnik.objects.create(prvni_rok = 1993 + ri, rocnik = ri) |
|
|
|
|
|
|
|
# cisla |
|
|
|
cisel = rnd.randint(4, 8) |
|
|
|
|
|
|
|
slovnik_cisel = {} |
|
|
|
for ci in range(1, cisel + 1): |
|
|
|
if ci >= 3: |
|
|
|
vydano = datetime.date(r.prvni_rok, ci + 6, rnd.randint(1, 28)) |
|
|
|
deadline = datetime.date(r.prvni_rok, ci + 8, rnd.randint(1, 28)) |
|
|
|
else: |
|
|
|
vydano = datetime.date(r.druhy_rok, ci - 3, rnd.randint(1, 28)) |
|
|
|
# posledni 2 cisla v rocniku nemaji deadline |
|
|
|
if (ci + 2 > cisel): |
|
|
|
deadline = datetime.date(r.druhy_rok, ci - 1, |
|
|
|
rnd.randint(1, 28)) |
|
|
|
else: |
|
|
|
deadline = None |
|
|
|
cislo = Cislo.objects.create(rocnik = r, cislo = str(ci), |
|
|
|
datum_vydani=vydano, datum_deadline=deadline, verejne_db=True) |
|
|
|
slovnik_cisel[ci] = cislo |
|
|
|
|
|
|
|
# FIXME: misto typu ruzne typy objektu a vnoreni do sebe |
|
|
|
# TODO: vytvorit temata s ruznymi vlakny |
|
|
|
# TODO: nagenerovat starsim rocnikum pohadku |
|
|
|
|
|
|
|
# ulohy resene v ci |
|
|
|
jaka = ["Šachová", "Černá", "Větrná", "Dlouhá", "Křehká", "Rychlá", |
|
|
|
"Zákeřná", "Fyzikální"] |
|
|
|
co = ["kostka", "smršť", "díra", "zrada", "toulka", "tyč", |
|
|
|
"úloha", "blecha"] |
|
|
|
sloveso = ["Najděte", "Spočítejte", "Zapište", "Změřte", "Odhadněte"] |
|
|
|
koho = ["délku", "počet", "množství", "dílky"] |
|
|
|
ceho = ["všech", "správných", "konstatních", "zelených"] |
|
|
|
jmeno = ["řešení", "tahů", "čísel", "kalhot", "koulí", "hadů"] |
|
|
|
kde = ["na zemi", "ve vesmíru", "ve vzduchu", "na šňůře", "v letadle"] |
|
|
|
obor = ["M", "F", "I", "O", "B"] |
|
|
|
reseni = ["to je přece jasné", "triviální", "omlouváme se," |
|
|
|
"otevřený problém", "neřešitelné", "triviálně triviální", |
|
|
|
"použitím věty z prvního semestru na matfyzu", |
|
|
|
"jednoduše pomocí látky z druhého semestru na matfyzu", |
|
|
|
"netriviální aplikace diferenciálních rovnic", "zadání je vnitřně" |
|
|
|
"sporné", "nepopsatelně jednoduché", "pokud jste na to nepřišli," |
|
|
|
"tak jste fakt hloupí"] |
|
|
|
|
|
|
|
if ci >= 3: |
|
|
|
for pi in range(1, ((size + 1) // 2) + 1): |
|
|
|
poc_op = rnd.randint(1, 4) |
|
|
|
poc_oboru = rnd.randint(1, 2) |
|
|
|
p = Uloha.objects.create( |
|
|
|
nazev=" ".join([rnd.choice(jaka), rnd.choice(co)]), |
|
|
|
stav=Problem.STAV_ZADANY, |
|
|
|
zamereni=rnd.sample(zamereni, poc_oboru), |
|
|
|
autor=rnd.choice(organizatori), |
|
|
|
garant=rnd.choice(organizatori), |
|
|
|
opravovatele=rnd.sample(organizatori, poc_op), |
|
|
|
kod=str(pi), |
|
|
|
cislo_zadani=cs[ci-2], |
|
|
|
cislo_reseni=cs[ci], |
|
|
|
cislo_deadline=cs[ci], |
|
|
|
max_body = rnd.randint(1, 8)) |
|
|
|
p.zadani = " ".join([rnd.choice(sloveso), rnd.choice(koho), |
|
|
|
rnd.choice(ceho), rnd.choice(jmeno), rnd.choice(kde)]) |
|
|
|
p.vzorak = " - ".join([p.zadani, rnd.choice(reseni)]) |
|
|
|
p.save() |
|
|
|
|
|
|
|
# reseni ulohy |
|
|
|
poc_reseni = rnd.randint(size // 2, size * 2) |
|
|
|
poc_resitel = rnd.randint(1, 3) |
|
|
|
res_sel = rnd.sample(resitele, min(poc_reseni, len(resitele) - 2)) |
|
|
|
for resitel in res_sel: |
|
|
|
res = Reseni.objects.create(problem = p, |
|
|
|
resitele=[resitel], |
|
|
|
forma=rnd.choice(Reseni.FORMA_CHOICES)) |
|
|
|
hod = Hodnoceni.objects.create(body=rnd.randint(0, p.max_body), |
|
|
|
cislo_body=cs[ci], reseni=res, problem=p) |
|
|
|
|
|
|
|
# TODO: nahodne nagenerovat problemum reseni a prilohy reseni, hodnoceni |
|
|
|
|
|
|
|
|
|
|
|
# TODO: vice soustredeni a k nim nahodne podmnoziny organizatoru a ucastniku |
|
|
|
sous = Soustredeni.objects.create(rocnik=Rocnik.objects.first(), verejne_db=True, misto=u'Někde', |
|
|
|
datum_zacatku=datetime.date(2000, 11, 23), datum_konce=datetime.date(2000, 11, 27)) |
|
|
|
for res in rnd.sample(resitele, 6): |
|
|
|
Soustredeni_Ucastnici.objects.create(resitel=res, soustredeni=sous) |
|
|
|
sous.save() |
|
|
|
|
|
|
|
nastaveni = Nastaveni.objects.create(aktualni_rocnik = Rocnik.objects.last(), |
|
|
|
aktualni_cislo = Cislo.objects.all()[1]) |
|
|
|
|
|
|
|
|
|
|
|