|
@ -13,7 +13,7 @@ from django.contrib.sites.models import Site |
|
|
|
|
|
|
|
|
User = django.contrib.auth.get_user_model() |
|
|
User = django.contrib.auth.get_user_model() |
|
|
|
|
|
|
|
|
def gen_osoby(size): |
|
|
def gen_osoby(rnd, size): |
|
|
jmena_m = ['Aleš', 'Tomáš', 'Martin', 'Jakub', 'Petr', 'Lukáš', 'Cyril', 'Pavel Karel'] |
|
|
jmena_m = ['Aleš', 'Tomáš', 'Martin', 'Jakub', 'Petr', 'Lukáš', 'Cyril', 'Pavel Karel'] |
|
|
jmena_f = ['Eva', 'Karolína', 'Zuzana', 'Sylvie', 'Iva', 'Jana', 'Marie', |
|
|
jmena_f = ['Eva', 'Karolína', 'Zuzana', 'Sylvie', 'Iva', 'Jana', 'Marie', |
|
|
'Marta Iva', 'Shu Shan'] |
|
|
'Marta Iva', 'Shu Shan'] |
|
@ -34,7 +34,7 @@ def gen_osoby(size): |
|
|
'Unterschiedlich', 'Old York', 'Lancastershire', 'Vóloďháza'] |
|
|
'Unterschiedlich', 'Old York', 'Lancastershire', 'Vóloďháza'] |
|
|
|
|
|
|
|
|
osoby = [] |
|
|
osoby = [] |
|
|
for i in range(3 * size): |
|
|
for i in range(3 * size): # 3 je náhodná konstanta, size je použité na víc místech a říká, jak velká asi chceme testovací data |
|
|
pohlavi = rnd.randint(0,1) |
|
|
pohlavi = rnd.randint(0,1) |
|
|
jmeno = rnd.choice([jmena_m, jmena_f][pohlavi]) |
|
|
jmeno = rnd.choice([jmena_m, jmena_f][pohlavi]) |
|
|
prijmeni = rnd.choice([prijmeni_m, prijmeni_f][pohlavi]) |
|
|
prijmeni = rnd.choice([prijmeni_m, prijmeni_f][pohlavi]) |
|
@ -61,7 +61,7 @@ def gen_osoby(size): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def gen_skoly(): |
|
|
def gen_skoly(): #TODO někdy to přepsat, aby jich bylo více |
|
|
skoly = [] |
|
|
skoly = [] |
|
|
prvnizs = Skola.objects.create(mesto='Praha', stat='CZ', psc='101 00', |
|
|
prvnizs = Skola.objects.create(mesto='Praha', stat='CZ', psc='101 00', |
|
|
ulice='Krátká 5', nazev='První ZŠ', je_zs=True, je_ss=False) |
|
|
ulice='Krátká 5', nazev='První ZŠ', je_zs=True, je_ss=False) |
|
@ -77,13 +77,13 @@ def gen_skoly(): |
|
|
skoly.append(Skola.objects.create(mesto='Humenné', stat='SK', psc='012 34', |
|
|
skoly.append(Skola.objects.create(mesto='Humenné', stat='SK', psc='012 34', |
|
|
ulice='Pltká 1', nazev='Sredná škuola', je_zs=False, je_ss=True)) |
|
|
ulice='Pltká 1', nazev='Sredná škuola', je_zs=False, je_ss=True)) |
|
|
#FIXME pridat kontaktni osobu alespon nekde |
|
|
#FIXME pridat kontaktni osobu alespon nekde |
|
|
skoly.append(zlinska = Skola.objects.create(mesto = 'Zlín', stat='CZ', psc='76001', |
|
|
skoly.append(Skola.objects.create(mesto = 'Zlín', stat='CZ', psc='76001', |
|
|
ulice='náměstí T.G. Masaryka 2734-9', |
|
|
ulice='náměstí T.G. Masaryka 2734-9', |
|
|
nazev='Gymnázium a Střední jazyková škola s právem SJZ', |
|
|
nazev='Gymnázium a Střední jazyková škola s právem SJZ', |
|
|
kratky_nazev="GaSJŠspSJZ", je_zs=True, je_ss=True)) |
|
|
kratky_nazev="GaSJŠspSJZ", je_zs=True, je_ss=True)) |
|
|
return skoly |
|
|
return skoly |
|
|
|
|
|
|
|
|
def gen_resitele(osoby, skoly): |
|
|
def gen_resitele(rnd, osoby, skoly): |
|
|
resitele = [] |
|
|
resitele = [] |
|
|
for os in osoby: |
|
|
for os in osoby: |
|
|
rand = rnd.randint(0, 8) |
|
|
rand = rnd.randint(0, 8) |
|
@ -93,30 +93,30 @@ def gen_resitele(osoby, skoly): |
|
|
zasilat=rnd.choice(Resitel.ZASILAT_CHOICES))) |
|
|
zasilat=rnd.choice(Resitel.ZASILAT_CHOICES))) |
|
|
return resitele |
|
|
return resitele |
|
|
|
|
|
|
|
|
def gen_prijemci(osoby, kolik=10): |
|
|
def gen_prijemci(rnd, osoby, kolik=10): |
|
|
prijemci = [] |
|
|
prijemci = [] |
|
|
for i in range(kolik): |
|
|
for i in range(kolik): |
|
|
rand_os = rnd.choice(osoby) |
|
|
rand_os = rnd.choice(osoby) |
|
|
prijemci.add(Prijemce.objects.create(osoba=rand_os)) |
|
|
prijemci.append(Prijemce.objects.create(osoba=rand_os)) |
|
|
return prijemci |
|
|
return prijemci |
|
|
|
|
|
|
|
|
def gen_organizatori(osoby, last_rocnik): |
|
|
def gen_organizatori(rnd, osoby, last_rocnik): |
|
|
organizatori = [] |
|
|
organizatori = [] |
|
|
for os in osoby: |
|
|
for os in osoby: |
|
|
rand = rnd.randint(0, 8) |
|
|
rand = rnd.randint(0, 8) |
|
|
if (rand % 8 == 0): |
|
|
if (rand % 8 == 0): |
|
|
pusobnost = rnd.randint(1, last_rocnik) |
|
|
pusobnost = rnd.randint(1, last_rocnik) |
|
|
od = 1993 + last_rocnik - pusobnost |
|
|
od = 1993 + pusobnost |
|
|
do = od + rnd.randint(1, 6) |
|
|
do = od + rnd.randint(1, 6) |
|
|
# aktualni organizatori jeste nemaji vyplnene organizuje_do |
|
|
#aktualni organizatori jeste nemaji vyplnene organizuje_do |
|
|
#if do > datetime.datetime.now().year: |
|
|
if do > datetime.datetime.now().year: |
|
|
# do = None |
|
|
do = None |
|
|
#organizatori.append(Organizator.objects.create(osoba=os, |
|
|
organizatori.append(Organizator.objects.create(osoba=os, |
|
|
# user=rnd.choice(users), |
|
|
user=rnd.choice(users), |
|
|
# organizuje_od=od, organizuje_do=do)) |
|
|
organizuje_od=od, organizuje_do=do)) |
|
|
return organizatori |
|
|
return organizatori |
|
|
|
|
|
|
|
|
def gen_ulohy_do_cisla(cislo, organizatori, resitele, slovnik_cisel, size): |
|
|
def gen_ulohy_do_cisla(rnd, cislo, organizatori, resitele, slovnik_cisel, size): |
|
|
'''cislo = cislo cisla v rocniku, nikoli objekt Cislo ''' |
|
|
'''cislo = cislo cisla v rocniku, nikoli objekt Cislo ''' |
|
|
# ulohy resene v ci |
|
|
# ulohy resene v ci |
|
|
jaka = ["Šachová", "Černá", "Větrná", "Dlouhá", "Křehká", "Rychlá", |
|
|
jaka = ["Šachová", "Černá", "Větrná", "Dlouhá", "Křehká", "Rychlá", |
|
@ -139,7 +139,7 @@ def gen_ulohy_do_cisla(cislo, organizatori, resitele, slovnik_cisel, size): |
|
|
|
|
|
|
|
|
if cislo >= 3: |
|
|
if cislo >= 3: |
|
|
for pi in range(1, ((size + 1) // 2) + 1): |
|
|
for pi in range(1, ((size + 1) // 2) + 1): |
|
|
poc_op = rnd.randint(1, 4) |
|
|
poc_op = rnd.randint(1, 4) #počet opravovatelů |
|
|
poc_oboru = rnd.randint(1, 2) |
|
|
poc_oboru = rnd.randint(1, 2) |
|
|
p = Uloha.objects.create( |
|
|
p = Uloha.objects.create( |
|
|
nazev=" ".join([rnd.choice(jaka), rnd.choice(co)]), |
|
|
nazev=" ".join([rnd.choice(jaka), rnd.choice(co)]), |
|
@ -163,14 +163,25 @@ def gen_ulohy_do_cisla(cislo, organizatori, resitele, slovnik_cisel, size): |
|
|
poc_resitel = rnd.randint(1, 3) |
|
|
poc_resitel = rnd.randint(1, 3) |
|
|
res_vyber = rnd.sample(resitele, min(poc_reseni, len(resitele) - 2)) |
|
|
res_vyber = rnd.sample(resitele, min(poc_reseni, len(resitele) - 2)) |
|
|
for resitel in res_vyber: |
|
|
for resitel in res_vyber: |
|
|
res = Reseni.objects.create(problem = p, |
|
|
res = Reseni.objects.create(problem = p, |
|
|
resitele=[resitel], |
|
|
resitele=[resitel], |
|
|
forma=rnd.choice(Reseni.FORMA_CHOICES)) |
|
|
forma=rnd.choice(Reseni.FORMA_CHOICES)) |
|
|
hod = Hodnoceni.objects.create(body=rnd.randint(0, p.max_body), |
|
|
hod = Hodnoceni.objects.create(body=rnd.randint(0, p.max_body), |
|
|
cislo_body=slovnik_cisel[cislo], reseni=res, problem=p) |
|
|
cislo_body=slovnik_cisel[cislo], reseni=res, problem=p) |
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
def gen_soustredeni(): |
|
|
|
|
|
# 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]) |
|
|
|
|
|
|
|
|
@transaction.atomic |
|
|
@transaction.atomic |
|
|
def create_test_data(size = 6, rnd = None): |
|
|
def create_test_data(size = 6, rnd = None): |
|
@ -202,15 +213,15 @@ def create_test_data(size = 6, rnd = None): |
|
|
skoly = gen_skoly() |
|
|
skoly = gen_skoly() |
|
|
|
|
|
|
|
|
# osoby |
|
|
# osoby |
|
|
osoby = gen_osoby() |
|
|
osoby = gen_osoby(rnd, size) |
|
|
|
|
|
|
|
|
# resitele a organizatori |
|
|
# resitele a organizatori |
|
|
last_rocnik = 25 |
|
|
last_rocnik = 25 |
|
|
resitele = gen_resitele(osoby) |
|
|
resitele = gen_resitele(rnd, osoby, skoly) |
|
|
organizatori = gen_organizatori(osoby) |
|
|
organizatori = gen_organizatori(rnd, osoby, last_rocnik) |
|
|
|
|
|
|
|
|
# prijemci |
|
|
# prijemci |
|
|
prijemci = gen_prijemci() |
|
|
prijemci = gen_prijemci(rnd) |
|
|
|
|
|
|
|
|
zlinska.kontaktni_osoba=rnd.choice(osoby) |
|
|
zlinska.kontaktni_osoba=rnd.choice(osoby) |
|
|
zlinska.save() |
|
|
zlinska.save() |
|
@ -240,7 +251,7 @@ def create_test_data(size = 6, rnd = None): |
|
|
slovnik_cisel[ci] = cislo |
|
|
slovnik_cisel[ci] = cislo |
|
|
|
|
|
|
|
|
# generovani uloh |
|
|
# generovani uloh |
|
|
gen_ulohy_do_cisla(ci, organizatori, resitele, size) |
|
|
gen_ulohy_do_cisla(rnd, ci, organizatori, resitele, slovnik_cisel, size) |
|
|
|
|
|
|
|
|
# generovani temat |
|
|
# generovani temat |
|
|
if ci <= 3: |
|
|
if ci <= 3: |
|
@ -299,16 +310,5 @@ def create_test_data(size = 6, rnd = None): |
|
|
# TODO: nahodne nagenerovat problemum reseni a prilohy reseni, hodnoceni |
|
|
# 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]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|