|
|
@ -4,6 +4,7 @@ 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 |
|
|
|
|
|
|
@ -19,6 +20,7 @@ def create_test_data(size = 6, rnd = None): |
|
|
|
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]) |
|
|
@ -36,61 +38,134 @@ def create_test_data(size = 6, rnd = None): |
|
|
|
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()) |
|
|
|
skoly = [] |
|
|
|
skoly.append(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(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', ulic='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', None, None, None, None, None, None, None, |
|
|
|
'Riki', 'Sapa', None, '', '---', '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]) |
|
|
|
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()) |
|
|
|
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]) |
|
|
|
cp = rnd.int(1, 99) |
|
|
|
ulice = " ".join(ulic, 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, 8) |
|
|
|
# aktualni organizatori jeste nemaji vyplnene organizuje_do |
|
|
|
if do > datetime.now().year: |
|
|
|
do = None |
|
|
|
organizatori.append(Organizator.objects.create(osoba = os, organizuje_od = od, |
|
|
|
organizuje_do = do)) |
|
|
|
|
|
|
|
# rocniky |
|
|
|
last_rocnik = 21 |
|
|
|
for ri in range(last_rocnik - size, last_rocnik + 1): |
|
|
|
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, 6) |
|
|
|
cisel = rnd.randint(4, 8) |
|
|
|
|
|
|
|
cs = {} |
|
|
|
slovnik_cisel = {} |
|
|
|
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]) |
|
|
|
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 |
|
|
|
|
|
|
|
# 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]) |
|
|
|
# |
|
|
|
# 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): |
|
|
|