|
@ -4,6 +4,7 @@ import datetime |
|
|
import random |
|
|
import random |
|
|
import django.contrib.auth |
|
|
import django.contrib.auth |
|
|
from django.db import transaction |
|
|
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 |
|
|
|
|
|
|
|
@ -14,89 +15,163 @@ User = django.contrib.auth.get_user_model() |
|
|
|
|
|
|
|
|
@transaction.atomic |
|
|
@transaction.atomic |
|
|
def create_test_data(size = 6, rnd = None): |
|
|
def create_test_data(size = 6, rnd = None): |
|
|
assert size >= 1 |
|
|
assert size >= 1 |
|
|
# pevna pseudo-nahodnost |
|
|
# pevna pseudo-nahodnost |
|
|
rnd = rnd or random.Random(x=42) |
|
|
rnd = rnd or random.Random(x=42) |
|
|
|
|
|
|
|
|
# static URL stranky |
|
|
# static URL stranky |
|
|
s = Site.objects.filter(name="example.com") |
|
|
# FIXME: nakopirovat sem vsechny z produkcni databaze |
|
|
f = FlatPage.objects.create(url="/", title="Seminář M&M", content = "<p>Vítejte na stránce semináře MaM!</p>") |
|
|
s = Site.objects.filter(name="example.com") |
|
|
f.sites.add(s[0]) |
|
|
f = FlatPage.objects.create(url="/", title="Seminář M&M", content = "<p>Vítejte na stránce semináře MaM!</p>") |
|
|
f.save() |
|
|
f.sites.add(s[0]) |
|
|
|
|
|
f.save() |
|
|
# users |
|
|
|
|
|
admin = User.objects.create_superuser(username='admin', email='', password='admin') |
|
|
# users |
|
|
|
|
|
admin = User.objects.create_superuser(username='admin', email='', password='admin') |
|
|
usernames = ['anet', 'bara', 'cyril', 'david', 'eva', 'filip'] |
|
|
|
|
|
orgs = [] |
|
|
usernames = ['anet', 'bara', 'cyril', 'david', 'eva', 'filip'] |
|
|
for org in usernames[:size]: |
|
|
orgs = [] |
|
|
o = User.objects.create_user(username=org, password=org) |
|
|
for org in usernames[:size]: |
|
|
o.first_name = org.capitalize() |
|
|
o = User.objects.create_user(username=org, password=org) |
|
|
o.save() |
|
|
o.first_name = org.capitalize() |
|
|
orgs.append(o) |
|
|
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) |
|
|
# skoly |
|
|
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) |
|
|
skoly = [] |
|
|
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) |
|
|
skoly.append(Skola.objects.create(mesto = 'Praha', stat='CZ', psc='101 00', ulice='Krátká 5', |
|
|
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) |
|
|
nazev='První ZŠ', je_zs=True, je_ss=False)) |
|
|
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) |
|
|
skoly.append(Skola.objects.create(mesto = 'Praha', stat='CZ', psc='101 00', ulice='Krátká 5', |
|
|
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) |
|
|
nazev='První SŠ', je_zs=False, je_ss=True)) |
|
|
|
|
|
skoly.append(Skola.objects.create(mesto = 'Praha', stat='CZ', psc='102 00', ulice='Dlouhá 5', |
|
|
# resitele |
|
|
nazev='Druhá SŠ', je_zs=False, je_ss=True)) |
|
|
jmena_m = ['Aleš', 'Tomáš', 'Martin', 'Jakub', 'Petr', 'Lukáš', 'Cyril'] |
|
|
skoly.append(Skola.objects.create(mesto = 'Praha', stat='CZ', psc='103 00', ulice='Široká 3', |
|
|
jmena_f = ['Eva', 'Karolína', 'Zuzana', 'Sylvie', 'Iva', 'Jana', 'Marie'] |
|
|
nazev='Třetí SŠ a ZŠ', je_zs=True, je_ss=True)) |
|
|
prijmeni_m = ['Novotný', 'Svoboda', 'Pecha', 'Kořen', 'Holan', 'Uhlíř', 'Chytráček', 'Pokora', 'Koch', 'Szegedy', 'Rudý'] |
|
|
skoly.append(Skola.objects.create(mesto = 'Ostrava', stat='CZ', psc='700 00', ulic='Hluboká 42', |
|
|
prijmeni_f = ['Novotná', 'Svobodová', 'Machová', 'Zelená', 'Yu-Xin', 'Mlsná', 'Dubná', 'Mrkvová', 'Suchá', 'Lovelace', 'Holcová'] |
|
|
nazev='Hutní gympl', je_zs=False, je_ss=True)) |
|
|
for i in range(3*size): |
|
|
skoly.append(Skola.objects.create(mesto = 'Humenné', stat='SK', psc='012 34', ulice='Pltká 1', |
|
|
skola = rnd.choice(Skola.objects.all()) |
|
|
nazev='Sredná škuola', je_zs=False, je_ss=True)) |
|
|
pohlavi = rnd.randint(0,1) |
|
|
#FIXME pridat kontaktni osobu alespon nekde |
|
|
jmeno = rnd.choice([jmena_m, jmena_f][pohlavi]) |
|
|
skoly.append(zlinska = Skola.objects.create(mesto = 'Zlín', stat='CZ', psc='76001', |
|
|
prijmeni = rnd.choice([prijmeni_m, prijmeni_f][pohlavi]) |
|
|
ulice='náměstí T.G. Masaryka 2734-9', nazev='Gymnázium a Střední jazyková škola s právem SJZ', |
|
|
Resitel.objects.create(skola = skola, datum_prihlaseni = datetime.date(rnd.randint(2002, 2014), rnd.randint(1,12), 1), |
|
|
kratky_nazev="GaSJŠspSJZ", je_zs=True, je_ss=True)) |
|
|
jmeno =jmeno, prijmeni = prijmeni, rok_maturity = rnd.randint(2015, 2019), |
|
|
|
|
|
stat = skola.stat, zasilat = Resitel.ZASILAT_NIKAM, pohlavi_muz = pohlavi) |
|
|
# osoby |
|
|
resitele = list(Resitel.objects.all()) |
|
|
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'] |
|
|
# rocniky |
|
|
prijmeni_m = ['Novotný', 'Svoboda', 'Pecha', 'Kořen', 'Holan', 'Uhlíř', 'Chytráček', 'Pokora', |
|
|
last_rocnik = 21 |
|
|
'Koch', 'Szegedy', 'Rudý', "von Neumann", "d'Este"] |
|
|
for ri in range(last_rocnik - size, last_rocnik + 1): |
|
|
prijmeni_f = ['Novotná', 'Svobodová', 'Machová', 'Zelená', 'Yu-Xin', 'Mlsná', 'Dubná', 'Mrkvová', |
|
|
r = Rocnik.objects.create(prvni_rok = 1993 + ri, rocnik = ri) |
|
|
'Suchá', 'Lovelace', 'Holcová', 'Rui'] |
|
|
|
|
|
prezdivka = ['Kaki', 'Hurdur', 'Maracuja', 'Bobbo', None, None, None, None, None, None, None, |
|
|
# cisla |
|
|
'Riki', 'Sapa', None, '', '---', 'Koko'] |
|
|
cisel = rnd.randint(4, 6) |
|
|
domain = ['example.com', 'dolujeme.eu', 'mff.cuni.cz', 'strcprstskrzkrk.cz', 'british.co.uk', |
|
|
|
|
|
'splachni.to', 'haha.org'] |
|
|
cs = {} |
|
|
seznam_ulic = ['Krátká', 'Vlhká', 'Jungmanova', '17. listopadu', '4. října', 'Roztocká', |
|
|
for ci in range(1, cisel + 1): |
|
|
'Forstova', 'Generála Františka Janouška', 'Náměstí Války', 'Svratecké náměstí', |
|
|
vydano = datetime.date(r.prvni_rok, ci + 6, 1) |
|
|
'Zelená lhota', 'Z Plynu', 'K Jezeru', 'U Kocourkova', 'Uštěpačná', 'Ostrorepská', |
|
|
deadline = datetime.date(r.prvni_rok, ci + 8, 1) if ci + 2 < cisel else None |
|
|
'Zubří'] |
|
|
c = Cislo.objects.create(rocnik = r, cislo = str(ci), datum_vydani=vydano, datum_deadline=deadline, verejne_db=True) |
|
|
seznam_mest = ['Praha', 'Brno', 'Ostrava', 'Horní Jelení', 'Dolní Zábrdovice', 'Prdelkov', |
|
|
cs[ci] = c |
|
|
'Stará myslivna', 'Kocourkov', 'Šalingrad', 'Medvědí hora', 'Basilej', |
|
|
|
|
|
'Unterschiedlich', 'Old York', 'Lancastershire', 'Vóloďháza'] |
|
|
# problemy resene v ci |
|
|
|
|
|
seq='#ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
|
|
osoby = [] |
|
|
if ci >= 3: |
|
|
for i in range(3 * size): |
|
|
for pi in range(1, ((size + 1) // 2) + 1): |
|
|
pohlavi = rnd.randint(0,1) |
|
|
p = Problem.objects.create(autor = rnd.choice(orgs), cislo_zadani=cs[ci-2], cislo_reseni=cs[ci], |
|
|
jmeno = rnd.choice([jmena_m, jmena_f][pohlavi]) |
|
|
opravovatel = rnd.choice(orgs), kod = str(pi), nazev = u'Dummy úloha %s-%s' % (seq[ci], seq[pi]), |
|
|
prijmeni = rnd.choice([prijmeni_m, prijmeni_f][pohlavi]) |
|
|
stav = Problem.STAV_ZADANY, typ = Problem.TYP_ULOHA, body = rnd.randint(1, 5)) |
|
|
prezdivka = rnd.choice(prezdivka) |
|
|
p.text_problemu = (u"<p>Text problému <strong>%s.%s %s</strong><em> [id %d]</em> za %d body.</p>" % |
|
|
email = "@".join([unidecode.unidecode(jmeno), rnd.choice(domain)]) |
|
|
(p.cislo_zadani.kod(), p.kod, p.nazev, p.id, p.body)) |
|
|
telefon = [rnd.choice([k for k in range(10)]) for i in range(10)] |
|
|
p.text_problemu_org = u"<p><strong>Neveřejný</strong> text problému.</p>" |
|
|
narozeni = datetime.date(rnd.randint(1980, 2020), rnd.randint(1, 12), rnd.randint(1, 28)) |
|
|
p.save() |
|
|
ulic = rnd.choice([seznam_ulic]) |
|
|
|
|
|
cp = rnd.int(1, 99) |
|
|
poc_reseni = rnd.randint(size // 2, size * 2) |
|
|
ulice = " ".join(ulic, cp) |
|
|
res_sel = rnd.sample(resitele, min(poc_reseni, len(resitele) - 2)) |
|
|
mesto = rnd.choice([seznam_mest]) |
|
|
for resitel in res_sel: |
|
|
psc = [rnd.choice([k for k in range(10)]) for i in range(6)] |
|
|
res = Reseni.objects.create(problem = p, resitel = resitel, |
|
|
osoby.append(Osoba.objects.create(jmeno = jmeno, prijmeni = prijmeni, prezdivka = prezdivka, |
|
|
body = rnd.randint(0, p.body), cislo_body = cs[ci]) |
|
|
pohlavi_muz = pohlavi, email = email, telefon = telefon, datum_narozeni = narozeni, |
|
|
|
|
|
ulice = ulice, mesto = mesto, psc = psc, |
|
|
sous = Soustredeni.objects.create(rocnik=Rocnik.objects.first(), verejne_db=True, misto=u'Někde', |
|
|
datum_registrace = datetime.date(rnd.randint(2019, 2029), rnd.randint(1, 12), |
|
|
datum_zacatku=datetime.date(2000, 11, 23), datum_konce=datetime.date(2000, 11, 27)) |
|
|
rnd.randint(1, 28)))) |
|
|
for res in rnd.sample(resitele, 6): |
|
|
#TODO pridat foto male a velke. Jak? |
|
|
Soustredeni_Ucastnici.objects.create(resitel=res, soustredeni=sous) |
|
|
|
|
|
sous.save() |
|
|
# resitele a organizatori |
|
|
|
|
|
last_rocnik = 25 |
|
|
nastaveni = Nastaveni.objects.create(aktualni_rocnik = Rocnik.objects.last(), |
|
|
resitele = [] |
|
|
aktualni_cislo = Cislo.objects.all()[1]) |
|
|
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 |
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
# 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): |
|
|
|
|
|
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]) |
|
|
|
|
|
|
|
|