|
|
@ -13,52 +13,7 @@ from django.contrib.sites.models import Site |
|
|
|
|
|
|
|
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 |
|
|
|
# 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 |
|
|
|
def gen_osoby(size): |
|
|
|
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'] |
|
|
@ -89,7 +44,7 @@ def create_test_data(size = 6, rnd = None): |
|
|
|
narozeni = datetime.date(rnd.randint(1980, 2020), rnd.randint(1, 12), |
|
|
|
rnd.randint(1, 28)) |
|
|
|
ulic = rnd.choice(seznam_ulic) |
|
|
|
print(ulic) |
|
|
|
print(ulic) #FIXME: pozdeji smazat, jen debug |
|
|
|
cp = rnd.randint(1, 99) |
|
|
|
ulice = " ".join([ulic, str(cp)]) |
|
|
|
mesto = rnd.choice([seznam_mest]) |
|
|
@ -102,64 +57,69 @@ def create_test_data(size = 6, rnd = None): |
|
|
|
rnd.randint(1, 12), rnd.randint(1, 28)))) |
|
|
|
#TODO pridat foto male a velke. Jak? |
|
|
|
|
|
|
|
# resitele a organizatori |
|
|
|
last_rocnik = 25 |
|
|
|
return osoby |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def gen_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)) |
|
|
|
return skoly |
|
|
|
|
|
|
|
def gen_resitele(osoby, skoly): |
|
|
|
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: |
|
|
|
return resitele |
|
|
|
|
|
|
|
def gen_prijemci(osoby, kolik=10): |
|
|
|
prijemci = [] |
|
|
|
for i in range(kolik): |
|
|
|
rand_os = rnd.choice(osoby) |
|
|
|
prijemci.add(Prijemce.objects.create(osoba=rand_os)) |
|
|
|
return prijemci |
|
|
|
|
|
|
|
def gen_organizatori(osoby, last_rocnik): |
|
|
|
organizatori = [] |
|
|
|
for os in osoby: |
|
|
|
rand = rnd.randint(0, 8) |
|
|
|
if (rand % 8 == 0): |
|
|
|
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 |
|
|
|
#organizatori.append(Organizator.objects.create(osoba=os, |
|
|
|
# user=rnd.choice(users), |
|
|
|
# organizuje_od=od, organizuje_do=do)) |
|
|
|
return organizatori |
|
|
|
|
|
|
|
def gen_ulohy_do_cisla(cislo, organizatori, resitele, slovnik_cisel, size): |
|
|
|
''' |
|
|
|
cislo = cislo cisla v rocniku, nikoli objekt Cislo |
|
|
|
''' |
|
|
|
# ulohy resene v ci |
|
|
|
jaka = ["Šachová", "Černá", "Větrná", "Dlouhá", "Křehká", "Rychlá", |
|
|
|
"Zákeřná", "Fyzikální"] |
|
|
@ -179,7 +139,7 @@ def create_test_data(size = 6, rnd = None): |
|
|
|
"sporné", "nepopsatelně jednoduché", "pokud jste na to nepřišli," |
|
|
|
"tak jste fakt hloupí"] |
|
|
|
|
|
|
|
if ci >= 3: |
|
|
|
if cislo >= 3: |
|
|
|
for pi in range(1, ((size + 1) // 2) + 1): |
|
|
|
poc_op = rnd.randint(1, 4) |
|
|
|
poc_oboru = rnd.randint(1, 2) |
|
|
@ -191,9 +151,9 @@ def create_test_data(size = 6, rnd = None): |
|
|
|
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], |
|
|
|
cislo_zadani=slovnik_cisel[cislo-2], |
|
|
|
cislo_reseni=slovnik_cisel[cislo], |
|
|
|
cislo_deadline=slovnik_cisel[cislo], |
|
|
|
max_body = rnd.randint(1, 8)) |
|
|
|
p.zadani = " ".join([rnd.choice(sloveso), rnd.choice(koho), |
|
|
|
rnd.choice(ceho), rnd.choice(jmeno), rnd.choice(kde)]) |
|
|
@ -209,14 +169,143 @@ def create_test_data(size = 6, rnd = None): |
|
|
|
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) |
|
|
|
cislo_body=slovnik_cisel[cislo], reseni=res, problem=p) |
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@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 |
|
|
|
# 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'] |
|
|
|
users = [] |
|
|
|
for usr in usernames[:size]: |
|
|
|
u = User.objects.create_user(username=usr, password=usr) |
|
|
|
u.first_name = usr.capitalize() |
|
|
|
u.save() |
|
|
|
users.append(u) |
|
|
|
print(users) |
|
|
|
|
|
|
|
# skoly |
|
|
|
skoly = gen_skoly() |
|
|
|
|
|
|
|
# osoby |
|
|
|
osoby = gen_osoby() |
|
|
|
|
|
|
|
# resitele a organizatori |
|
|
|
last_rocnik = 25 |
|
|
|
resitele = gen_resitele(osoby) |
|
|
|
organizatori = gen_organizatori(osoby) |
|
|
|
|
|
|
|
# prijemci |
|
|
|
prijemci = gen_prijemci() |
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
# generovani uloh |
|
|
|
gen_ulohy_do_cisla(ci, organizatori, resitele, size) |
|
|
|
|
|
|
|
# generovani temat |
|
|
|
if ci <= 3: |
|
|
|
jake = ["Hravé", "Fyzikální", "Nejlepší", "Totálně masakrální", |
|
|
|
"Šokující", "Magnetické", "Modré", "Překvapivé", |
|
|
|
"Plasmatické", "Novoroční"] |
|
|
|
co = ["téma", "záření", "stavení", "jiskření", "jelito", |
|
|
|
"drama", "kuře", "moře", "klání", "proudění", "čekání"] |
|
|
|
poc_oboru = rnd.randint(1, 2) |
|
|
|
poc_op = rnd.randint(1, 3) |
|
|
|
t = Tema.objects.create( |
|
|
|
nazev=" ".join([rnd.choice(jake), 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), |
|
|
|
tema_typ=rnd.choice(Tema.TEMA_CHOICES), |
|
|
|
rocnik=r) |
|
|
|
# nagenerovat k tématu úlohy a Nody pro vsechna cisla |
|
|
|
for i in range(ci, cisel): |
|
|
|
# vytvor ulohu |
|
|
|
poc_op = rnd.randint(1, 4) |
|
|
|
poc_oboru = rnd.randint(1, 2) |
|
|
|
p = Uloha.objects.create( |
|
|
|
nazev=": ".join([t.nazev, "úloha {}.".format(i)]), |
|
|
|
stav=Problem.STAV_ZADANY, |
|
|
|
zamereni=t.zamereni, |
|
|
|
autor=t.autor, |
|
|
|
garant=t.garant, |
|
|
|
opravovatele=rnd.sample(organizatori, poc_op), |
|
|
|
kod=str(i), |
|
|
|
cislo_zadani=slovnik_cisel[cislo-2], |
|
|
|
cislo_reseni=slovnik_cisel[cislo], |
|
|
|
cislo_deadline=slovnik_cisel[cislo], |
|
|
|
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() |
|
|
|
|
|
|
|
|
|
|
|
# vytvor text |
|
|
|
# vytvor TemaVCisleNode |
|
|
|
if (rnd.randint(1, 3) % 3 == 0): |
|
|
|
# vytvor mezicislo Node |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# FIXME: misto typu ruzne typy objektu a vnoreni do sebe |
|
|
|
# TODO: vytvorit temata s ruznymi vlakny |
|
|
|
# TODO: nagenerovat starsim rocnikum pohadku |
|
|
|
|
|
|
|
# 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)) |
|
|
|
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() |
|
|
|